What are the commands to modify file names in Linux?

小老鼠
Release: 2023-10-26 14:46:17
Original
3817 people have browsed it

Linux commands to modify file names include mv command, rename command, touch command, sed command, etc. Detailed introduction: 1. The mv command is used to rename files or directories, or move files from one directory to another. The syntax is "mv source file name target file name"; 2. The rename command is used to modify file names in batches. The syntax is "rename 'original file name' 'new file name' file list"; 3. touch command, etc.

What are the commands to modify file names in Linux?

#In Linux systems, there are a variety of commands that can be used to modify file names. The following are some commonly used commands:

  1. mv command: The mv command is used to rename files or directories, or move files from one directory to another. The syntax is:
mv  源文件名  目标文件名
Copy after login

For example, to rename a file named "file1.txt" to "file2.txt", you can use the following command:

mv  file1.txt  file2.txt
Copy after login
  1. rename command: The rename command is used to modify file names in batches. The syntax is:
rename  '原始文件名'  '新文件名'  文件列表
Copy after login

For example, you want to rename the files named "file1.txt", "file2.txt" and "file3.txt" to "file1_new.txt" and "file2_new" respectively. .txt" and "file3_new.txt", you can use the following command:

rename  'file'  'file_new'  file1.txt  file2.txt  file3.txt
Copy after login
  1. touch command: The touch command is used to change the timestamp of the file, and can also be used to modify the file name. The syntax is:
touch  -d  日期时间  文件名
Copy after login

For example, to modify the file named "file1.txt" to the current date and time, you can use the following command:

touch  -d  "$(date)"  file1.txt
Copy after login
  1. sed command : The sed command is used for stream editing and can be used to modify file names in batches. The syntax is:
sed  's/原始文件名/新文件名/g'  文件列表  >  新文件列表
Copy after login

For example, you want to rename the files named "file1.txt", "file2.txt" and "file3.txt" to "file1_new.txt" and "file2_new" respectively. .txt" and "file3_new.txt", you can use the following commands:

sed  's/file/file_new/g'  file1.txt  file2.txt  file3.txt  >  file1_new.txt  file2_new.txt  file3_new.txt
Copy after login

These commands can modify the file name to a certain extent. Which method to use depends on your needs and preferences.

The above is the detailed content of What are the commands to modify file names in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!