Shell script which will sort all the files in a directory with the timestamp they were created


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell script which will sort all the files in a directory with the timestamp they were created
# 1  
Old 07-16-2010
Shell script which will sort all the files in a directory with the timestamp they were created

Team,

Pls help writing a shell script which will sort all the files in a directory with the timestamp they were created. (like ls -lrt)
# 2  
Old 07-16-2010
Is it a home work ?
# 3  
Old 07-16-2010
whats wrong with
Code:
ls -lrt

? ^^
# 4  
Old 07-16-2010
After veto from a user the thread is reopened. If this tends to be homework though and op will not state what exactly is needed and why, thread will be closed again.

---------- Post updated at 12:33 PM ---------- Previous update was at 09:16 AM ----------

Just another thing - there is no such thing as creation time.
Accessing (atime), changing the files permissions and/or the contents (ctime) and modificating it's contents only (mtime) are the given things you can handle with ls.

Last edited by zaxxon; 07-16-2010 at 07:18 AM..
# 5  
Old 07-16-2010
As zaxxon rightly points out there is no such definition as "file creation time".
In a modern unix the nearest you will get is:
Code:
ls -lrct

However the moment the inode is modified (e.g. by chmod or by some backup software) the "ctime" timestamp changes.

This used to work in Berkeley unix.
# 6  
Old 07-17-2010
hi all,
you can user "sort

---------- Post updated at 01:05 PM ---------- Previous update was at 01:04 PM ----------

you can use "sort" command.
thanx
# 7  
Old 07-18-2010
To reiterate this command sorts the directory by last modified timestamp, not by "created" timestamp.
Code:
ls -lrt

The nearest you will get is to sort by the time the inode was last modified which can often be when the file was created but actions such as "chmod" or modifications by backup software can change this timestamp.
Code:
ls -lrct

If it is critical to know when a file was created one must write software to record the creation time in an independent index.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find files and sort by timestamp

Used below command to get list of files sorted by timestamp find -L . -type f -name '*dat*' | xargs ls -ltrg I want to get only the filenames so I tried adding basename but it doenst work , can some one advise on how to get only file name (1 Reply)
Discussion started by: lalitpct
1 Replies

2. Shell Programming and Scripting

Moving Files one directory to another directory shell script

Hi, Could you please assist how to move the gz files which are older than the 90 days from one folder to another folder ,before that it need to check the file system named "nfs" if size is less than 90 or not. If size is above 90 then it shouldn't perform file move and exit the script throwing... (4 Replies)
Discussion started by: venkat918
4 Replies

3. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

4. Shell Programming and Scripting

Shell Script Help..Renaming Quoted files removing the timestamp

Hi all, i am new to this forum, unix and shell scripting. I would really appreciate if you all can help me here.. I have files coming in the below format 'filename20513'13May06:03:45 filename are characters.. like 'ABDDUT20513'13May06:03:45 i need it to be renamed as... (17 Replies)
Discussion started by: khman
17 Replies

5. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

6. Shell Programming and Scripting

How to sort the timestamp in the filename in shell script?

originally the shellscript #ln_file_name=`echo $ld_interface_date"_"${8}".csv"` #ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv` ln_file_name="*"`echo ${7}".csv"` get_file_list_1=$log_path"tm1_file_list.gfl1" cd ${source_path} echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies

7. Shell Programming and Scripting

Backup shell script created temp files .

Hi, I've a script which creates a temp flat file for storing all business dates received on a single day from diff control files sent by source system on that day. e.g on 12th april I receive txns for business day 8,9,10,11 april. I capture this business day and append to a flat file from... (1 Reply)
Discussion started by: manojg9
1 Replies

8. Programming

Sort the files on their name and then the timestamp using Perl

Hi All, I am new to Perl. I have a scenario to code. In a folder I have number of files and they will start with P01 or P02 or P03 and so on..I have to sort them on name first and then on time stamp. Ex. File name timestamp P01_file1.txt 1PM P02_file1.txt 1AM P01_file2.txt 2PM... (12 Replies)
Discussion started by: unankix
12 Replies

9. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

10. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies
Login or Register to Ask a Question