Work the Shell - Scripting Common File Rename Operations
Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- RSS Feeds
- Validate an E-Mail Address with PHP, the Right Way
- Readers' Choice Awards
- Tech Tip: Really Simple HTTP Server with Python
- DynDNS
1 hour 3 min ago - Reply to comment | Linux Journal
1 hour 35 min ago - All the articles you talked
3 hours 59 min ago - All the articles you talked
4 hours 2 min ago - All the articles you talked
4 hours 3 min ago - myip
8 hours 28 min ago - Keeping track of IP address
10 hours 19 min ago - Roll your own dynamic dns
15 hours 32 min ago - Please correct the URL for Salt Stack's web site
18 hours 44 min ago - Android is Linux -- why no better inter-operation
20 hours 59 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
A few problems
Hi Dave
I downloaded the script and it would not run. There were several syntax errors:
Line 14 was missing a double quote.
Line 30 had fi instead of esac (the case statement ending syntax)
Missing done after Line 30
Also, there were two other issues with using the script in renumbering mode, that you did not mention.
ONE - If there is no filename extension, then the original filename will be used as an extension name. For example, junk-1 through junk-11 will be renamed to:
newjunk1.junk-1
newjunk10.junk-9
newjunk2.junk-10
newjunk3.junk-11
newjunk4.junk-3
newjunk5.junk-4
newjunk6.junk-5
newjunk7.junk-6
newjunk8.junk-7
newjunk9.junk-8
Note the contents of the files (illustrated by the new extension) are no longer in the orignial sequence after being renamed.
Two - If there is a digit change in the original numbering sequence (ie. 1 digit to two or three digits to four) the contents of the renamed files will no longer be in the same sorting sequences as the original files.
If all numbers in the file name have the same number of digits then there is no problem with the contents of the files remaining in the same sorting sequence. If the original files above had a 0 in front of the single digit numbers there would not have been a problem with the rename.
Anyone using the script should be aware of this sorting sequence issue. Since mv is used to rename the files, and if the sorting sequence is important to you, the script could create a big mess that would be difficult or at least time consuming to restore to the original sorting sequence.
You could replace mv with cp and delete the original files if the script produced what you wanted or if it did not you could delete the new filenames and try again.
Other than all that... it worked fine.
"I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone."
-- Bjarne Stroustrup
rename script
ls -1 $1*will list directories and will descend in subdirectories. In some situations this may well produce unexpected results.