Environment variables, cp, mv, view documentation commands

First, the environment variable PATH

echo $PATH prints the current environment variable
PATH=$PATH: path custom environment variable

  • which finds the absolute path of a command, and you can also view the alias of a command. The scope of which is searched in several directories under the PATH;

  • Why do we just type the commands without using the absolute paths of these commands when we use the commands? This is because the environment variable PATH is in effect.

  • If your commands are in these directories, you do not need to add absolute paths to the commands you type; for example:

  • The absolute path is used here. If it is not added, an error will be reported; as follows:

  • We add the ls2 directory to the PATH, and we can use the ls2 command directly. The command is as follows:

  • Note: This is only to temporarily add the /tmp/ directory to the PATH. Re-opening a terminal and using ls2 will still report an error and will not take effect. If we want to take effect permanently, we need to modify the configuration file /etc/profile; the command is as follows:

  • here is the list text then open another terminal and enter the command ls2

  • If you want to delete /tmp/; after deleting the configuration file, or directly delete the PATH=$PATH:/tmp/ just added in /etc/profile, execute the following command:

2. cp command

  • cp [options] [source file] [destination file]
  • -r copy directory
  • -v visualize
  • -i Security option, if the target file exists, prompt whether to overwrite. cp comes with the -i option

cp [options] [source file] [destination file]

cp -r copy directory, must add /;

cp -i security options

cp -v to visualize

3. mv command

  • mv is the abbreviation of move, move or rename
  • mv [options] [source file or directory] [destination file or directory]
  • Here is the list text mv command has the following situations
  1. The target file is a directory, but the directory does not exist

  1. The target file is a directory, and the directory exists

  • When the target file is a directory, the source file or directory will be moved into the directory if the directory exists, and the source directory will be renamed to the given target filename if the directory does not exist.
  1. The target file is a file and the file does not exist

  1. The target file is a file, but the file exists

  • When the target file is a file, if the file exists, it will ask whether to overwrite, and if the file does not exist, it will rename the source file to the given target file name.

Fourth, view the relevant commands of the document

cat command

  • -n: When viewing a file, also display line numbers on the screen; for example:

  • -A: Display everything, including special symbols; for example:

Note: $ terminator.

tac command

  • Like cat, viewing the contents of a file displays it on the screen, but reverses it, showing the last line first and the first line last; for example:

more command

View the content of a file. When the content of the file is too much and cannot be displayed on one screen, press the space to view it as needed

  • space scroll down
  • Ctrl+b scroll up
  • Ctrl+f scroll down

less command

Like the more command, directly followed by the file name, but with more functions than more

  • blank page
  • j key to move down
  • k key to move up
  • g cursor to the first line
  • G cursor to the end
  • / Enter a string, press Enter to search down this string, press the n key to display the next;
  • ? Enter a string, press Enter to search up this string, press the n key to display the next;

head command

Used to display the first 10 lines of the file, followed directly by the file name;

  • -n This displays the first few lines of the file; for example:

  • Note: There is no space after -n; you can also omit the letter n, and - directly followed by a number

tail command

  • Similar to the head command, the tail command is used to display the last 10 lines of a file, followed directly by the file name; for example:

  • tail -f can dynamically display the last 10 lines of the file. If the content of the file is constantly increasing, you can use the -f option to display it very intuitively. For example, tail -f /var/log/messages can dynamically view the log content in real time.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325895520&siteId=291194637