Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

dsjkvf http://dsjkvf.livejournal.com/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

various du applications

list of folders accompanied by size (human-readable), sorted by name:
   1  
   2  du -hd 1 | sort -k 2

list of folders accompanied by size (human-readable), sorted by size:
   1  
   2  du -hd 1 | grep [0-9]K | sort -n -k 1 ; du -hd 1 | grep [0-9]M | sort -n -k 1

recursive list of folders and files, which are less, than 1MB
   1  
   2  du -ah | grep '[0-9]K' | sort -n -k 1 | less

recursive list of folders and files, which are more, than 1MB, but less, than 1GB
   1  
   2  du -ah | grep '[0-9]M' | sort -n -k 1 | less

same, but folders only
   1  
   2  du -h | grep '[0-9]M' | sort -n -k 1 | less

same, but files only
   1  
   2  find . -type f -size +2048 -exec du -hs {} \; | sort -n -k 1 | less

substitution for 'ps -aux | grep [P]ROCESS'

as we know, invoking grep after ps with first letter of the PROCESS enclosed in brackets [] (like this: ps -aux | grep [P]ROCESS), excludes grep PROCESS from the output. so, instead of typing those brackets manualy every time, we may use the code below:
   1  
   2  FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
   3  REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
   4  ps -aux | grep "[$FIRST]$REST"


you may use it as separate shell-script -- like this:
   1  
   2  #!/bin/sh
   3  FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
   4  REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
   5  ps -aux | grep -v "full/path/to/your/script" | grep "[$FIRST]$REST"


or just include it in your .bashrc or similar -- like this:
   1  
   2  function psg
   3  {
   4  FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
   5  REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
   6  ps -aux | grep "[$FIRST]$REST"
   7  }
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS