If you have gnu ls
then this:
so, --time=ctime to sort by creation time; -d to not list the contents of directories; */ expands to the list of directories in the current directory, forcing ls to only list directories.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Quote:
Originally Posted by apmcd47
...so, --time=ctime to sort by creation time ...
Quote:
ctime
ctime originally meant creation time,[12] however it has since been used almost always to refer to inode change time. It is updated any time file metadata stored in the inode changes, such as file permissions, file ownership, and creation and deletion of hard links. In some implementations, ctime is affected by renaming a file (both original Unix and modern Linux tend to do this).
Unlike atime and mtime, ctime cannot be set to an arbitrary value with utime(), as used by the touch utility, for example. Instead, when utime() is used, the ctime value is set to the current time.
Unix and Windows file systems interpret 'ctime' differently:
Unix systems maintain the historical interpretation of ctime as being the time when certain file metadata, not its contents, were last changed, such as the file's permissions or owner (e.g. 'This file's metadata was changed on 05/05/02 12:15pm').
Windows systems use ctime to mean 'creation time'[citation needed] (also called 'birth time') (e.g. 'This file was created on 05/05/02 12:15pm').
This difference in usage can lead to incorrect presentation of time metadata when a file created on a Windows system is accessed on a Unix system and vice versa.[citation needed] Most Unix file systems don't store the creation time, although some, such as HFS+, ZFS, and UFS2 do. NTFS stores both the creation time and the change time.
The semantics of creation times is the source of some controversy. One view is that creation times should refer to the actual content of a file: e.g. for a digital photo the creation time would note when the photo was taken or first stored on a computer. A different approach is for creation times to stand for when the file system object itself was created, e.g. when the photo file was last restored from a backup or moved from one disk to another.
If you want to ignore everything you've been told and do not want to print directory names in order of date of creation and instead want to print directory names in order of increasing file status change times, you can use:
(note that the 1st option in the above command is the digit 1; not the lowercase letter l). Using the -1 option tells ls to produce names one per line without needing to feed the output through a while read echo loop.
If your directories are located on a filesystem type that does save creation times in addition to file status change times, on some systems you could get a list of directories in increasing order of creation times with:
but since standard filesystems don't have a creation time (only a status change time as drl mentioned), the option letter to print the creation time (if there is one) may be different on your system. Search the ls man page on your system for an option containing the word creation to see if there is an option to sort output by creation time on your system, and if there is, what option character invokes it and what filesystem types have that information.
This User Gave Thanks to Don Cragun For This Post:
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)
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)
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)
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)
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)
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)
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)
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)
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)