深度阅读

How can I copy, move or rename files in Linux using the cp, mv and rename commands?

作者
作者
2023年08月22日
更新时间
12.76 分钟
阅读时间
0
阅读量

Here are some examples of how to use the cp, mv, and rename commands in Linux:

To copy a file named “file.txt” to a directory named “new_dir”:

cp file.txt new_dir/

To move a file named “file.txt” to a directory named “new_dir”:

mv file.txt new_dir/

To rename a file named “old_name.txt” to “new_name.txt”:

rename 's/old_name/new_name/' old_name.txt

(Note that for the rename command, you need to provide a “search pattern” and a “replace pattern” for the file name)

Here are some additional examples of how to use the cp, mv, and rename commands in Linux

Certainly! Here are some additional examples of how to use the cp, mv, and rename commands in Linux:

To copy all files in the current directory to a subdirectory named “backup”:

cp * backup/

To move all files in the current directory to a subdirectory named “old”:

mv * old/

To rename all files in the current directory with the “.txt” extension to have a “.docx” extension:

rename 's/.txt$/.docx/' *.txt

(Note that for the rename command, we use a regular expression to search for all files with the “.txt” extension)

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。