ls_usage
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ls_usage [2021/01/15 21:48] – created raju | ls_usage [2022/07/22 23:34] (current) – [indicators] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Show file date in YYYY-MM-DD format | + | ==== sort ls output by filename length |
- | tags | YYYYMMDD, date format, YYYYMMDD_HHMMSS | + | < |
+ | ls --color=never --indicator-style=none | ||
+ | sort -n | cut -d" " -f2- | ||
+ | </ | ||
- | Use --time-style=' | + | To see it in action, create some files |
< | < | ||
+ | % touch a ab abc | ||
+ | </ | ||
+ | |||
+ | and some directories | ||
+ | < | ||
+ | % mkdir d de def | ||
+ | </ | ||
+ | |||
+ | Output of the normal ls command | ||
+ | < | ||
+ | % ls | ||
+ | a ab abc d/ de/ def/ | ||
+ | </ | ||
+ | |||
+ | Output from the proposed command | ||
+ | < | ||
+ | % ls --color=never --indicator-style=none | awk ' | ||
+ | sort -n | cut -d" " -f2- | ||
+ | a | ||
+ | d | ||
+ | ab | ||
+ | de | ||
+ | abc | ||
+ | def | ||
+ | </ | ||
+ | |||
+ | Ref:- https:// | ||
+ | ==== Show file date in different date formats ==== | ||
+ | tags | YYYY-MM-DD, YYYYMMDD, YYYYMMDD_HHMMSS | ||
+ | |||
+ | Use one of | ||
+ | < | ||
+ | --time-style=' | ||
+ | --time-style=' | ||
+ | --time-style=' | ||
+ | </ | ||
+ | |||
+ | For example | ||
+ | < | ||
+ | % ls -l --time-style=' | ||
+ | -rwx------ 1 rajulocal rajulocal 1112 20201017_141554 / | ||
+ | |||
% ls -l --time-style=' | % ls -l --time-style=' | ||
- | -rwx------ 1 rajulocal rajulocal | + | -rwx------ 1 rajulocal rajulocal |
- | % ls -l ~/.vimrc | + | % ls -l --time-style=' |
- | -rwx------ 1 rajulocal rajulocal | + | -rwx------ 1 rajulocal rajulocal |
</ | </ | ||
+ | |||
+ | ==== indicators ==== | ||
+ | "ls -F" appends indicators < | ||
+ | * * means executable. | ||
+ | * / means directory. | ||
+ | * = means socket. | ||
+ | * > means door. | ||
+ | * @ means symbolic link (or that the file has extended attributes). | ||
+ | * | means named pipe. | ||
+ | |||
+ | Ref:- https:// | ||
+ | |||
+ | ==== only show filename and modification time ==== | ||
+ | < | ||
+ | ls -al | cut -d ' ' -f 6- | ||
+ | </ | ||
+ | |||
+ | Another way (using find): | ||
+ | < | ||
+ | find -maxdepth 1 -type f -printf "%TY %Tb %Td %TH: | ||
+ | </ | ||
+ | |||
+ | To sort the files based on timestamp (reverse chronological order) | ||
+ | < | ||
+ | find -maxdepth 1 -type f -printf " | ||
+ | </ | ||
+ | |||
+ | The %T+ is used to sort the output properly and gets removed by cut afterwards. | ||
+ | |||
+ | Ref:- https:// | ||
ls_usage.1610747314.txt.gz · Last modified: 2021/01/15 21:48 by raju