Bash directory loop and order by creation date?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash directory loop and order by creation date?
# 8  
Old 12-16-2016
I'm afraid that stubbornly repeating your question as well as that code snippet, ignoring any of the proposals given in this thread, won't take you anywhere.
Why don't you take a step back and start over from the beginning, specify your needs - in detail! - , your data (structures), and the desired outcome, describe what you have (obviously that for loop) and its results, what and where it does NOT satisfy your needs, show the results of the proposals given and their shortcomings, and eventually errors occurring? That MIGHT put us in a position to help you.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 12-16-2016
sorry Smilie

i tested all above i am not ignoring the posts above, i thanked for all the posts as i am tried it all, but none worked the way, i want, sort it by latest created dirs by the loop script

that loop i have now only show all dirs in
/home/test/, those are NOT sorted by created date in any way, probably just by name...

simply i need in that loop sort dirs by created date/time ...

Code:
Example (i do not care the created thing date "Created 2016-*-*", just sort order by create folder) in folder /home/test/:

Folder_test_1 - Created 2016-01-01
Folder_test_2 - Created 2016-05-01
Folder_test_3 - Created 2016-09-01

Output should be 

Folder_test_3 - Created 2016-09-01
Folder_test_2 - Created 2016-05-01
Folder_test_1 - Created 2016-01-01


# 10  
Old 12-16-2016
In what way did they not work? "Does not work" is manifestly unhelpful. They might be one minor correction away from working for all we know - rejecting them out of hand without even bothering to explain why is a huge waste of our time and effort.
  • Show what you tried, word for word, letter for letter, keystroke for keystroke.
  • Show what happened. Do not paraphrase. Show the real result.
  • Show how the result is different from what you wanted.
Either work with the people trying to help you, or I will close this thread.
This User Gave Thanks to Corona688 For This Post:
# 11  
Old 12-16-2016
i just said none worked THE WAY i wanted, i did not said "it does not work" Smilie

so all being said, all post above this just do not reproduce following output -> SORT BY DATE CREATION what more to say?

The posts above just showed the way its possible to sort via update folder date&time, thats the one i do not need, i need SORT BY DATE CREATION

And output of the commands from all above replies was just folders sorted by update date&time
# 12  
Old 12-16-2016
Quote:
Originally Posted by ZerO13
sorry Smilie

i tested all above i am not ignoring the posts above, i thanked for all the posts as i am tried it all, but none worked the way, i want, sort it by latest created dirs by the loop script

that loop i have now only show all dirs in
/home/test/, those are NOT sorted by created date in any way, probably just by name...

simply i need in that loop sort dirs by created date/time ...

Code:
Example (i do not care the created thing date "Created 2016-*-*", just sort order by create folder) in folder /home/test/:

Folder_test_1 - Created 2016-01-01
Folder_test_2 - Created 2016-05-01
Folder_test_3 - Created 2016-09-01

Output should be 

Folder_test_3 - Created 2016-09-01
Folder_test_2 - Created 2016-05-01
Folder_test_1 - Created 2016-01-01


Yes, you are ignoring everything that has been said.

First, you can't get output file directory creation order unless the filesystem you are using stores that information. You haven't told us what operating system and filesystem type you're using; so our first guess is that what you want CANNOT be done on your system.

Second you never said anything about sorting in reverse order and until post #9 you never gave any indication that sorting by creation date was not sorting by increasing creation date (instead of decreasing creation date).

Third, if you are using a filesystem type that keeps creation date data, I told you exactly how to find out how print directories in increasing creation date order on BSD systems in post #6 and told you where to look for the option to use on your system. Did you bother looking at the ls man page on your system to see if your system provides an option to sort by file creation time? If so, what filesystem types on your system provide file creation time data? Is the filesystem where the directories you want to process one of those filesystem types? If the answer to any of these questions is no, there is nothing we can do to help you unless you move your files to a filesystem type that keeps track of file creation dates and you mount that filesystem on a system with an ls utility that provides a way to sort its output based on file creation dates.

Fourth, the code that you keep showing us is code that prints directories in increasing alphanumeric order. None of the examples we have suggested print directories in alphabetic order unless the file status change time or file creation time happens to be the same order as alphabetic order. To get output from ls in reverse sorted order add the -r option to any of the ls commands we suggested.
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 12-16-2016
Quote:
Originally Posted by ZerO13
i just said none worked THE WAY i wanted, i did not said "it does not work" Smilie

so all being said, all post above this just do not reproduce following output -> SORT BY DATE CREATION what more to say?
Many of them clearly and obviously do. I see literally no indication you've actually tried them. Which isn't to say you haven't, but if you have and didn't post what you did and its results, you've wasted your own time.

Complaining is useless. If you show what you try and exactly the results you get, maybe we can figure out why. (Do those folders actually have ctimes like you think, or are they just NAMED those dates?)

As is, we have nothing to work from, and neither do you. Last chance before thread closure.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with date in bash script for loop from YYYYMMDDHHMM

Hi everyone I need some help I want to create an script which does some processing it takes the two arguments 201901010000 and 201901020200 - so YYYMMDDHHMM I want to split processing into hours from start until end, I dont get why this works but when I add to a future variable... (1 Reply)
Discussion started by: kl1ngac1k
1 Replies

2. Shell Programming and Scripting

Reason for no directory creation date

i read here that linux provides no way to determine when a directory was created. https://www.unix.com/shell-programming-and-scripting/157874-creation-date-directory.htmlI have a directory /home/andy/scripts that had a README file in it. That file says I put the script in that directory and... (3 Replies)
Discussion started by: drew77
3 Replies

3. UNIX for Beginners Questions & Answers

Copy files in order of creation date

Hi everyone :-) I ran into a small issue. I would like to copy some files in the precise order they were created. So the oldest files should be copied first and the newest ones last. I tried cp -r $(ls -1t) ./destination but the files are still not sorted properly. I was thinking, that... (11 Replies)
Discussion started by: officiallyme
11 Replies

4. Shell Programming and Scripting

Bash directory loop, but only choose those folders with specific word in it

Hello, how in bash i can get directory loop, but only choose those folders with specific word in it, so it will only echo those with specific word #!/bin/bash for filename in /home/test/* do if ; then echo $filename; fithx! (4 Replies)
Discussion started by: ZerO13
4 Replies

5. Shell Programming and Scripting

Bash to create new directory by date followed by identifier and additional subdirectories

I have a bash that downloads a list and if that list has data in it then a new main directory is created (with the date) with several subdirectories (example1, example2, example3). My question is in that list there are portion of specific file types (.vcf.gz) - identifier towards the end that have... (0 Replies)
Discussion started by: cmccabe
0 Replies

6. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

7. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies

8. Shell Programming and Scripting

Creation date of a directory

what's the command to find the creation date of a certain dirctory? (1 Reply)
Discussion started by: miss_dodi
1 Replies

9. Shell Programming and Scripting

Grep by range of date from file creation in directory

Hi Expert, Need your scripting and finding data so that it help me to find the culprit of this memory usage error. Data provided here is a sample. Process Snapshot directory: /var/spool/processes-snapshot webdev9o9% pwd /var/spool/processes-snapshot webdev9o9% ls -lrct -rw-r--r-- ... (3 Replies)
Discussion started by: regmaster
3 Replies

10. AIX

loop through the directory for files and sort by date and process the first file

hello i have a requirement where i have a direcotry in which i get files in the format STOCKS.20080114.dat STOCKS.20080115.dat STOCKS.20080117.dat STOCKS.20080118.dat i need to loop through the directory and sort by create date descending order and i need to process the first file. ... (1 Reply)
Discussion started by: dsdev_123
1 Replies
Login or Register to Ask a Question