one

    • Set -u // Terminates execution of the script whenever an error occurs
  1. Set +e // set +e indicates to disable the -e option and set -e indicates to enable the -e option.
  2. Set -o pipefail // If one subcommand fails, the entire pipe command fails and the script terminates.

Set-euxo Pipefail

2 set-eux set-o pipefail

These two notations are usually placed at the head of all bash files

two

1. The cp command

Cp [option] Source file or directory Destination file or directory # This command copies the specified source file to the destination file or copies multiple source files to the destination directory

Eg: cp -rf a/ b/ # copy all contents of a folder to b file

The meanings of the options in the command are as follows: -a This option is used when copying directories. It preserves links, file attributes, and copies directories recursively, equal to a combination of dpR options. -d Retain links for copying. -f Deletes an existing target file without prompting. The -i option is the opposite of the f option, prompting the user for confirmation before overwriting the target file. The object file will be overwritten when y is answered. It is an interactive copy. -p In addition to copying the content of the source file, cp copies the modification time and access permission of the source file to the new file. -r If the source file is a directory file, cp recursively copies all subdirectories and files in the directory. The target file must be a directory name. -l Does not copy files, but links files. To be sure, in order to prevent the user in the case with the cp command destroy another file, such as the user to specify the target file name is an existing file name, use the cp command copies files, this file will be covered by a new copy of the source file, therefore, recommend that users in the use of cp command copies files, it is best to use the -i option. * If the target file does not exist, a new target file will be created and the source content will be added to the target file. * If the target file is an existing file, the source content will be overwritten to the target file. * If the target file is a directory, a new file with the same name as the source file will be created in the target directory and the source content will be added to the new file

  • If the source directory is multiple files, the target directory must exist. In other cases, an error occurs when the source directory is a directory. The -r option is used to indicate that the recursive * target does not exist, and a specified directory is created

———————————————— Copyright notice: This article is originally published BY CSDN blogger “Zexizhai Wei”. It is subject to CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement. The original link: blog.csdn.net/vv19910825/…

2. The mv command

Using the rename command, you can rename a file or directory or move the file or directory to another location.

  1. Mv source_file(file) dest_file(file) # change the source filename source_file to the destination filename dest_file
  2. Mv source_file(file) dest_directory # move the file source_file to the destination directory dest_directory
  3. Mv source_directory(directory) dest_directory(directory) # dest_directory exists. If the directory name dest_directory does not exist, the source_directory is renamed dest_directory
  4. Mv source_directory dest_file file error

3. Run the mkdir command to create a directory

Command is used to create a directory.

  1. -p Creates a directory name if it does not exist.

  2. Mkdir -p runoob2/test Creates a two-level directory

  3. Create a directory with permission 777

mkdir -m 777 test3

4. Create /text5/text6 in the current directory with the permission 750 mkdir -p-m 750 text5/text6

-m –mode= mode, set directory permissions when creating a directory; -p –parents create the parent directory if the parent directory has not already been created; -v –verbose Displays information every time a new directory is created. -h –help Displays help information

4. Create a file

TXT create two files 3.> overwrite the original file without any prompt 4.>> append to the original file without overwriting the original file 5. And command line writing 6. Ls > a.t xt file created a.t xt and the current file name written at the same level 7. Ls > > a.t xt with 6 8. Ps – ef | grep Java > a.t xt grep create file (writes the result to file) 9. Echo $PATH > a.txt cho create a file (write the result to the file) 10.cp a.txt c.txt create a file if the target file is a new file 11.cat >> aa. TXT << eof Cat >> zz. TXT << exit the same as 11

5. Delete files

Rm -rf /a/ Delete all files in directory A

-r is the downward recursion, no matter how many levels of directories are deleted. -f is the forcible deletion without any warning. -I asks whether to delete the directory

6. Shell obtains the current directory and upper-level directory paths

Current Directory (PWD) Upper Directory (PWD) Upper directory (PWD) Upper directory (dirName $(PWD))

To be continued…

Welcome to follow. Public number: programmer snail, share the bit of technology encountered, accumulated experience //