Linux introductory training tutorial under linux copy cp delete rm move mv command parameters and instructions


Copy, move and delete looks so simple in Windows, but Linux often uses the text interface, so for the Linux system

, copy cp delete

rm
move mv command parameters, you have to understand and learn the function of the

  cp

  command will be given. Copying a file or directory to another file or directory is as powerful as the copy command under MSDOS.

  Syntax: cp [option] source file or directory target file or directory

  Description : This command copies the specified source file to the target file or copies multiple source files to the target directory.

  The meanings of the options of this command are as follows:

  - a This option is usually used when copying directories. It preserves links, file attributes, and recursively copies directories, and acts as a combination of dpR options.

  -d preserve links when copying.

  -f Delete existing object files without prompting.

  The -i option is the opposite of the f option and will prompt the user for confirmation before overwriting the target file. When answering y, the target file will be overwritten, which is an interactive copy.

  -p At this time, cp will not only copy the content of the source file, but also copy its modification time and access rights to the new file.

  -r If the given source file is a directory file, then cp will recursively copy all subdirectories and files in the directory. In this case the target file must be a directory name.

  - l does not make a copy, just links the file.

  It should be noted that, in order to prevent the user from inadvertently destroying another file with the cp command, if the target file name specified by the user already exists, after copying the file with the cp command, the file will be overwritten by the new source file. Therefore, It is recommended that users use the i option when using the cp command to copy files.

  mv command

  Users can use the mv command to rename files or directories or move files from one directory to another. This command is like a combination of ren and move in MSDOS.

  Syntax: mv [options] source file or directory target file or directory

  Description : Depending on the type of the second parameter in the mv command (target file or target directory), the mv command renames the file or moves it to a new one in the directory. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (or the source directory name), and it renames the given source file or directory to the given one. target filename. When the second parameter is the name of an existing directory, there can be multiple source file or directory parameters, and the mv command moves the source files specified by each parameter to the target directory. When moving a file across filesystems, mv first copies and then deletes the original file, and the link to the file will also be lost.

  The meaning of each option in the command is:

  - I Operation in interactive mode. If the mv operation will result in overwriting the existing target file, the system asks whether to overwrite, and the user is required to answer y or n, which can avoid overwriting the file by mistake.

  -f Suppresses interactive operations. No instruction is given when the mv operation is to overwrite an existing target file. After this option is specified, the i option will no longer work.

  If the given target file (not a directory) already exists, the contents of the file will be overwritten by the new file. To prevent users from corrupting another file with the mv command, it is best to use the i option when using the mv command to move files.

  rm command

  Users can use the rm command to delete unnecessary files. The function of this command is to delete one or more files or directories in a directory. It can also delete a directory and all files and subdirectories under it. For linked files, the link is just broken, and the original file remains unchanged.

  The general form of the rm command is:

  rm [options] files...

  If the -r option is not used, rm does not delete directories.

  The meanings of the options of this command are as follows:

  -f Ignore non-existing files and never prompt.

  -r instructs rm to recursively delete all directories and subdirectories listed in the argument.

  -i for interactive deletion.

  Be careful with the rm command. Because once a file is deleted, it cannot be recovered. To prevent this from happening, you can use the i option to confirm the files to delete one by one. If the user enters y, the file will be deleted. If you enter anything else, the file is not deleted.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326556019&siteId=291194637