LS (list) command
ls [ 选项 ] <目录或文件位置>
Options :
-L: (long format) list displays the contents of the directory, showing permissions, time and other information
-A: Displays information for all subdirectories and files
-A: The function is basically the same as the-a option, "." "..." Two special hidden targets are not displayed
-D: Displays the properties of the directory itself and does not display content in the directory
-H: Displays the size of the directory or file in a more humane way, with the-l option
-R: Recursively displays all content in the specified directory and its subdirectories
Example :
ls -lA /etc/
Long format displays all hidden files or directories under/etc/
ls -lh /etc/
Display the information of all files and directories in the/etc/directory in a long-form user-friendly (unit from byte to k/m/g, etc.)
ls -lhd /etc/
User-friendly display of/etc/directory information in long format
ls -R /etc/
Recursively displays information about all files and subdirectories that are/etc/blind
Du (disk usage) command
du [ 选项 ] <文件或目录的位置>
Used to count the size of the self-disk space occupied by a specified directory (or file)
Options :
-A: Statistical disk space consumption includes all files, not just the statistics directory
-H: Display results in a more user-friendly way (by default in kilobytes, but not in units)
-S: Only the total size of the occupied space is counted, and the size of each subdirectory and file is not counted.
Example :
du -sh /etc/
Count the size of the/etc/directory
mkdir (make directory) command
mkdir [ 选项 ] <目录位置及名称>
Options :
-P: Create nested multi-level catalogs at once
Example :
mkdir/hiahia///Create Hiahia under the root directory
Mkdir-p/data/hiahia///Create/data/directory and create/data/hiahia/directory in sequence
Touch command
touch <文件位置及名称>
Creates an empty file for testing, and when the directory already exists, updates the time stamp for the file
Example :
touch /tmp/hiahia.txt
Create a hiahia.txt empty file under the TMP directory
touch /tmp/{a..z}
Create a new letter from A-Z in the/tmp/directory
CP command
cp [ 选项 ] <源文件或目录> <目标文件或目录>
Options :
-F: Override the target file or directory with the same name without a reminder and direct force replication
-I: Alert user when overwriting the target file or directory with the same name (Interactive, interactive)
-P: Preserve (Preserve) source file permissions, owner and time tags, and so on while copying
-r: This option must be used when copying directories, indicating that all files and subdirectories are replicated recursively
Example :
cp /etc/hosts /tmp/
Copy the/etc/hosts file to the/tmp/directory
cp /etc/hosts /tmp/hehe
Copy the/etc/hosts file to the/tmp/directory and rename it to hehe file
cp -r /etc/ /tmp/
Copy all contents of/etc/directory to/tmp directory;-r: Add-r option when copying directories
cp -p /etc/hosts.bak /tmp/
Copy the/etc/hosts.bak file to the/tmp directory and save the original permissions
RM (remove) command
rm [ 选项 ] <要删除的文件或目录>
Options :
-F: No reminders, direct force removal
-I: Remind users to confirm
-r: Recursively delete entire directory tree
Example :
Rm-f/tmp/hosts//Do not ask to forcibly delete/tmp/hosts files
rm-rf/tmp/etc///Do not ask to delete/tmp/etc/directory
* Note: "RM-RF/", command is extremely dangerous, do not try * *
MV Command
mv [ 选项 ] <源文件或目录> <目标文件或目录>
1. Transfer the established files or directories to the location
2. If the target location is the same as the original location, it is equivalent to performing a rename operation
Example :
mv /etc/hosts.bak /tmp/
Move the/etc/hosts.bak file to the/tmp/directory and save the original file name
mv /etc/hosts.bak /tmp/hehe
Move the/etc/hosts.bak file to the/tmp/directory and change the name to hehe
mv /etc/hosts /etc/hosts.bak
Rename the/etc/hosts file to Hosts.bak
which command
which <命令> | <程序名> ( | 表示二选一)
Find the location of your Linux command program
1. The first target is found by default and no longer continues to find
2. If you are looking in all search paths, add the "-a" option
3. Unable to find the program file corresponding to the internal command
Example :
which ls
Search the full path of the LS command
which CD//search the full path of the CD command
Note : It is important to note that which can only search external commands during use.
Find command
find [ 查找范围 ] [ 查找条件 ]
Fine-grained search for files or directories
Common search Criteria :
Find by name: "-name", wildcard "*", "?" Supported
Find by file size: "-size", can use "+", "-" as capacity conditions
Search by file owner: "-user"
Find by File type: "Type"
Example :
find /etc/ -name "host*"
Search all files or directories under the/etc/directory that begin with host
find /etc/ -name "host?"
Search all files or directories under the/etc/directory that begin with host
find /etc/ -size +1M
Search all files or directories larger than 1M in the/etc/directory
find /etc/ -size -1M
Search all files or directories less than 1M in the/etc/directory
find /boot/efi / -user root
Search for all files or directories under the/boot/efi/directory that were created as root
find /etc/ -type d
Search all directories under the/etc/directory
logical operators :
? -A: and (and), show all the results of all conditions satisfied
? -O: or (or) to display results that meet one of the conditions
find / -type d -a -name vm*
Search/Lower directory and start with a directory named VM
find / -type d -o -name vm*
Search/Next Directory or/bottom file or directory starting with VM
Linux basic Commands (i)