01. View Directory Contents 1.1 Terminal practical Tips 1> Auto-complete
文件 目录 命令 After the first few letters of the hit//, press the tab key
- If there is no ambiguity in the input, the system will automatically complete
- If there is another
文件 / 目录 / 命令 , press the tab key again, the system will prompt for possible commands
2> have used the command
- Press the
上 / 下 cursor key to switch back and forth between commands that have been used
- If you want to exit the selection and do not want to perform the currently selected command, you can press
ctrl + c
1.2
lsCommand description
lsis the abbreviation of the English word list , its function is to list the contents of the directory, is one of the most commonly used commands, similar to DOS dir commands
Features of files and directories under Linux
- A Linux file or directory name can have
256 a maximum of one character
.the file to begin with is a hidden file and needs to be displayed with the-a parameter
- . Represents the current directory
- .. Represents the previous level of the directory
1.3 ls Common options
| Parameters | meaning |
| -A | Displays all subdirectories and files in the specified directory, including hidden files
| -L | Display file details in a list
| -H | Display file size in a humane way with-l
How file sizes are represented in your computer
| Units | English | meaning |
| bytes | B (Byte) | As a digital unit in a computer, typically a 8-bit binary number
| thousand | K (Kibibyte) | 1 KB = 1024x768 B, Kbytes (1024 = 2 * * 10)
| Mega | M (Mebibyte) | 1 MB = KB, Million bytes
| Gigabit | G (Gigabyte) | 1 GB = 1024x768, 1 billion bytes, gigabytes
| Too | T (Terabyte) | 1 TB = 1024x768, trillion bytes, MBytes
| Pat | P (Petabyte) | 1 PB = 1024x768 TB, petabyte bytes, Pat Byte
| Ai | E (Exabyte) | 1 EB = 1024x768 PB, exascale bytes, Ai byte
| Ze | Z (Zettabyte) | 1 ZB = EB, 10 trillion bytes, ze byte
| Yao | Y (Yottabyte) | 1 YB = 1024x768 ZB, 100 million bytes, Yao byte
Use of the 1.4 LS wildcard
| Wildcard characters | meaning |
| * | Represents an arbitrary number of characters
| ? | Represents any one character, at least 1
| [] | Indicates that any one of the character groups can be matched
| [ABC] | Match any of A, B, c
| [A-f] | Match any one of the characters from a to F range
02. Switch Directories 2.1
cd
cdis a shorthand for the English word change directory , which is a function of changing the current working directory and is one of the most commonly used commands for users.
Note: All Linux directories and file names are case-sensitive
| Command | meaning |
| CD | Switch to the current user's home directory (/home/user directory)
| CD ~ | Switch to the current user's home directory (/home/user directory)
| Cd. | Remains unchanged in the current directory
| CD ... | Switch to Parent directory
| CD-| Can switch back and forth between the last two working directories
2.2 Relative and absolute paths
- relative path at input path, first not / or ~, relative to the directory location where the current directory is located
- Absolute path in the input path, the first is / or ~, indicating the specific directory location starting from the root/home directory
03. Create and DELETE operations 3.1
touch
- Create a file or modify a file time
- If the file does not exist , you can create a blank file
- If the file already exists , you can modify the last modified date of the file
3.2
mkdir
| Options | meaning |
| -P | Directory can be created recursively
the name of the new directory cannot be the same as the existing directory or file in the current directory
3.3
rm
- Delete a file or directory
Use rm the command with caution because the file cannot be recovered after deletion
| Options | meaning |
| -F | Forced deletion, ignoring nonexistent files without prompting
| -r | To delete the contents of a directory recursively, this parameter must be added when Deleting a folder
04. Copying and moving files
| Serial number | Command | Correspondence in English | function |
| 01 | Tree [directory Name] | Tree | List the file directory structure in a tree view
| 02 | CP source File Destination File | Copy | Copy files or directories
| 03 | MV Source file Destination File | Move | Move files or directories/files or directories to rename
4.1
tree
treecommand to list the file directory structure in a tree view
| Options | meaning |
| -D | Show only Directories
4.2
cp
cpThe function of a command is to copy the given file or directory to another file or directory , which is equivalent to a DOS copy command
| Options | meaning |
| -I. | Prompt before overwriting files
| -r | If the given source file is a directory file, the CP will recursively replicate all subdirectories and files in that directory, and the destination file must be a directory name
4.3
mv
mvCommands can be used to move files or directories , or to rename files or directories
| Options | meaning |
| -I. | Prompt before overwriting files
05. View the contents of a file
| Serial number | Command | Correspondence in English | function |
| 01 | Cat file name | Concatenate | Ability to view file contents, create files, merge files, append file contents, and more
| 02 | More File names | more | Split-screen display of file contents
| 03 | grep search text File name | grep | Search for text file contents
5.1
cat
catCommands can be used to view file contents , Create files , merge Files , append file contents , etc.
catDisplays all content at once, suitable for viewing text files with less content
| Options | meaning |
| -B | Number of non-null output lines
| -N | Numbering all lines of the output
Linux also has one nl command and cat -b the effect is equivalent
5.2
more
moreCommands can be used to display the contents of a file on a split screen, displaying only one page at a time
- Suitable for viewing text files with more content
moreoperating keys to use:
| Operation Keys | Features |
| Space Key | Show the next screen of the man page
| Enter key | One row of the scroll manual page
| B | Roll back one screen
| f | Roll forward one screen
| Q | Exit
| /word | Search Word string
5.3
grep
- Commands in Linux systems
grep are a powerful text-search tool
grepAllow the text file to pattern lookup, so-called pattern lookup, also known as regular expression, in the employment meeting detailed explanation
| Options | meaning |
| -N | Display matching lines and line numbers
| -V | Display all lines that do not contain matching text (equivalent negation)
| -I. | Ignore case
- Two common modes of finding
| Parameters | meaning |
| ^a | Beginning of line, searching for lines beginning with a
| ke$ | End of line, search for lines ending with ke
06. Other 6.1
echo 文字内容
echoThe text specified in the parameter is displayed in the terminal and is typically used in conjunction with redirection
6.2 Redirects
>And
>>
- Linux allows command execution results to be redirected to a file
- Output/Append content that should be displayed on the terminal to the specified file
which
>Represents the output, overwriting the original contents of the file
>>Represents an append that appends content to the end of an existing file
6.3 Piping
|
- Linux allows the output of one command to be piped as input to another command
- Can understand the real life of the pipe, the pipe of a plug in, the other side out, where the left and
| right are divided into two ends, the end of a plug thing (write), and take something at the end (read)
Common pipeline commands are:
more: Split screen display content
grep: Queries the specified text based on the result of the command execution
03_ common commands for files and directories