Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a way I can do a rename of a large number of file at once? For example:
I want to rename (technically replace) any (, ), [, or ] in the file name of my mp3's. My script has an issue with those in the file name, and I would like to replace the ( or [ with "- " and just remove the ] or ). Is that something that can be done, or should I continue to do it by hand?
unfortunately they all have a different look, but for the most part it's "Artist - Title.mp3" sometime a title will be in there. Most of the songs that I need to rename have the brackets or parentheses at the end before .mp3.
If this is anything that takes more than 5 minutes of work for anyone on this forum to figure out, then I don't want to bother anyone. I just wanted to see if there was an easy way to do this. If not, I can change them manually.
Nice script homey, could you please also explain it to benefit others. I for one, would love to know what part is sent to /dev/null, obviously it is the brackets and stuff but how
The 2> /dev/null part is just to get rid of noise when you have a file name doesn't get changed. You get a message saying the old file and new file are the same.
This is the part that gets rid of brackets and replaces ( , ) with ( - )
tr -d '[' | tr -d ']' | tr ',' '-'
That replaces , with -? I think I typed my request incorectly. I would like ( and [ to be replaced by - and ) and ] to be removed. Sorry about the confusion.
The message is an stderr so that is redirected to /dev/null
If you don't want to see what the mv command is doing, remove the -v
Output redirection:
0 = stdin input device such as keyboard
1 = stdout output device usually the console
2 = stderr error message usually displayed at the console
Example: ls nofile > test 2>&1 This sends the error message to a file called test.
Example: ls | tee test This sends output to the screen and to a file called test.
That replaces , with -? I think I typed my request incorectly. I would like ( and [ to be replaced by - and ) and ] to be removed. Sorry about the confusion.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.