Path Variable
Path variable: The directory where the executable file (command) is recorded.
echo $PATH: View the PATH variable.
If you change the path of the LS command to/tmp/ls (using the MV command to move the/usr/bin/ls to/tmp/), you can only use the LS command with the full path/tmp/ls.
If you add/tmp to the PATH variable, you can use the LS command directly.
Path= $PATH:/tmp (assigning value to PATH variable) (temporarily active, current user current terminal is active, restart disabled)
If you want to take effect permanently, you need to modify/etc/profile (global) or ~/.BASHRC (user), and add a new directory using the above command. (General modification of/etc/profile file)
CP Command (copy)
CP Original file target: Copy file.
Cp-r Original directory target: Copy directory.
Depending on the target attribute, the effect will be different, as shown below:
-
If the target is a directory, regardless of the source (file or directory), the copy will be in the target directory;
-
If the target is a file, the source must be a file, and the copy will overwrite the target (prompting for overwrite);
-
If the target does not exist, regardless of the source, the copy will be located in the parent directory of this target and renamed.
Recommendation: When using the CP command, whether it is the source or the target, as long as the directory, it is best to take the back (the same as the tab completion of the effect), in order to separate from the file area, it is beneficial.
The CP command is actually an alias with the-I option (As with the RM command), which asks if you are sure, and if you don't want it to ask, use absolute path/USR/BIN/CP.
Cp-p files: Reserved permissions, ownership, and timestamps.
Cp-a directory: Equivalent to the CP-PR directory.
MV Command (move)
Two functions: 1. Move the file or directory (may also involve renaming, when the target file or directory does not exist);
2. Modify the file or directory name.
The MV command is also an alias, with the-I option (as with the CP command), which asks if you are sure, and if you don't want it to ask, use absolute path/USR/BIN/MV. To overwrite the directory, the overwritten directory must be empty or an error will be taken.
View File Contents
Cat: View the contents of the file.
Cat-n: View the contents of the file and display the line number.
TAC: View the contents of the file in reverse.
More: View files, split screen display. (Press the Space page, press ENTER to turn the line, press Ctrl+b to page UP, press Q to exit, after the end will automatically exit)
Less: View files, split screen display.
You can use more of all the features, the difference is:
1. It supports the arrow keys to scroll up and down.
2. You can enter/to search for content from the first line, search by N to find the next, press N to find the previous.
Input? To search for content from the last row, press N to find the previous, and press N to find the next.
3. Press G to move directly to the last line, and press G to move directly to the first line.
3. You must press Q to exit.
Head: Displays the first 10 lines of the file's contents.
Head-n 8: Displays the first 8 lines of the file. (You can also use head-8 directly)
Tail: Displays the following 10 lines of the file.
Tail-n 3: Displays the following 3 lines of the file. (You can also use tail-3)
Tail-f: Dynamically view the contents of a file, typically used to monitor logs. (The content of the file is increasing)
Linux Basic Command Two