Showing posts with label ls. Show all posts
Showing posts with label ls. Show all posts

Monday, 6 June 2011

ls Sort by time

-t = sort by modification time [recent at top]

ls -lt

-tr = sort by modification time [recent at bottom]

ls -ltr

Thursday, 13 May 2010

Sorted ls by size

Run an 'ls' but sort the results by file size:

ls -al | sort -n -k5

Thursday, 6 August 2009

Stripping out parts of a filename from an ls

command:
   ls * | cut -f1 -d '_'

in dir with these files:
  6250_DBAGZ_Asset_CF.20090610
   1149_DBAGZ.20090716
   7321_DBAGZ_Asset_CF.20090716
   HYB_DBAGZ_Assets.20090716

output:
   6250
   1149
   7321
   HYB

breakdown:
  cut
  -f1 >>>>> field 1
  -d '_' >>>>>> use delimeter '_' Default is TAB not space

Advanced real word usage:
Searches through nginx log access file for user agent (field 9) - Prints number of user agents by type. Useful for spotting scrapers:
  cat /log/nginx_access/FILE | cut -f 9 | sort | uniq -c | sort -nr | less -S