1. Switch directory cd
1.1 Return to a certain level of directory
cd dirName1/dirName2/dirName3/
dirName1, dirName2, dirName3 represent a certain directory;
1.2 Return to the parent directory
cd ../
can also be written as:
cd ..
1.3 Return to home directory
cd ~
1.4 Return to the previous directory
cd -
Second, view the directory ls
2.1 View the current directory
ls
Display the files and directories under the current directory;
-l lists the detailed information of files and directories, which can be abbreviated as ll;
-a lists all files and directories in the current directory, including hidden files or directories;
ll
3. Create directory mkdir
3.1 Create a first-level directory
mkdir dirName
dirName indicates a certain directory;
Create dirName directory under the current directory;
3.2 Create a multi-level directory
mkdir -p dirName1/dirName2/dirName3/
dirName1, dirName2, dirName3 represent a certain directory;
Create the dirName1 directory under the current directory, where the dirName1 directory contains the dirName2 directory, and the dirName2 directory contains the dirName3 directory;
Note: -p cannot be omitted;
Fourth, create a file touch
4.1 Create a single file
touch file.*
file.* indicates a certain type of file (eg: file.txt, file.cfg, file.ini, file.db, file.dat, file.xml, etc.);
In the current directory, create file.* files;
Note: You can not specify the file type, that is, do not add the file suffix, such as:
touch file
In the current directory, create a file file;
4.2 Create multiple files
touch file1.* file2.* file3.*
file.* indicates a certain type of file (eg: file.txt, file.cfg, file.ini, file.db, file.dat, file.xml, etc.);
In the current directory, create file1.*, file2.*, file3.* files;
Note: The files created are all new empty files;
Five, delete the file rm
5.1 Delete a single file
rmdir file.*
file.* indicates a certain type of file (eg: file.txt, file.cfg, file.ini, file.db, file.dat, file.xml, etc.);
Delete file.* files in the current directory;
5.2 Delete multiple files
rm file1.* file2.* file3.*
Delete file1.*, file2.*, file3.* files in the current directory;
The files that need to be deleted together can continue to be added later, and so on;
6. Delete the directory rmdir/rm
6.1 Delete a single empty directory
rmdir dirName
dirName indicates a certain directory;
Delete the dirName directory under the current directory;
Note: rmdir can only delete empty directories;
6.2 Delete multiple empty directories
rmdir dirName1 dirName2 dirName3
dirName1, dirName2, dirName3 represent a certain directory;
Delete dirName1, dirName2, dirName3 directories in the current directory;
The empty directory that needs to be deleted together can continue to be added later, and so on;
6.3 Delete a single non-empty directory
rm -r dirName
dirName indicates a certain directory and the directory is not empty;
Delete the dirName directory under the current directory;
Note: -r cannot be omitted;
6.4 Delete multiple directories
rm -r dirName1 dirName2 dirName3
dirName1, dirName2, and dirName3 represent a certain directory, which can be a non-empty directory or an empty directory;
Delete dirName1, dirName2, dirName3 directories in the current directory;
The directory that needs to be deleted together can continue to be added later, and so on;
Seven, move or rename files or directories mv
7.1 Double Naming
mv fileName1 fileName2
fileName1 indicates the name of the original file or directory, and fileName2 indicates the name of the renamed file or directory;
In the current directory, change the name of fileName1 to fileName2;
7.2 Moving files
mv fileName dirName1/dirName2/dirName3/
In the current directory, move fileName to the directory dirName1/dirName2/dirName3/;
7.3 Moving directories
mv dirName1/dirName2/dirName3/ dirName11/dirName22/dirName33/
In the current directory, move dirName1/dirName2/dirName3/ to the dirName1/dirName2/dirName3/ directory;
Eight, copy copy cp
8.1 Copy files to files
cp file1.* file2.*
file1.*, file2.* represent a certain file;
In the current directory, copy the content of file1.* to file2.*. If the second file does not exist, create the file first, and then copy the content. If present, overwrite without warning;
Add the -i option, it will ask before overwriting, and the rest of the operations are the same;
cp -i file1.* file2.*
Add the -f option to force a copy when copying, and the rest of the operations are the same;
cp -f file1.* file2.*
8.2 Copy a single file to a directory
cp file.* dirName
file.* means a certain file, dirName means a certain directory, the directory can be non-empty or empty, but the directory must exist;
In the current directory, copy the file.* files to the dirName directory;
8.3 Copy multiple files to a directory
cp file1.* file2.* file3.* dirName
file1.*, file2.*, file3.* represent a certain file, dirName represents a certain directory, the directory can be a non-empty directory or an empty directory, but the directory must exist;
In the current directory, copy the file1.*, file2.*, file3.* files to the dirName directory;
8.4 Copy a single directory into a directory
cp -r dirName1 dirName2
dirName1, dirName2 represent a certain directory;
In the current directory, copy dirName1 to dirName2, if dirName2 exists, directly copy dirName1 to the dirName2 directory; if dirName2 does not exist, it will be created first, and then copy the contents of dirName1 to dirName2;
Note: -r cannot be omitted;
8.5 Copy multiple directories into a directory
cp -r dirName1 dirName2 dirName3 dirName4
dirName1, dirName2, dirName3, dirName4 represent a directory;
In the current directory, copy dirName1, dirName2, dirName3 to dirName4;
You can also copy files and directories to the directory at the same time;
cp -r file1.* file2.* file3.* dirName1 dirName2 dirName3 dirName4
Note: -r cannot be omitted;