LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2010, 01:34 PM   #1
drnick911@yahoo.com
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: Disabled
How to rename files


Hello all,

I need help with renaming files and folders in one go.
I have a folder called /opt/utility/pictures/
Inside that folder have sub-folders and files such as

01-Archive/
01-Beach.jpg
01-atx.in
01-mtu.cfg
01-files/
..
...
....


I want to rename all the files to be without 01-

So basically, I want it to be as
Archive/
Beach.jpg
atx.in
mtu.cfg
files/
..
...
....

Thank you in advance and appreciate all the help.

Cheers~
 
Old 10-20-2010, 02:05 PM   #2
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-17.3 with Cinnamon & KDE
Posts: 1,511
Blog Entries: 3

Rep: Reputation: 96
I've heard of utilities for bulk rename, but I cannot name one without research.

This sounds like an opportunity to practice your shell (or perl or whatever) scripting if you are not under the gun. Even if you are pressed for time, a script might get you there faster than finding a utility and learning to use it.

If I were making scripts -- yes, I'd make more than one -- I might create a file that lists all of the parts that I want to change. Once I had that file or files, I would then cycle through implementing the changes.

Hmmm?! Now that I've written this, it seems that Gnome Nautilus has features that might accomplish what you want. If I find something there, I'll report back.

Bonne chance,
~~~ 0;-D
 
Old 10-20-2010, 02:13 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Similar to http://www.linuxquestions.org/questi...3/#post4133865

Code:
for i in *; do new=$(echo $i | sed 's/^...//'); mv "$i" "$new";done
Untested.


Cheers,
Tink
 
Old 10-20-2010, 03:31 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Use the rename command.

Code:
rename '01-' '' *
 
Old 10-20-2010, 04:06 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,608

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Quote:
Originally Posted by Tinkster View Post
Code:
for i in *; do new=$(echo $i | sed 's/^...//'); mv "$i" "$new";done
Hi,

I think this can be shortened to
Code:
for f in *;do mv "${f}" "${f:3}";done
Careful, if you have subfolders. They will be renamed, too.
In this case
Code:
for f in *;do if [[ -f "$f" ]];then mv "${f}" "${f:3}";fi ;done
 
1 members found this post helpful.
Old 10-20-2010, 11:28 PM   #6
drnick911@yahoo.com
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: Disabled
THANK YOU ALL ... I'll test it out tomorrow and let you know how it goes
 
Old 10-21-2010, 04:23 PM   #7
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-17.3 with Cinnamon & KDE
Posts: 1,511
Blog Entries: 3

Rep: Reputation: 96
Quote:
Originally Posted by crts View Post
Hi,

I think this can be shortened to
Code:
for f in *;do mv "${f}" "${f:3}";done
Careful, if you have subfolders. They will be renamed, too.
In this case
Code:
for f in *;do if [[ -f "$f" ]];then mv "${f}" "${f:3}";fi ;done
I can never remember to use the ${ var:number } form -- and all of its friends -- of shell variable expansions.

Merci,
~~~ 0;-Dan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 08:00 AM
how to rename files bkcreddy17 Programming 7 09-14-2008 09:22 AM
rename files linux2man Linux - General 8 02-03-2007 05:26 AM
rename files allelopath Linux - General 5 07-05-2005 03:00 AM
Can not rename files. Maximus2000 Linux - General 0 04-22-2004 01:36 PM


All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration