Common ubuntu file operation commands

Source: Internet
Author: User

Common ubuntu file operation commands
Mkdir command
Format: mkdir [Option] DirName
-M is used to set the access permission for the new directory. You can also use the chmod command to set the access permission.
-P is required to create an upper-level folder (or directory). If the folder (or directory) already exists, it is not considered as an error.

Cp command

Format: cp [Option] source file or directory target file or directory
-A this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of dpR options.
-D: the link is retained during copy.
-F delete an existing target file without prompting.
-I and f options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is y, the target file will be overwritten, which is an interactive copy.
-P in addition to copying the source file content, cp also copies the modification time and access permissions to the new file.
-If the source file provided by r is a directory file, cp will recursively copy all subdirectories and files in the directory. The target file must be a directory name.
-L do not copy, but only link files.
It should be noted that, in order to prevent users from using the cp command to destroy another file inadvertently, for example, if the target file name specified by the user is an existing file name, after copying the file with the cp command, this file will be overwritten by the newly copied source file. Therefore, we recommend that you use the I option when copying the file using the cp command.

Mv command (rename/move)
Format: mv [Option] source file or directory target file or directory
Note: depending on the type of the second parameter in the mv command (whether it is the target file or the target directory), the mv command will rename the file or move it to a new directory. When the second parameter type is file, the mv command renames the file. At this time, only one source file (or the source directory name) can be used ), it renames the given source file or directory to the given target file name. When the second parameter is an existing directory name, there may be multiple source files or directory parameters. The mv command moves the source files specified by each parameter to the target directory. When a file is moved across file systems, the mv copies the file first, and then deletes the original file. The link to the file will also be lost.
-I interactive operation. If the mv operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to Answer y or n. This will avoid overwrite the file by mistake.
-F prohibit interactive operations. When an mv operation overwrites an existing target file, no instructions are given. If this option is specified, the I option will no longer work.
If the target file (not a directory) already exists, the content of the file will be overwritten by the new file. To prevent users from inadvertently using the mv command to destroy another file, we recommend that you use the I option when using the mv command to move the file.
Note that the mv and cp results are different. Mv is like a "moving" file. The number of files increases at the end, while cp copies the files, and the number of files increases.

Rm command
It is easy to create files in linux, and files may become obsolete and useless at any time in the system. You can use the rm command to delete it. This command is used to delete one or more files or directories in a directory. It can also delete a directory and all its files and subdirectories. For linked files, only the links are deleted, and the original files remain unchanged.
Format: rm [Option] File
If the-r option is not used, rm will not delete the directory.
-F ignores non-existing files and never gives a prompt.
-R indicates that rm recursively deletes all directories and subdirectories listed in the parameter.
-I.
Be careful when using the rm command. Because once an object is deleted, it cannot be recovered. For example, a user accidentally mistakenly enters the rm command when entering cp, mv, or other commands. It is too late when the user presses the Enter key and realizes his or her error, the file does not exist. To prevent this, you can use the I option in the rm command to confirm each file to be deleted. If you enter y, the file will be deleted. If you enter anything else, the file will be retained. In the next example, You need to delete the files test and example. Then, each file is required to be confirmed. The user finally decided to delete the example file and keep the test file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.