LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-19-2012, 09:17 AM   #1
ncube22
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Rep: Reputation: Disabled
Help with sorting folders


Linux Newbie.. So pardon my ignorance.
I need to sort folders for "each year" based on the ls -ltr cmd below and copy them to a diff path.
Ex: ls -ltr
drwxr-xr-x 2 mqm mqm 80 Mov 3 2007 38
drwxr-xr-x 2 mqm mqm 80 Dec 2 2007 21
drwxr-xr-x 2 mqm mqm 80 Jan 3 2008 01
drwxr-xr-x 2 mqm mqm 80 Jan 3 2008 82
drwxr-xr-x 5 mqm mqm 1024 Dec 3 2009 24
drwxr-xr-x 2 mqm mqm 80 Jan 3 2010 21
drwxr-xr-x 2 mqm mqm 80 Nov 3 2010 613
drwxr-xr-x 5 mqm mqm 1024 Feb 3 2011 493
drwxr-xr-x 5 mqm mqm 1024 Oct 4 2012 349
 
Old 12-19-2012, 09:44 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello ncube22, welcome to LQ,

is this homework? As per our forumrules we do not each other's homework.

Could you please explain, what you have achieved so far?
Have you already written some code? please post it here.
Which tools/programs do you want to use?

Markus
 
Old 12-19-2012, 10:57 AM   #3
ncube22
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Dude. Chill out. This ain't a homework, so people have to list out their achievements to post a qn and look for a solution/help. Wow.
Didn't know that.. If you can help do so or else please move on with you life.

Later !
 
Old 12-19-2012, 11:03 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
How is the sorting you want different from what ls -tr provides? Please understand that directories are stored in no particular order on disk; only the presentation of the order can vary. When userspace code gets a list of files or directories, they are read in whatever order the kernel/filesystem chooses. The application (like ls, for example) then sorts the list (or not) according to its own purpose. The same goes for copying. When you write the files or directories, they will be stored in an arbitrary arrangement not controllable by you.

BTW, it is customary for people to demonstrate that they are actually trying to accomplish their objective on their own, and not simply using LQ as a source of free workers.

--- rod.

Last edited by theNbomr; 12-19-2012 at 11:08 AM.
 
Old 12-19-2012, 11:41 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Sorting on basis of yrs value can be done as:
Code:
ls -la | sort -n -k 7
You can then create a small script and copy/move selected files to another place.

Ciao!
 
Old 12-19-2012, 12:43 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by ncube22 View Post
Dude. Chill out. This ain't a homework, so people have to list out their achievements to post a qn and look for a solution/help. Wow.
Didn't know that.. If you can help do so or else please move on with you life.

Later !
No need to be so harsh. As previously pointed out - if you show some effort and tell us at which point you're stuck or what exactly puzzles you, you will receive answers more suitable to your needs. Being it homework or not.

Regarding your question, you can start from something like:
Code:
for dir in */
do
  destination=/path/to/destination/$(date -r $dir +%Y)
  mkdir -p $destination && cp -a $dir $destination
done
This will create yearly directories under /path/to/destination based on the timestamp of the directories and copy them accordingly. Not sure if it's really what you're looking for. Hope it helps, anyway.
 
1 members found this post helpful.
  


Reply



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
Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders unix_72427 Programming 8 08-08-2012 02:51 PM
bash script to create folders including making recursive folders.... linux-bandit Linux - Software 8 11-28-2009 01:50 AM
Sorting photos into folders based on exif date SuperJediWombat! Programming 7 05-16-2009 06:53 PM
Sorting mp3s into folders by ID3 tags? deadjoebob Linux - Software 0 03-07-2004 12:21 PM
Sorting mail into folders? cli_man Linux - Software 4 11-07-2003 10:20 AM

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

All times are GMT -5. The time now is 06:31 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
Open Source Consulting | Domain Registration