Article directory
1. du command
du: Count the size of the disk space occupied by the specified directory (or file).
Format: du [options] [file or directory...]
常用选项
options | illustrate |
---|---|
-a | Include all files when counting disk space usage, not just counting directories |
-h | **Display the statistical results in a more humane way (counted in KB by default, but does not display the unit) |
-s | Only count the total size of the occupied space, not the size of each subdirectory and file |
–max-depth=n | Count the total size of all directories less than or equal to the nth level |
—————————————————————— du command: —————————————————————
—————————————————————— du-ah command: ———————————————————
—————————————————————— du -sh command: ——————————————————
————————————————— du -h --max-depth=1 command: ———————————————
—————————————— -d with --max-depth=n command: —————————————
注意:
1. Options -a and -s cannot be used at the same time.
2. To count the space occupied by the directory, you can only use the du command to view it.
示例:
** Statistics of the size of the subdirectories in the /var/log directory **
du -h --max-depth=1 /var/log/ #统计出/var/log目录中子目录的大小
2. mkdir command
Create new empty directory
Format: mkdir [options] directory location and name...
注意:
-p: Create nested multi-level directories at once
————————————————————— mkdir -p command: ——————————————————
[root@clr ~/gzy]# mkdir -p 11/22/33/44
#在当前目录下创建目录11,然后在11目录下创建目录22,在22目录下创建33目录,最后在33目录下创建44目录
[root@clr ~/gzy]# ls -R #递归查看各层目录创建的位置
.:
11
./11:
22
./11/22:
33
./11/22/33:
44
./11/22/33/44:
Another way to create multiple directories at once:
——————————————— mkdir -pv command: ————————————————————
3. touch command
Create an empty file.
- Update the timestamp of the file
- Often used to create multiple new empty files
Format: touch [file]…
———————————————————— touch command: ——————————————————
Create files with specified requirements at one time;
示例:
Create two empty files named aa.txt and bb.txt
touch aa bb
touch {
a,b}.txt
4. ln command
Create a link file: Create a link file for a file or directory, similar to a Windows system shortcut.
链接文件类型:
-
Soft links (aka symbolic links)
-
hard link
Create a soft link format: ln [-s] source file or directory... link file or target location
———————————————————— ln -s command: —————————————————————
The soft link points to the executable file;
If the source file in the soft link uses a relative path, and then moves the soft link to another directory, the following errors will occur;
The source file in the soft link must use an absolute path, so that when the position of the soft link moves, the soft link is still available and there will be no problem;
创建硬链接操作步骤如下所示:
[root@clr /opt/gzy/abc]# touch test1.txt #当前目录下创建文件test1.txt
[root@clr /opt/gzy/abc]# ll
总用量 0
drwxr-xr-x. 3 root root 16 3月 27 09:22 123
-rw-r--r--. 1 root root 0 3月 27 18:27 test1.txt #第二字段中硬链接数为1
[root@clr /opt/gzy/abc]# ln test1.txt h-abc.txt #为文件test1.txt创建硬链接h-abc.txt
[root@clr /opt/gzy/abc]# ll
总用量 0
drwxr-xr-x. 3 root root 16 3月 27 09:22 123
-rw-r--r--. 2 root root 0 3月 27 18:27 h-abc.txt
-rw-r--r--. 2 root root 0 3月 27 18:27 test1.txt #第二字段中硬链接数加1,由1变成2
[root@clr /opt/gzy/abc]# ln test1.txt h-123.txt #为文件test1.txt创建硬链接h-123.txt
[root@clr /opt/gzy/abc]# ll
总用量 0
drwxr-xr-x. 3 root root 16 3月 27 09:22 123
-rw-r--r--. 3 root root 0 3月 27 18:27 h-123.txt
-rw-r--r--. 3 root root 0 3月 27 18:27 h-abc.txt
-rw-r--r--. 3 root root 0 3月 27 18:27 test1.txt #第二字段中硬链接数加1,由2变成3
[root@clr /opt/gzy/abc]# vi h-123.txt #修改硬链接h-123.txt中的内容
[root@clr /opt/gzy/abc]# cat test1.txt #在硬链接test1.txt中查看
jhlk
[root@clr /opt/gzy/abc]# cat h-123.txt #在硬链接h-123.txt中查看
jhlk
[root@clr /opt/gzy/abc]# ll -i #查看硬链接的inode号
总用量 12
1277063 drwxr-xr-x. 3 root root 16 3月 27 09:22 123
100744055 -rw-r--r--. 3 root root 5 3月 27 18:30 h-123.txt #硬链接的inode号是相同的
100744055 -rw-r--r--. 3 root root 5 3月 27 18:30 h-abc.txt
100744055 -rw-r--r--. 3 root root 5 3月 27 18:30 test1.txt
[root@clr /opt/gzy/abc]# rm -f h-123.txt #删除硬链接h-123.txt
[root@clr /opt/gzy/abc]# ll
总用量 8
drwxr-xr-x. 3 root root 16 3月 27 09:22 123
-rw-r--r--. 2 root root 5 3月 27 18:30 h-abc.txt #硬链接数 -1,由之前的3变成2
-rw-r--r--. 2 root root 5 3月 27 18:30 test1.txt
[root@clr /opt/gzy/abc]# cat h-abc.txt #查看硬链接h-abc.txt依然可以查,依然可用
jhlk
[root@clr /opt/gzy/abc]# cat test1.txt
jhlk
注意:
When a file has multiple hard links,Modifying the file content will affect all file names; but delete a file
name, does not affect access to other file names. Deleting a file name will only decrease the "number of hard links" by 1. It should be noted that the target
Record as a hard link. Hard links to files are rarely created in day-to-day work.
软链接和硬链接的区别如下图所示:
注意:
-
The soft link can be located in a different partition from the source file, while the hard link must be located in the same partition as the source file;
-
The soft link is equivalent to the shortcut of the source file, and the hard link is equivalent to giving the file an alias, that is, "shadow";
-
The inode numbers of the source file and the soft link in the soft link are different, but the inode numbers of the source file and the hard link in the hard link are the same;