I am working on a Red Hat server. The commands
ls -l or
ll giving me the date and time in format
+"%b %-d %H:%M".
I want to list the files in a way where the year when each was file created would appear within the date.
How is that possible?
You can use
man ls and here you can find
--time-style parameter. Or you can use:
ls -l will display month day and year - since, according to BSD man page:
If the modification time of the file is more than 6 months in the past or future, then the year of the last modification is displayed in place of the hour and minute fields.
So, to make sure that year will always be shown, use:
ls --time-style=long-iso (GNU/Linux)
ls -lT will display display complete time information in BSD (MacOS)
Since you asked for the year,
ls -lac is an easy one to remember if, like me, you use
ls -la all the time. The
c gives you ctime which will display a year if it's not the current year or the hour and minute if it is.
In addition to Jan Marek's answer.... I've noticed you can get away with just:
ls --full or ls --fu
which will do the same thing as
ls --full-time as he described. Thanks Stéphane Chazelas. Now I type
ls --fu everywhere. :)
If you're using
busybox (embedded distros, e.g. OpenWRT, LEDE), the switch you're looking for is
-e for versions up to 1.26.2 and
--full-time for 1.27.0 and above (see the commit that changed it).
$ ls -altT /path/to/some/dir