Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux System Getting Started Learning: rename multiple files in Linux     - Single-node Hadoop environment to build (Server)

- Analysis of C ++ exception mechanism (Programming)

- Linux crontab (Linux)

- Use Makeself Create installation file (Linux)

- PostgreSQL query lock and kill the process (Database)

- Go constructed using an interpreted language (Programming)

- Oracle Bug caused by the collection of AWR Snapshot fault (Database)

- Ubuntu 14.10 / 14.04 / 12.04 virtual users to install the printing software Boomaga (Linux)

- Java, boolean operators & =, | = ^ = use (Programming)

- The Gitlab migrated to Docker container (Server)

- Oracle 11g How dataguard master repository to Oracle single instance data recovery (Database)

- The correct way to open Xcode - Debugging (Programming)

- Binding multiple network cards in Linux using command nmcli (Linux)

- Oracle multi-user concurrency and transaction processing (Database)

- Repair Chrome for Linux is (Linux)

- Linux, how to filter, split, and merge pcap file (Linux)

- HTTP Client Hints Introduction (Server)

- MySQL Authorized a recovered (Database)

- Lenovo Ultrabooks Ubuntu system can not open the wireless hardware switch solutions (Linux)

- Moosefs Distributed File System Configuration (Server)

 
         
  Linux System Getting Started Learning: rename multiple files in Linux
     
  Add Date : 2017-08-31      
         
         
         
  Question: I know I can use the mv command to rename a file. But when I want to rename a lot of files how to do? If you all do for each file it will be tedious. There is no way to rename multiple files at once?

In Linux, when you want to change a file name, use the mv command enough. Yet mv can not use wildcards to rename multiple files. It can be used together to handle the case of multiple files using sed, awk, or with xargs. However, the command line that is not cumbersome and friendly, and if not careful, very prone to error. You do not want to undo the wrong file name 1000 of it!

When you want to rename multiple files at the time, rename tool may be the easiest, safest and most powerful command-line tool. The rename command is actually a Perl script, it pre-installed on all current Linux distributions.

Here is the basic syntax of the command to rename.

rename [-v -n -f] < pcre > < files >
is a Perl-compatible regular expression that is to rename files and how to do it. A regular expression that 's / old-name / new-name /'.

'-v' Option to display the file name change details (eg: XXX renaming YYY).

'-n' Option tells the command file rename will rename Show without actually changing the name of the case. This option in case you want to change the file name without changing the file name of the case of analog useful.

'-f' Option to forcibly overwrite existing files.

Now, let us look at some practical examples rename command.

Change the file extension

Suppose you have many .jpeg image file. You want to put their name to .jpg. The following command will change the .jpeg file * .jpg.

$ Rename 's / \. Jpeg $ / \. Jpg /' *. Jpeg
Uppercase to lowercase, and vice versa

Sometimes you want to change the file name of the case, you can use the following command.

All files lowercase:

# Rename 'y / A-Z / a-z /' *
All the documents into capital:

# Rename 'y / a-z / A-Z /' *

Change the file name pattern

Now let's consider a more complex sub-pattern comprising regular expression. In PCRE, the sub pattern enclosed in parentheses after the $ symbol connected to a digital (such as $ 1, $ 2).

For example, the following command will 'imgNNNN.jpeg' becomes 'danNNNN.jpg'.

# Rename -v 's / img _ (\ d {4}) \. Jpeg $ / dan_ $ 1 \ .jpg /' * .jpeg
img_5417.jpeg renamed as dan_5417.jpg
img_5418.jpeg renamed as dan_5418.jpg
img_5419.jpeg renamed as dan_5419.jpg
img_5420.jpeg renamed as dan_5420.jpg
img_5421.jpeg renamed as dan_5421.jpg
For example, the following command will 'img_000NNNN.jpeg' becomes 'dan_NNNN.jpg'.

# Rename -v 's / img_ \ d {3} (\ d {4}) \. Jpeg $ / dan_ $ 1 \ .jpg /' * jpeg
img_0005417.jpeg renamed as dan_5417.jpg
img_0005418.jpeg renamed as dan_5418.jpg
img_0005419.jpeg renamed as dan_5419.jpg
img_0005420.jpeg renamed as dan_5420.jpg
img_0005421.jpeg renamed as dan_5421.jpg
The above example, the sub-mode '\ d {4}' will capture four consecutive numbers, capturing four digits is $ 1, will be used for a new file name.
     
         
         
         
  More:      
 
- Singleton (Linux)
- Ubuntu installed Gimp 2.6.11 (stable version) with PPA (Linux)
- Elaborate .NET Multithreading: Using Task (Programming)
- The OpenGL ES GLFW window structures (Programming)
- MySQL function: group_concat () function (Database)
- Oracle 11g dataguard main library backup and recovery to the test environment in one database error (Database)
- Linux initialization init system - UpStart (Linux)
- Linux crontab (Linux)
- There are more than one server, there is reason to try cloud operating system (Server)
- Ubuntu 14.04 Boot Repair (Linux)
- Install Rubinius testing Ubuntu 14.04 native threads (Linux)
- MySQL restart process can not be taken lightly (Database)
- Android project using the command to create and install the package (Programming)
- Linux boot the system does not display a progress bar setting method (Linux)
- RedHat 6 xrdp use remote login interface (Linux)
- Ubuntu 12.04 configure NVIDIA CUDA 5.5 Record (Linux)
- xCAT line installation on CentOS 6.X (Linux)
- AppCode developed Mac OS X application or shared library experience summary (Programming)
- Security enhancements in Ubuntu ssh service (Linux)
- Ubuntu 14.04 Nvidia proprietary drivers for install two graphic cards (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.