Linux system file and directory naming rules
- Case sensitive.
- The length of the name cannot exceed 255 bytes.
- The maximum length of the absolute file path is 4095 bytes.
- Any character other than slash and NUL can be used as a legal name. In practice, you should avoid using special characters and spaces to name directories and files.
- Files beginning with a dot are hidden files, and you need to use
ls -a
commands to view related information. - The file extension is only used to distinguish file types and has no special meaning.
The purpose of Linux system directories
1. bin:存放Linux系统的引导文件,包括内核文件、GRUB引导加载器
2. boot:存放所有用户可以使用的Linux命令
3. dev:存放各种设备文件和特殊的文件
4. etc:存放Linux系统和各种软件的配置文件
5. home:普通用户的家目录,存放普通用户相关的文件
6. lib:存放各种程序运行时需要使用的库文件和内核模块文件
7. lib64:存放64位程序运行时需要使用的库文件
8. media:挂载U盘、移动硬盘等移动存储设备
9. mnt:挂载文件系统,如NFS、ISO文件
10. opt:存放用户安装的第三方软件
11. proc:存放内核与进程
12. root:root用户的目录,存放root用户相关的文件
13. run:存放系Linux统启动以后的信息
14. sbin:存放拥有管理员权限的用户才可以使用的Linux命令
15. srv:存放各种服务相关的文件
16. sys:保存硬件设备的相关信息
17. tmp:保存临时文件
18. usr:保存用户安装的软件、共享库文件
19. var:保存系统和应用程序的日志文件
Metadata of Linxu system files
In the Linux system, file metadata refers to file attribute information, which ls -l
can be viewed using commands, mainly including the following:
1. 文件类型
2. 权限
3. inode数
4. 所有者
5. 所属组
6. 大小
7. 创建时间
8. 文件名
Modify the time stamp information of the file
Files in the Linux system have three timestamps:
1. access time 访问时间,atime,读取文件内容后改变
2. modify time 修改时间,mtime,改变文件内容(数据)后改变
3. change time 改变时间,ctime,元数据发生改变后改变
It can be seen from the definition of three timestamps that using the cat command to view the file will modify atime, and using vim to modify the content of the file will modify three timestamps.
In addition, the atime and mtime of the file can be customized using the touch command.
# 自定义文件的atime
touch -a -d "2019-10-10 20:00" anaconda-ks.cfg
# 自定义文件的mtime
touch -m -d "2019-10-20 20:00" anaconda-ks.cfg
# 自定义文件的atime和mtime
touch -d "2019-10-30 20:00" anaconda-ks.cfg
The difference between soft link and hard link
Compared | Hard link | Soft link |
---|---|---|
Same file | Yes | no |
Support cross partition | no | Yes |
Support link directory | no | Yes |
inode | the same | different |
The link number of the original file after the link file is created | increase | constant |
The relative path of the original file | Relative to the current working directory | Relative path relative to soft link file |
Delete original file | The number of links minus one, you can access hard-linked files | Cannot access soft link file |
file type | Same as original file | Link file |
The actual demonstration is as follows:
Linux file management class naming summary
(1) The ls command can view the contents of the current directory or the specified directory
# 查看当前目录下的所有文件
ls -a
# 查看/boot目录下文件的详细信息
ls -l /boot
(2) The stat command can view file status information
# 查看anaconda-ks.cfg文件的状态信息
stat anaconda-ks.cfg
(3.) The file command is used to view the file type of the specified file
# 查看/dev/sda的文件类型
file /dev/sda
(4.) The touch command is used to create an empty file and modify the timestamp of the file
# 创建空文件
touch file1
# 修改文件的时间戳
touch anaconda-ks.cfg
touch -d "2019-10-30 20:00" anaconda-ks.cfg
(5) The cp command is used to copy files
# 复制anaconda-ks.cfg到/tmp目录
cp anaconda-ks.cfg /tmp
# 复制/etc目录到/tmp目录
cp -r /etc/ /tmp
(6) Commands are used to move files or rename files
# 将anaconda-ks.cfg重命名为test.txt
mv anaconda-ks.cfg test.txt
# 将test.txt移动到/tmp目录
mv test.txt /tmp
(8) The rm command is used to delete files
# 删除anaconda-ks.cfg文件
rm anaconda-ks.cfg
# 删除/opt目录
rm -rf /opt
Delete the blank character at the beginning of the text line
Requirement: Copy /etc/profile to the /tmp/ directory, use the search and replace command to delete the blank characters at the beginning of the line in the /tmp/profile file
-
Copy the profile file and open it with vim
cp /etc/profile /tmp/ vim /tmp/profile
- Enter "/^[[:blank:]]+" and press Enter to view the blank characters at the beginning of the file line
- Enter ":%s#^[[:blank:]]+##g" and press Enter to delete all blank characters at the beginning of the line
Set vim's tab indentation to 4 characters
Temporarily effective: enter set tabstop=4 in extended command mode, and then press enter
Permanently effective for the current user:echo 'set tabstop=4' >> $HOME/.vimrc
Permanently effective for all users:echo 'set tabstop=4' >> /etc/vimrc