LINUX basic operation commands (two)

Statistics directory file space occupation-du

◆Statistics of the size of the disk space occupied by the specified directory (or file)
du [Options] [File or directory]
◆Common options

Options Description
-a Including all files, not just directories, when counting disk usage
-h Display the statistical results in a more user-friendly way (the default count is KB, but the unit is not displayed)
-s Only count the total size of the occupied space, not the size of each sub, directory, and file
- -max-depth=n Count the total size of all directories less than or equal to the Nth level

Note: -a and -s cannot be used at the same time.
Insert picture description here
Note: The proc file is a kernel parameter mapped by the system, not a real kernel file. This command cannot be read

Create a new directory-mkdir

◆Create a new directory
mkdir [Options] Directory location and name
Insert picture description here

Note: mkdir -p: create nested multi-level directories at onceInsert picture description here
Insert picture description here

In addition, the tree structure shows the search command: yum -y install tree, which is an external command and needs to be loaded and installed
Insert picture description here

Create empty file-touch command

◆Time stamp of update file
Insert picture description here

◆It is often used to create multiple new spatial files
touch file
touch file name file name
touch {name, name}. file type
touch name. {file type 1, file type 2}
Insert picture description here

Create link file -ln

◆Create link files for files or directories, similar to shortcuts in windows system

◆Link file type
1. Soft link (also called symbolic link)
ln [-s] source file or directory link file or target location
Insert picture description here
Note: aa.txt source file abc.txt is a soft link file Insert picture description here
Note: delete the source file, soft link The link file still exists, but the viewing source file does not exist. By viewing the hidden file soft link still exists, all only the soft link is completely deleted.

2. Hard link
Insert picture description here
I edited the bb.txt file, but after viewing the two files, the content is the same, both
Insert picture description here

◆The difference between soft link and hard linkInsert picture description here

file type Soft link Hard link
Delete source file effect Invalidation Still available (the file takes up the same space as the source file)
Use range Applicable files and directories Only for files
Save location Can be in a different file system from the source file Must be in the same file system (that is, the same partition) as the source file
Relationship with source files Equivalent to shortcut It is equivalent to giving a file an alias
inode Different inode numbers Same inode number

◆In Linux, the file name and file data are stored separately.
1. In Linux, only the hard link of the file=0 will be deleted
2. Use ls-l to view the number of hard links of a file
3. In daily work In, hard links to files will not be established
4. When a file has multiple hard links, modification of the file content will affect all file names, but deleting a file name will not affect the access of other files, delete one The file name will only reduce the number of hard links by 1. It should be noted that hard links to directories cannot be made, and hard links to files are hardly established in daily work

Copy files or directories-cp

◆Rebuild a copy of the file or directory (source) that needs to be copied, and save it as a new file or directory
cp [option] source file or directory target file or directory
◆Common option
-f: not when overwriting the file or directory with the same name as the target Remind, and force the copy directly
-i: remind the user to confirm when overwriting the file or directory with the same name as the target
-p: keep the permissions, attributes, time stamp and other attributes of the source file unchanged
during copying -r: must use this item when copying the directory , Means recursively copy all files and subdirectories.
Note: When copying multiple files and directories, the target location must be a directory, and the target must already exist

Delete files or directories -rm

Delete the specified file or directory
rm [Options] The file or directory to be deleted
◆Common option
-f: delete the file or directory without reminding, but directly force deletion
-i: remind the user to confirm when deleting the file or directory, (y means delete , N means not to delete)
-r: This option must be used when deleting a directory, which means that the entire directory number is deleted recursively, and it needs to be used with caution.
Note: Do not directly delete the existing directories or configuration files in the system to avoid unexpected failures.
rm -rf /etc/yum.repos.d/*
rm -rf ./*

Move files or directories -mv

◆Move the specified file or directory to the location
◆If the target location is the same as the source file location, it is equivalent to perform a rename operation
mv [Options] The source file or directory target file or directory
mv command can only rename a single file, you can use rename Command batch modify file name
rename old character new character target file

Priority of command execution
First priority: the command of the specified path, absolute path /boot/pwd.sh or relative path. /pwd.sh
Second priority: Commands specified by aliases
Third priority: Internal commands
Fourth priority: Hash command
There is a hash table under Linux system. When you just start the system, this hash table is empty. When a command is executed, the hash table will record the path of the command, which is equivalent to a cache. The path of the command is searched under the path of the shell interpreter of the first execution command. When you use the command for the second time, the shell interprets The server will first check the hash table, and search under the PATH path if there is such a command. The hash table can increase the call rate of the command.
Fifth priority: search through the search order defined by PATH

Find the directory where the command file is stored -which

The search range is determined by the environment variable PATH (echo $PATH)
which command | program name * default when the first target is found, no further search
which -a command | program name * search in all search paths
Note: use which to find inside When commanding, the corresponding program will not be found

Find a file or directory-find

Recursive method is used to accurately search according to different attributes such as target name, type, size, etc.
find [Search range] [Search condition expression]
Search range: find the directory location of a file or subdirectory
Search condition expression: find condition type
◆Commonly used Search condition type

Lookup type Keyword Description
Find by name -name According to the name of the file to search, allow to use * or? Wildcard
Find by file size -size Search according to the size of the target file, generally use +,-to set the search condition that exceeds or is less than the specified size. Commonly used capacity units include kB\MB\GB
Find by file owner -user Search based on whether the file belongs to the target user
Search by file type -type Search according to the type of file. File types include ordinary file f, directory d, block device file b, character device file c, etc.; block device file: devices that read data in blocks such as hard disks, memory, and CD-ROM drives; character device files: Devices that read data by a single character such as keyboards and mice

◆Use the find command to achieve multiple query conditions
. Logical operators between expressions
-a: means and (and)
-o: means or (or)

◆The exec usage of find
1. The Linux command is followed by the -exec parameter, which is a semicolon ";" as the end sign. Since the semicolon in each system has different meanings, a backslash is added before the semicolon The slash escape character "\"
{} means the file name found by the previous find 2. The find
command matches all the ordinary files in the current directory, and uses the ls-l command in the -exec option to list them
find. / -type f exec ls-l {};

Insert picture description here

Guess you like

Origin blog.csdn.net/Dark_Tk/article/details/112967852
Recommended