LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-23-2011, 08:48 PM   #1
.mE
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
Reordering files command


Hello everyone,

Im kind of new to linux so i am not very familiar with even the most simple commands.
This is what i would like to know;

I have a huge folder of pictures downloaded over the years from different digital cameras, im trying to reorder it now but it taking forever because of how the photos are placed...

Lets say this is how the photos are disposed
Quote:
>year
..|
..>--month
..v--month
.....|
.....>--day
.....v--day
.........|
.........+picture#.jpg
Is there a command that will move the pictures into one single folder and rename them based on the folders it was placed in? EXAMPLE.:

year.month.day.picturename#.jpg

Hope i have been clear enough...
Please let me know

Thanks

Last edited by .mE; 09-23-2011 at 08:55 PM.
 
Old 09-23-2011, 09:10 PM   #2
claudelepoisson
LQ Newbie
 
Registered: Jul 2011
Location: Montreal, Quebec, Canada
Distribution: Arch Linux
Posts: 16

Rep: Reputation: 8
find . -type f -print0 | while read -d '' old; do new=$(tr / . <<< "$old"); echo mv \"$old\" \"$new\"; done

If it looks good, append " | sh". Please feel free to ask if part of this is cryptic.
 
1 members found this post helpful.
Old 09-23-2011, 09:24 PM   #3
.mE
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
It worked like a charm,

You saved me hours or worse of work...
Now i will take my time to decode the command.


Thanks a lot
 
Old 09-23-2011, 09:31 PM   #4
.mE
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Oh i just noticed it puts 2 dots in front of the name "..year.month.day.picture#.jpg"
Any fast fix for that?
 
Old 09-23-2011, 09:54 PM   #5
claudelepoisson
LQ Newbie
 
Registered: Jul 2011
Location: Montreal, Quebec, Canada
Distribution: Arch Linux
Posts: 16

Rep: Reputation: 8
Quote:
Originally Posted by .mE View Post
Oh i just noticed it puts 2 dots in front of the name "..year.month.day.picture#.jpg"
Any fast fix for that?
Yes, sorry about that.
find . -type f -fprint "%P\0" | while read -d '' old; do new=$(tr / . <<< "$old"); echo mv \"$old\" \"$new\"; done

If your files are renamed already, use this to remove two leading dots:
Code:
find . -type f -fprint "%P\0" | while read -d '' old; do echo mv \"$old\" \"$(sed "s/^\.\.//" <<< "$old")\"; done # | sh
then remove the # if it looks fine, to execute the mv command.
 
1 members found this post helpful.
Old 09-24-2011, 05:12 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
You could also do away with the tr and keep it all to bash with a simple substitution (plus I think there is a slight typo in the last post):
Code:
find . -type f -printf "%P\0" | while read -d '' old; do echo mv \"$old\" \"${old//\//.}\"; done
Typo highlighted in red
 
1 members found this post helpful.
  


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
[SOLVED] Reordering open windows on Gnome Panel Suppen Linux - Desktop 7 05-01-2011 04:16 PM
packet reordering NS2 passer-by Linux - Newbie 3 11-01-2010 07:37 PM
Drive reordering flathood Linux - Enterprise 1 11-16-2007 10:36 AM
MYSQL-Reordering Problem in REDHAT9.0 JsSS Programming 8 09-08-2004 06:24 AM
packet reordering and delay using libipq shinkm Linux - Networking 0 09-08-2004 01:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:58 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