Linux rename to lowercase

Rename All Files and Directory Names to Lowercase in Linux

In our previous article, we have described how to count the number of files and subdirectories inside a given directory. This guide will show you how to rename all files and directories names to lowercase in Linux.

There are several ways to achieve this, but we’ll explain two of the most efficient and reliable methods. For the purpose of this guide, we have used a directory named Files which has the following structure:

List Directory Structure

1. Using find, xargs and rename Commands Together

rename is a simple command line utility for renaming several files at once in Linux. You can use it together with find utility to rename all files or subdirectories in a particular directory to lowercase as follows:

Explanation of options used in the above command.

  • -depth – lists each directory’s contents before the directory itself.
  • -n 1 – instructs xargs to use at most one argument per command line from find output.

Sample output after renaming files and subdirectories to lowercase in Files directory.

Rename Files and Directory Names to Lowercase

Another alternative way using the find and mv commands in a script as explained below.

2. Using find and mv Commands in Shell Script

First create your script (you can name it anything you prefer):

Then add the code below in it.

Save and close the file, then make the script executable and run it:

Lowercase File Names Using Script

You may also like to read these following related articles.

In this guide, we expalined you how to rename all files and directories to lowercase in Linux. If get any errors, please hit us up via the feedback form below. You can as well offer us any other methods of doing the same.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Thread: rename all files to lowercase names?

Thread Tools
Display

rename all files to lowercase names?

any easy way to rename all files to lowercase names?

Re: rename all files to lowercase names?

First, ‘cd’ into the directory with your files you want to change. Then, run this.

Re: rename all files to lowercase names?

or install thunar and use bulk rename, for the gui way to do it. You will have to use menu editor to see bulk rename under accesories.

Re: rename all files to lowercase names?

First, ‘cd’ into the directory with your files you want to change. Then, run this.

Читайте также:  How to copy all on windows

Thanks, that did the trick for me.

For some reason files I restored from DVD using Roxio 2009 were renamed as all caps.

Last edited by Vegan; November 25th, 2009 at 04:53 PM .

Re: rename all files to lowercase names?

Originally Posted by KiLaHuRtZ View Post
First, ‘cd’ into the directory with your files you want to change. Then, run this.

ls | while read upName; do loName=`echo «$» | tr ‘[:upper:]’ ‘[:lower:]’`; mv «$upName» «$loName»; done

Worked great for me too

Re: rename all files to lowercase names?

from the above command with

it will happen recursively, although it will complain for non-capital names.

Re: rename all files to lowercase names?

File names in Linux can contain any characters other than a slash (/) and the null character. So, I wouldn’t use ls | while read or for file in `ls`. The first one fails if the file name contains a new line; the second one fails with files with spaces in their name too.

The proper way to write the script is:

Last edited by sisco311; January 19th, 2011 at 03:49 PM .

Источник

Batch rename files to lowercase

Is there a way to rename all files in a directory to lowercase|uppercase?

I am looking for a oneliner command.

I loved TotalCommander’s Alt + F7 , now I need that functionality in the Terminal.

4 Answers 4

For each file a_file in current directory rename a_file to lower case.

For upper case reverse the arguments to [:lower:] [:upper:]

tr command reference link

Update

For even more control * can be replaced with ls .

For example in a directory containing 1.txt, 2.txt, 3.txt, 1.jpg, 2.jpg and 3.jpg in order to filter only *.jpg files, ls can be used:

The above code will assign to a_file variable all files with .jpg extension.

Update added -v option to mv command as per sds suggested.

There’s a more elegant and general utility called prename .

Written by Larry Wall, it comes with perl so it is most likely already available on your system as /usr/bin/prename (if you have setup alternatives is may also be available as /usr/bin/rename symlinked via /etc/alternatives to prename )

Using it you can rename multiple files in one command by providing any perl expression (including but not limited to substitution s/// or char transliteration tr/// ):

Examples:

Another nice thing about prename is that it protects you, in the case of renaming a file to an existing file name.

Источник

How to rename file extension to lowercase?

I know this question has been asked (and answered) before, but it seems my situation is unique, because I cannot have any of the solution to work.

Running, I need to rename all my photos from *.JPG to *.jpg .

Let’s say I don’t need recursive, just all the pictures in the same folder.

The problem I meet is this one:

Same problem using rename, with that kind of command:

4 Answers 4

It is really simple:

Rename to something else than the same value with different case

Now rename that something else to .jpg back again, but lowercase this time

Demo: http://paste.ubuntu.com/8853245/

If αғsнιη is right in his comment, and I think he is, OP’s problem is that a similarly named file already exists. If that is the case, the script will have to check if the targeted file name (lowercase) already exists, and (only) if so, rename the original file additionally (not only lowercase extension) to prevent the name error, e.g.

Читайте также:  Refresh rate mac os

since image1.jpg would raise an error

If so, a python solution to rename could be:

The script renames:

but if image1.jpg already exists:

Copy the script into an empty file, save it as rename.py , make it executable and run it by the command:

Thanks for contributing an answer to Ask Ubuntu!

  • Please be sure to answer the question. Provide details and share your research!
  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Источник

Linux rename command

On Unix-like operating systems, the rename command renames multiple files, using regular expressions. It was written by Larry Wall, creator of the Perl programming language.

Description

rename renames the named files according to the regular expression perlexpr.

If a specified file is not modified by the expression, it is not renamed. If no file names are given on the command line, file names are read via standard input.

Syntax

Options

-v, —verbose Verbose: print names of files successfully renamed.
-n, —no-act No Action: show what files would be renamed.
-f, —force Force: overwrite existing files.

Perl expressions: a quick overview

The perlexpr argument is a regular expression as used by the Perl programming language. Perl regular expressions is a complex and nuanced subject, but here is a brief overview:

Substitution

To substitute one expression for another, the form of perlexpr is:

. where expr1 is an expression describing the string you want to replace, and expr2 is an expression describing the string you want to replace. For instance,

. would substitute the first occurrence of the string ‘silly‘ with the string ‘foolish‘.

To perform global substitution (that is, to substitute expr2 for expr1 as many times as expr1 occurs), add the modifier g at the end of the substitution expression. For instance:

. would substitute every occurrence of ‘silly‘ with ‘foolish‘, no matter how many times it occurs.

To perform matching in a case-insensitive manner, add an i at the end of the substitution expression. For instance,

. would substitute ‘SILLY‘, ‘Silly‘, or ‘siLLY‘ with ‘foolish‘.

The g and i modifiers may both be specified in the same expression, to perform case-insensitive global substitution, for example:

Metacharacters

A metacharacter is a character (or characters) with a special meaning. They are used in an expression to precisely define which strings should be matched and replaced.

These are some common metacharacters used in a Perl Expression:

metacharacters meaning
^ Matches the beginning of a string.
$ Matches the end of a string.
. Matches any character, except a newline.
* Matches occurrences of the preceding character, or group of characters, zero or more times.
+ Matches occurrences of the preceding character, or group of characters, one or more times.
? Match occurrences of the preceding character, or group of characters, zero or one times.

If used after a repetition modifier, ‘?‘ specifies that the shortest possible match should be used. For instance, ‘a<2,4>?‘ matches ‘aa‘ even if ‘aaa‘ and ‘aaaa‘ would also match. See repetition modifiers, below.

| Alternation; behaves like a boolean ‘OR’. For instance, ‘butter|jelly‘ matches either butter or jelly.
(. ) Grouping. For instance, ‘(eg|le)gs‘ matches either ‘eggs‘ or ‘legs‘.
[. ] A set of characters. For instance, ‘[abc]‘ matches ‘a‘ or ‘b‘ or ‘c‘. Character sets can be defined as:

[characters] Matches any one of the characters listed.
[xy] Matches any in a range of characters between x and y, inclusive. For instance, ‘[c-e]‘ matches c, d, or e, and ‘[a-z]‘ matches any lowercase letter.
[^characters] Does not match characters; in other words, matches any character except those listed. Can also negate a character range; for instance, ‘[^a-d]‘ matches any character except a, b, c, or d.
[\-] Matches the hyphen character (««).
[xyXZ] Multiple character ranges can be placed in a character set consecutively. For instance, ‘[a-zA-Z]‘ matches any letter, uppercase or lowercase.
<m[,[n]]> A repetition modifier that matches at least m and at most n of the preceding characters. For instance, ‘a ‘ matches ‘aa‘, ‘a ‘ matches either ‘aa‘, ‘aaa‘, or ‘aaaa‘, and ‘b ‘ matches two or more consecutive b characters.
\ Escapes a metacharacter so it is treated literally. For instance, ‘\+‘ matches a literal ‘+‘ (instead of the plus symbol having its special metacharacter meaning).
\t Matches a tab character.
\n Matches a newline character.
\r Matches a carriage return character.
\w Matches any single character classified as a «word» character (an alphanumeric character or an underscore ‘_‘).
\W Matches any single non-«word» character.
\s Matches any single whitespace character (space, tab, newline).
\S Matches any single non-whitespace character.
\d Matches any digit character. This switch is equivalent to the character set ‘7
\D Matches any non-digit character.
\b A «zero-width» matching assertion that matches any «word boundary».
\B A «zero-width» matching assertion that matches any non-«word boundary».

Translation

Translation is similar to substitution. It can translate one string to another, character-for-character. Translation expressions are specified as follows:

. where each character in the set charset1, in order, is to be translated into the corresponding character from the character set charset2. (These sets are like the character sets above, except you don’t need to put them in brackets.) For example, the translation expression:

. would translate every letter a into the letter d, every b into an e, etc.

This also works for charsets defined as ranges. For example:

. would translate every lowercase letter into its uppercase equivalent.

Examples

Rename any files with the extension «.jpeg» to have the extension «.jpg«.

For all files with the extension «.jpg«, if they contain the string «holiday«, replace it with «honeymoon«. For instance, this command would rename the file «ourholiday001.jpg» to «ourhoneymoon001.jpg«.

This example also illustrates how to use the find command to send a list of files (-type f) with the extension .jpg (-name ‘*.jpg’) to rename via a pipe (|). rename then reads its file list from standard input.

Rename all files matching «*.bak» to strip the file name of its extension. For instance, this command would rename the file «project.bak» to «project«.

Rename files such that all uppercase letters are changed to their lowercase equivalents.

mv — Move files and directories from one location to another, and optionally rename them.
perl — Interpreter for the Perl programming language.

Источник

Читайте также:  Шрифт times new roman для linux mint
Оцените статью