View the current directory pwd # present work directory
Display the contents of the specified working directory ls # list of directory contents
parameter | Features |
---|---|
-a | Show all files and directories (ls defaults to treat file names or directory names beginning with "." as hidden files) |
-A | Show all, excluding hide |
-l | In addition to the document name, the document type, permissions, owner, document size and other information are also listed in detail |
-t | View according to the order of file creation time |
Change the working directory cd dirPath # change directory
The dirName notation can be an absolute path or a relative path. If the name of the directory is omitted, it will be changed to the user's home directory (that is, the directory where the user just logged in).
"~" Switch to the home directory, "." Means the current directory, and "…" means the upper directory of the current directory location.
Create a new directory mkdir dirPath # make directory
mkdir -p dirName # -p make sure that the directory name exists, create one if it does not exist, you can create multi-level directories
Delete directory rmdir dirPath #remove directory
rmdir -p dirName # -p If the parent directory becomes an empty file after deletion, delete the empty file as well.
rmdir -f dirName # If it contains subdirectories, delete them as well
Create an empty directory touch dirPath
Copy file cp source file target directory# copy
parameter | Features |
---|---|
-a | This option is usually used when copying a directory, it retains links, file attributes, and copies all contents under the directory |
-d | Keep link when copying |
-f | Overwrite the existing target file without prompting |
-i | Contrary to the -f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite, the target file will be overwritten when answering "y" |
-p | In addition to copying the content of the file, the modification time and access permissions are also copied to the new file |
-r | If the given source file is a directory file, all the subdirectories and files in the directory will be copied at this time |
-l | Do not copy files, just generate link files |
Delete file or directory rm # remove
Move files or rename mv # move or rename files
Open the file in read-only mode cat # concatenate files and print on standard output
more
more is a text filter based on the vim editor, which displays the content of the text file page by page in a full screen manner
hot key | Features |
---|---|
space | Page down |
Enter | Scroll down one line |
q | drop out |
ctrl + F | Scroll one screen |
ctrl + B | Scroll down one screen |
= | Output current line number |
:f | Output file name and line number |
less
The function of less is similar to that of more, but instead of loading the entire file at once, it is loaded as needed, which is more efficient for large files.
Redirect>
The redirection will overwrite the original content,
Append>>
Append will not overwrite, add the content to the end of the file
echo output to the console
head
head is used to display the beginning of the file, 10 lines by default.
tail
tail Outputs the contents of the end of the file, 10 lines by default.