#linux Commands Usage: The rename command



#linux Commands Usage: The rename command

#linux Commands Usage: The rename command

So you have numerous files and want to change their filenames?
Here’s one of the most efficient ways to do it:

The rename command in Linux is used to change the name of one or more files or directories. It is a Perl-based utility that provides a powerful and flexible way to manipulate file names.

Here are a few examples of how to use the rename command:

This command will replace all the spaces in all the filenames of the current directory with underscores.

rename -v ‘s/ /_/g’ *

Here’s what each part of the command does:
-v – an optional flag that stands for “verbose” and makes rename display the names of files as they are processed.

s/ /_/g – This is a regular expression pattern that performs a global search and replace operation. The pattern s/ /_/g searches for spaces in file names and replaces them with underscores (_).

* – This wildcard symbol specifies that the command should apply to all files in the current directory.

In short, this command will search and replace spaces in the names of all files in the current directory with underscores and display the names of the files as they are processed.

This command will convert filenames in current directory to upper case
rename -v ‘y/a-z/A-Z/’ *

-v – an optional flag that stands for “verbose” and makes rename display the names of files as they are processed.

y/a-z/A-Z/ – This is a regular expression pattern that performs a case-insensitive character mapping operation. The pattern y/a-z/A-Z/ maps lowercase letters a-z to uppercase letters A-Z.

* – This wildcard symbol specifies that the command should apply to all files in the current directory.

You can change the extension of all .TXT files to .txt in a directory using the following rename command:

rename -v ‘s/.TXT$/.txt/’ *.TXT

To convert back the filenames to lowercase

rename -v ‘y/A-Z/a-z/’ *

This command uses a regular expression pattern to search for .TXT at the end of each file name and replace it with .txt. The $ symbol in the pattern matches the end of the string, and *.TXT specifies that the command should apply to all files with the .TXT extension in the current directory.

It’s worth noting that the rename command can be quite powerful, but also quite dangerous if not used with caution, as there is no undo option once the changes have been made.

PLEASE SUBSCRIBE 🙂
PLEASE HIT LIKE IF IT HELPED 🙂

GIVE SUPPORT – https://www.patreon.com/lazysysad
BUY ME A COFFEE – https://www.buymeacoffee.com/lazysysad
PAYPAL – https://www.paypal.com/donate/?hosted_button_id=K4RQ3LAWHGVS6

Drop me your feedback and comments.

That’s all for now.

If this video helped you in any way, please like share and subscribe!

Thank you!!!

Comments are closed.