User Tools

Site Tools


ls_usage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ls_usage [2021/01/15 21:48] – created rajuls_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 YYYYMMDDdate format, YYYYMMDD_HHMMSS+<code> 
 +ls --color=never --indicator-style=none awk '{print length$0}' | 
 +sort -n | cut -d" " -f2- 
 +</code>
  
-Use --time-style='+%Y-%m-%d'+To see it in action, create some files
 <code> <code>
 +% touch a ab abc
 +</code>
 +
 +and some directories
 +<code>
 +% mkdir d de def
 +</code>
 +
 +Output of the normal ls command
 +<code>
 +% ls
 +a  ab  abc  d/  de/  def/
 +</code>
 +
 +Output from the proposed command
 +<code>
 +% ls --color=never --indicator-style=none | awk '{print length, $0}' |
 +sort -n | cut -d" " -f2-
 +a
 +d
 +ab
 +de
 +abc
 +def
 +</code>
 +
 +Ref:- https://stackoverflow.com/a/70628169
 +==== Show file date in different date formats ====
 +tags | YYYY-MM-DD, YYYYMMDD, YYYYMMDD_HHMMSS
 +
 +Use one of
 +<code>
 +--time-style='+%Y%m%d_%H%M%S'
 +--time-style='+%Y-%m-%d'
 +--time-style='+%Y%m%d'
 +</code>
 +
 +For example
 +<code>
 +% ls -l --time-style='+%Y%m%d_%H%M%S' ~/.vimrc
 +-rwx------ 1 rajulocal rajulocal 1112 20201017_141554 /home/rajulocal/.vimrc*
 +
 % ls -l --time-style='+%Y-%m-%d' ~/.vimrc % ls -l --time-style='+%Y-%m-%d' ~/.vimrc
--rwx------ 1 rajulocal rajulocal 1087 2020-04-27 /home/rajulocal/.vimrc*+-rwx------ 1 rajulocal rajulocal 1112 2020-10-17 /home/rajulocal/.vimrc*
  
-% ls -l ~/.vimrc +% ls -l --time-style='+%Y%m%d' ~/.vimrc  
--rwx------ 1 rajulocal rajulocal 1087 Apr 27 20:56 /home/rajulocal/.vimrc*+-rwx------ 1 rajulocal rajulocal 1112 20201017 /home/rajulocal/.vimrc*
 </code> </code>
 +
 +==== indicators ====
 +"ls -F" appends indicators <nowiki>*/=>@|</nowiki> to filenames.
 +  * * means executable.
 +  * / means directory.
 +  * = means socket.
 +  * > means door.
 +  * @ means symbolic link (or that the file has extended attributes).
 +  * | means named pipe.
 +
 +Ref:- https://unix.stackexchange.com/questions/82357/what-do-the-symbols-displayed-by-ls-f-mean
 +
 +==== only show filename and modification time ====
 +<code>
 +ls -al | cut -d ' ' -f 6- 
 +</code>
 +
 +Another way (using find):
 +<code>
 +find -maxdepth 1 -type f -printf "%TY %Tb %Td %TH:%TM\t%p\n"
 +</code>
 +
 +To sort the files based on timestamp (reverse chronological order)
 +<code>
 +find -maxdepth 1 -type f -printf "%T+#%TY %Tb %Td %TH:%TM\t%p\n" | sort -rn| cut -d# -f2-
 +</code>
 +
 +The %T+ is used to sort the output properly and gets removed by cut afterwards.
 +
 +Ref:- https://askubuntu.com/a/1044206/574082
  
ls_usage.1610747314.txt.gz · Last modified: 2021/01/15 21:48 by raju