Saturday, June 5, 2021

"ls" on macOS : Simple commands to make looking for files easier

Looking for files (by size, date, type) can be made easier if you know a few simple Unix commands - as opposed to using a GUI file manager such as "Finder" on macOS. Here are some commands that I use on my Macbook Pro.


machine type : 

   Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; 

   root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64

   macOS 11.3.1 (BigSur)


-ltr : newest on bottom (reverse time order)

       $ls -ltr

       drwxr-xr-x+   4 albchi  staff        128 Jul  5  2019 Public

       drwxr-xr-x  186 albchi  staff       5952 Jun  5 05:05 Txt # <- newest on bottom




-lt : oldest on bottom

      $ls -ltr

      drwxr-xr-x  186 albchi  staff       5952 Jun  5 05:05 Txt

      drwxr-xr-x+   4 albchi  staff        128 Jul  5  2019 Public # <- oldest on bottom



-l : alphabetical z on bottom, long format

     $ls -l

     drwxr-xr-x    9 albchi  staff        288 Aug 24  2020 0DevVersionMacos

     -rw-r--r--@   1 albchi  staff       3033 Feb 27  2020 xindex.html # <- alphabetically, z at bottom


-lr : alphabetical 0 on bottom, long format

      $ls -lr

      -rw-r--r--@   1 albchi  staff       3033 Feb 27  2020 xindex.html

      drwxr-xr-x    9 albchi  staff        288 Aug 24  2020 0DevVersionMacos # <- alphabetically, 0 at bottom


-p or -F : directories with slashes

     $  ls -F or ls -p

     Attic/ migrations/ truffle-config.js

     contracts/ test/

-d -- */: directory name only

     $ls -d -- */   # JekyllGithubNetlify/  JekyllRubyBuildWebSites/


-Slr : biggest on bottom

       $ls -Slr

       -rw-r--r--@   1 albchi  staff                0 May 13  2020 index_mini.html

       -rw-r--r--      1 albchi  staff  167905792 Oct 30  2020 Txt.tar # <- largest file on bottom


No comments :

Post a Comment