ls_usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ls_usage [2021/01/15 21:53] – raju | ls_usage [2022/07/22 23:34] (current) – [indicators] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== sort ls output by filename length ==== | ||
+ | < | ||
+ | ls --color=never --indicator-style=none | awk ' | ||
+ | sort -n | cut -d" " -f2- | ||
+ | </ | ||
+ | |||
+ | 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 ==== | ==== Show file date in different date formats ==== | ||
tags | YYYY-MM-DD, YYYYMMDD, YYYYMMDD_HHMMSS | tags | YYYY-MM-DD, YYYYMMDD, YYYYMMDD_HHMMSS | ||
Line 20: | Line 55: | ||
-rwx------ 1 rajulocal rajulocal 1112 20201017 / | -rwx------ 1 rajulocal rajulocal 1112 20201017 / | ||
</ | </ | ||
+ | |||
+ | ==== 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.1610747603.txt.gz · Last modified: 2021/01/15 21:53 by raju