Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

how to view by ls -ltr file with year because if the file created less then year then the year not displayed by ls -ltr

share|improve this question

migrated from stackoverflow.com Sep 21 '10 at 18:44

This question came from our site for professional and enthusiast programmers.

1  
ls -ltr shows year for all files in my shell (bash on ubuntu) –  sje397 Sep 21 '10 at 18:16

3 Answers 3

This

ls --full-time

or this

ls -l --time-format='+%e. %b %Y'

where '+%e. %b %Y' is time format (see 'date --help').

share|improve this answer

Use

ls -lTr

instead of

ls -ltr

From the ls man page

 -T      When used with the -l (lowercase letter ``ell'') option, display
         complete time information for the file, including month, day,
         hour, minute, second, and year.

For example:

$ ls
dir   file1 file2 file3

$ ls -ltr
total 0
-rw-r--r--  1 nasser  staff    0 Sep 21 14:32 file3
-rw-r--r--  1 nasser  staff    0 Sep 21 14:32 file2
-rw-r--r--  1 nasser  staff    0 Sep 21 14:32 file1
drwxr-xr-x  5 nasser  staff  170 Sep 21 14:33 dir

$ ls -lTr
total 0
-rw-r--r--  1 nasser  staff    0 Sep 21 14:32:16 2010 file3
-rw-r--r--  1 nasser  staff    0 Sep 21 14:32:16 2010 file2
-rw-r--r--  1 nasser  staff    0 Sep 21 14:32:16 2010 file1
drwxr-xr-x  5 nasser  staff  170 Sep 21 14:33:18 2010 dir

The years are shown in the last one.

share|improve this answer

Assuming you may be wanting to do something with this information once you get it, the "find" command is built for this sort of thing:

For example, to find the relative paths of the 3 oldest files in a folder with access times that are no more than one year old, run this command:

find . -atime -365 -printf "%A+ %p\n" | sort -n | head -3

Outputs:
2009-09-30+14:29:39 ./code.py
2010-01-09+00:38:34 ./cloc
2010-01-12+15:16:21 ./mbox

Great for pumping into a "while" loop!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.