How to copy, delete, and move Linux files

Source: Internet
Author: User
Tags tmp folder
The cp command is used to copy files from one location to another. If the destination file exists, the file will be overwritten; if the destination directory exists, the file will

Cp copy command
The cp command is used to copy files from one location to another. If the destination file exists, the file will be overwritten; if the destination directory exists, the file will be copied to this directory (the directory will not be rewritten ).

Syntax:
Syntax:
Cp [command switch]... SOURCE DEST
Cp [OPTIONS]… SOURCE... DIRECTORY
Cp [OPTIONS]… -Target-directory = directory source...

Command switch:
-A is equivalent to-dpR.
-Backup [= CONTROL] backs up each existing target file.
-B is like-backup, but does not accept the parameter.
-F if the target file cannot be opened by the write operation, delete it and try again.
-P is equivalent to-preserve = mode, ownership, timestamps (retention mode, owner and timestamp information ).
-Preserve [= ATTR_LIST] retains the specified attributes (default attribute: mode, owner, timestamp) and security configuration. if possible, add the additional attributes: connection, all.
-No-preserve = ATTR_LIST does not retain the specified attribute.
-Add the source path to the directory of parents.
Example:

C. copy two files:
Cp file1 file2 the above cp command copies the content of the file file1.php to the file file2.php.

Copy the backup file:
Cp-B file1.php file2.php creates the file file1.php with the symbol '~ 'Backup file file2.php ~.
Copy folders and subfolders:
The cp command above cp-R scripts scripts1 copies folders and subfolders from scripts to scripts1.
Mv Mobile Command
The mv command is short for moving. Use it to move/rename a file from a directory to a directory. Unlike the cp command, the mv command completely moves the file from the source and moves the file to the specified directory. here the cp command only copies the file content from one file to another.
Syntax:
Syntax:
Mv [-f] [-I] Original name new name
Command switch:
-F is not prompted before overwriting (equivalent to is equivalent to-reply = yes ). mv-f will move the file (multiple files) without prompting, even if it will re-write the existing target file.
-I prompt before re-writing another file
Example:

To Rename/Move a file:
Mv file1.txt file2.txt
The name of this command is file2.txt.
To move a directory
Move a directory
Mv hscripts tmp
In the preceding command, if the tmp directory already exists, the mv command moves all files, directories, and subdirectories in the hscripts folder/directory to the tmp directory. If no tmp directory exists, it will rename the hscripts directory to the tmp directory.
Move multiple files/more prices to another directory
Mv file1.txt tmp/file2.txt newdir
This command moves the file1.txt file of the current directory and the file2.txt file of the tmp folder/directory to the newdir directory.
Rm delete command
The rm linux command is used to remove/delete files in the directory.
Syntax:
Syntax:
Rm [command switch ..] [file | Directory]
Command switch:
-F: If you are not prompted, delete all files in the directory.
-I interaction mode. With this option, the rm command prompts the user to confirm before deleting any files.
-R (or)-R recursively deletes the directories and their subdirectories in the parameter table. The directory will be cleared and deleted. Users are usually prompted to delete write-protected files in a directory.
Example:

Remove/delete files:
Rm file1.txt
Here, the rm command will remove/delete the file1.txt file.
Delete directory tree:
Rm-ir tmp
Here, the rm command recursively deletes the contents of all sub-directories in the tmp Directory. you will be prompted for the deletion of each file, and then delete the tmp directory itself.
Delete multiple files at a time.
Rm file1.txt file2.txt
Delete the file1.txt and file2.txt files at the same time.

Related Article

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.