Linux file management method
- Linux directory structure as a tree structure, the top of the directory is the root directory /. Other directories can be added by mounting them to the tree, you can remove them by unmounting
- There is one and only one /
- Relying on a path to distinguish file
- Both network partition can use local zoning
- A convention: FHS
/:根目錄
/usr:主要放軟件執行有關的東西
/var:放一些和運行有關的
/etc:配置文件
/bin:可執行文件
/dev:設備文件
/lib:執行文件需要的庫函數與核心所需要的模塊
/
The basic file attributes
- When as [d] is a directory
- As for the [-] is a file;
- If [l] is represented as a linked document (link file);
- If [b] indicates that the interface device is a device for storage of the files inside (random access device);
- If [c] said serial port device is a file inside the device, such as a keyboard, a mouse (one reading device).
rwx represent read access, write access, execute permissions
Manipulate files commonly used commands
- chgrp: Change the file owner group
chgrp [-R] 屬組名 文件名
- chown: Change file owner, the group can also change the file attributes
chown [-R] 屬主名 文件名
chown [-R] 屬主名: 數組名 文件名
- chomd: change the file's attributes 9
- Using digital
chmod [-R] syz 文件或者文件夾 xyz分別爲屬主,屬組,其他用戶的權和 r:4 w:2 x:1 -:0
- Use of symbols
chmod u/g/o/a +/-/= rwx u:user,屬主 g:group,屬組 o:others,其他 a:all,全部 +:添加權限 -:除去 =:設定 r:寫權限 w:讀權限 x:執行權限 例: 将文件权限设置为 -rwxr-xr-- ,可以使用 chmod u=rwx,g=rx,o=r 文件名
File and directory management
- ls: List directory
常用參數: -a: 顯示全部文件,包含隱藏文件 -l: 顯示文件及其屬性與權限等信息 -d: 僅列出目錄本身,而不是列出目錄内的文件數據
- cd: Change directory
- pwd: Displays the current directory
-P參數可以顯示出確切的路徑而非使用連接路徑
- mkdir: create directory
-m: 配置文件權限,可以直接配置,不需要看默認權限umask的臉色,如 mldor -m 770 test -p: 遞歸創建需要的目錄,包含上一級目錄
- rmdir: delete empty directories
-p:連同上級(空的)目錄一起刪除
- cp: copy files or directories
-a: 等價于-pdr -d:若来源档为连结档的属性(link file),则复制连结档属性而非文件本身; -f:为强制(force)的意思,若目标文件已经存在且无法开启,则移除后再尝试一次; -i:若目标档(destination)已经存在时,在覆盖时会先询问动作的进行(常用) -l:进行硬式连结(hard link)的连结档创建,而非复制文件本身; -p:连同文件的属性一起复制过去,而非使用默认属性(备份常用); -r:递归持续复制,用於目录的复制行为;(常用) -s:复制成为符号连结档 (symbolic link),亦即『捷径』文件; -u:若 destination 比 source 旧才升级 destination !
- rm: Remove files or directories
-f :就是 force 的意思,忽略不存在的文件,不会出现警告信息; -i :互动模式,在删除前会询问使用者是否动作 -r :递归删除啊!最常用在目录的删除了!这是非常危险的选项!!!
mv: move files or directories, or modify file and directory names
-f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖; -i :若目标文件 (destination) 已经存在时,就会询问是否覆盖! -u :若目标文件已经存在,且 source 比较新,才会升级 (update)
Check file contents
- cat from the first line displays the file contents
-A :相当於 -vET 的整合选项,可列出一些特殊字符而不是空白而已; -b :列出行号,仅针对非空白行做行号显示,空白行不标行号! -E :将结尾的断行字节 $ 显示出来; -n :列印出行号,连同空白行也会有行号,与 -b 的选项不同; -T :将 [tab] 按键以 ^I 显示出来; -v :列出一些看不出来的特殊字符
- tac beginning to show from the last row, you can see the tac is cat written backwards!
- Nl when displayed, take the opportunity to output line number!
-b :指定行号指定的方式,主要有两种: -b a :表示不论是否为空行,也同样列出行号(类似 cat -n); -b t :如果有空行,空的那一行不要列出行号(默认值); -n :列出行号表示的方法,主要有三种: -n ln :行号在荧幕的最左方显示; -n rn :行号在自己栏位的最右方显示,且不加 0 ; -n rz :行号在自己栏位的最右方显示,且加 0 ; -w :行号栏位的占用的位数。
- more display file contents page by page
空白键 (space):代表向下翻一页; Enter :代表向下翻『一行』; /字串 :代表在这个显示的内容当中,向下搜寻『字串』这个关键字; :f :立刻显示出档名以及目前显示的行数; q :代表立刻离开 more ,不再显示该文件内容。 b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。
- less and more similar, but better than more, he can move forward flip!
空白键 :向下翻动一页; [pagedown]:向下翻动一页; [pageup] :向上翻动一页; /字串 :向下搜寻『字串』的功能; ?字串 :向上搜寻『字串』的功能; n :重复前一个搜寻 (与 / 或 ? 有关!) N :反向的重复前一个搜寻 (与 / 或 ? 有关!) q :离开 less 这个程序;
- Look at the first few lines of head
Look at the tail tail lines