---
title: "Linux File System | linux文件系统"
author: "Wuaner"
date: "2013-02-01T17:54:50Z"
tags: []
categories: ["开源软件"]
slug: "linux-file-system-linux"
draft: false
lastmod: "2014-09-04T11:09:59Z"
id: 1782877
url: "https://wuaner.iteye.com/blog/1782877"
---

**Unix Filesystem Hierarchy Standard:
<http://www.pathname.com/fhs/pub/fhs-2.3.html#THEFILESYSTEM>
Unix directory structure:
<http://en.wikipedia.org/wiki/Unix_directory_structure>**


View file system hierarchy of Linux：
```shell

$ man hier
```


LinuxFilesystemTreeOverview
<https://help.ubuntu.com/community/LinuxFilesystemTreeOverview>

<http://linuxcommand.org/lts0040.php>


Linux 分区方案：
<https://help.ubuntu.com/community/DiskSpace>


**使用 <span style="color:red">update-rc.d</span> 实现linux服务的开机自启动：(rc stands for Run Commands)**
How-To: Managing services with update-rc.d：
<http://www.debuntu.org/how-to-manage-services-with-update-rc.d>
Ubuntu Manpage: update-rc.d - install and remove System-V style init script links：
<http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html>
> FILES
>        /etc/init.d/
>               The directory containing the actual init scripts.
> 
>        /etc/rc?.d/
>               The directories containing the links used by init and managed by
>               update-rc.d.
> 
>        /etc/init.d/skeleton
>               Model for use by writers of init.d scripts.
> 
>        /var/lib/sysv-rc/legacy-bootsequence
>               Flag indicating the machine is using legacy mode for boot script
>               ordering.
使用update-rc.d管理Linux服务：
<http://blog.bornin76.com:801/?p=130>


关于 /etc/init.d 目录：
<http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/>


**下面存放 binary files(二进制可执行文件) 的目录的区别（sbin之s代表system, usr 代表 Unix System Resources）：**
/bin/
/sbin/
/usr/bin/
/usr/sbin/
/usr/local/bin/
/usr/local/sbin/
<http://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux>



**.profile .bashrc .bash_profile 的区别：**
<http://superuser.com/questions/183870/difference-between-bashrc-and-bash-profile>
**/etc/bash.bashrc 和 ~/.bashrc 的区别：**
<http://superuser.com/questions/49562/whats-the-difference-between-etc-bash-bashrc-and-bashrc-which-one-should-i>
> /etc/bash.bashrc applies to all users
> ~/.bashrc only applies to the user in which home folder it is.
**针对单个用户的 ~/.bash_profile 与 ~/.bashrc 的区别：**
<http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html>
> .bash_profile是在登陆时起作用； .bashrc 是交互式non-login shells，即：修改.bashrc后，脚本在新打开的terminal中就开始起作用了，不用重新登陆。
关于 interactive shell / non-interactive shell、login shell / non-login shell,详见：
<http://wuaner.iteye.com/blog/1671522>



**File Descriptors & IO Redirection:**
![](http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Stdstreams-notitle.svg/220px-Stdstreams-notitle.svg.png)
What's File Descriptors? When a UNIX/linux program wants to use a file, it must first open that file. When it does so, UNIX/linux will associate a number with the file. This number, which is used by the program when reading from and writing to the file, is the file descriptor. linux kernal 的 /usr/include/unistd.h 文件中可查看stdin/stdout/stderr三个 fd 的定义：

```c

/* Standard file descriptors.  */
#define STDIN_FILENO    0   /* Standard input.  */
#define STDOUT_FILENO   1   /* Standard output.  */
#define STDERR_FILENO   2   /* Standard error output.  */
```
Understanding File Descriptors and IO Redirection：
<http://www.symkat.com/understanding-file-descriptors-and-io-redirection>
在 File Descriptors 间做 IO Redirection 时的 **&**，如 2>&1 ，代表了什么？答案是使用 & 仅仅是为了表明被重定向至的文件(stdin、stdout、stderr都是character devices，unix/linux下 character devices 也是被当作文件file来管理的)是stdout，而不是一个名为 1 的文件，参见：
<http://en.wikipedia.org/wiki/Redirection_(computing)>
> In shells derived from csh (the C shell), the syntax instead appends the & (ampersand) character to the redirect characters, thus achieving a similar result. The reason for this is to distinguish between a file named '1' and stdout, i.e. 'cat file 2>1' vs 'cat file 2>&1'. In the first case, stderr is redirected to a file named '1' and in the second, stderr is redirected to stdout.
<http://stackoverflow.com/questions/818255/in-the-bash-shell-what-is-21>
> 1 is stdout. 2 is stderr.
> Here is one way to remember this construct (altough it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.