help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to bulk rename files


From: lxnf98mm
Subject: Re: [Help-bash] how to bulk rename files
Date: Wed, 11 Apr 2012 16:06:05 -0500 (CDT)
User-agent: Alpine 2.00 (LRH 1167 2008-08-23)

On Wed, 11 Apr 2012, Greg Wooledge wrote:

On Wed, Apr 11, 2012 at 02:51:04PM -0600, Eric Blake wrote:
On 04/11/2012 02:44 PM, address@hidden wrote:
I have many files, 2.5 million, that I have to make available to Windows
folks
They demand that the files have a extension added
Is there an efficient method of bulk renaming files

If you're wanting to use just bash features:

for f in $(generate your list of files); do
  mv "$f" "$f.ext"
done

If you want efficient, there's several purpose-built tools for this job,
but it is no longer a question for the bash list.  My favorite:

man mmv

for f in $(thing that generates filesnames) is a very bad idea.  You'll
get hit by word splitting or globbing of filenames that have spaces or
glob characters in their names.

Is it safe to assume that these files exist in some sort of multi-level
hierarchy, rather than a single directory?  If so, you want to use find.

find . -type f ! -name '*.*' \
 -exec sh -c 'for f; do mv "$f" "$f.txt"; done' _ {} +

(assuming you wanted to add .txt)


they are in a single directory
and why not find . -type f ! -name '*.*' -exec mv '{}' '{}'.txt \;

--
"the 10 most dangerous words in the English language are, 'Hi, I'm from
the Government, and I'm here to help.'"

Ronald Reagan - July 28, 1988



reply via email to

[Prev in Thread] Current Thread [Next in Thread]