Linux - NewbieThis 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
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.
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
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?
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.