Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Instructions for Linux file copy, delete, and move commands

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the "instructions for the use of Linux file copy, delete and move commands". In the daily operation, I believe that many people have doubts about the instructions for the use of Linux file copy, delete and move commands. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "instructions for the use of Linux file copy, deletion and movement commands". Next, please follow the editor to study!

Cp copy command

The cp command copies files from one location to another. If the destination file exists, it will be overwritten; if the destination directory exists, the file will be copied to that directory (the directory will not be overwritten).

Syntax:

The grammar is

Cp [command switch]... SOURCE DEST

Cp [OPTIONS]... SOURCE... DIRECTORY

Cp [OPTIONS]... -target-directory=DIRECTORY SOURCE...

Command switch:

-an is equivalent to-dpR.-backup [= CONTROL] to make a backup of every target file that exists. -b is like-backup, but does not accept parameters. -f if the existing target file cannot be opened by the write operation, delete it and try again. -p equals-preserve=mode,ownership,timestamps (retention mode, owner, and timestamp information). -preserve [= ATTR_LIST] retains the specified attributes (default attributes: mode, owner, timestamp) and security configuration, and adds additional attributes, if possible: connection, all. -no-preserve=ATTR_LIST does not retain the specified properties. -parents adds the source path under the directory.

Example:

C copy two files:

Cp file1 file2 the above cp command copies the contents of the file file1.php into the file file2.php.

Back up the copied files:

Cp-b file1.php file2.php creates a backup file file2.php~ with the sign'~ 'for the file file1.php.

Copy folders and subfolders:

The cp command on the cp-R scripts scripts1 copies folders and subfolders from scripts to scripts1.

Mv move command

The mv command is an abbreviation for move. Use it to move / rename files from a directory to a directory. The mv command is different from the cp command, the mv command completely moves the file from the source and moves the file to the specified directory, where the cp command simply copies the contents of the file from one file to another.

Syntax:

The grammar is

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 files (multiple files) without prompting, even if it will overwrite the existing target file. -I make a prompt before copying another file

Example:

To Rename / Move a file:

Mv file1.txt file2.txt

This command renames the file1.txt file to file2.txt.

To move a directory

Move a directory

Mv hscripts tmp

In the above command, if the tmp directory already exists, the mv command will move all files, directories, and subdirectories under the hscripts folder / directory to the tmp directory. If there is no tmp directory, it renames the hscripts directory to the tmp directory.

Move multiple files / more asking 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 a directory.

Syntax:

The grammar is

Rm [command switch..] [file | Directory]

Command switch:

-f delete all files in the directory without prompting the user. -I interaction mode. With this option, the rm command prompts the user for confirmation before deleting any files. -r (or)-R recursively deletes the directory and its subdirectories in the parameter table. The directory will be emptied and deleted. The user is usually prompted when deleting a file with write protection contained in a directory.

Example:

Remove / delete files:

Rm file1.txt

Here the rm command will remove / delete the file file1.txt.

Delete the directory tree:

Rm-ir tmp

Here the rm command recursively deletes all the subdirectories under the tmp directory, prompts you for the deletion of each file, and then deletes the tmp directory itself.

Delete more than one file at a time.

Rm file1.txt file2.txt

The rm command deletes both the files file1.txt and file2.txt.

At this point, the study on the "instructions for the use of Linux file copy, delete and move commands" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report