Reply to comment

bash one liners

Find IP's in exim log that are in hosts.deny:

user@example $ grep `date '+%Y-%m-%d'` /var/log/exim_rejectlog | perl -lne 'print $1 if ( /\[(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\]/ )' | sort -u | xargs -0 -I IP egrep IP /etc/hosts.deny


Accept command line arguments in a bash alias like in csh:

user@example $ alias apgg='theapg () { apg -m $1 -x $1 -a 0; apg -m $1 -x $1 -a 1; exit 0; }; theapg $1'


Feed a list of filenames that have spaces in them to a command using xargs. Here the files are of name "Excel 2009-04-08 04;34;44.zip" - actually needed this because else need to remove old backups by hand...

user@example $ ~/gymbackups $  ls | xargs -d '\n' -I FN echo "ls -al 'FN'" | sh
-rw-r--r-- 1 gregg gregg 225911982 Apr  8 05:19 Excel 2009-04-08 04;34;44.zip
-rw-r--r-- 1 gregg gregg 225939060 Apr  9 05:19 Excel 2009-04-09 04;34;36.zip
-rw-r--r-- 1 gregg gregg 225941296 Apr 10 05:19 Excel 2009-04-10 04;34;38.zip
-rw-r--r-- 1 gregg gregg 225945178 Apr 11 05:19 Excel 2009-04-11 04;34;46.zip


Find big files from where you are at, in megabytes (designated by "M")

alias big='BIG () { find . -size +$1M -ls; }; BIG $1'


Un-gzip and untar a lot of files at once..

for file in `ls *.tar.gz`; do gunzip $file; newfile=`echo $file | sed 's/\.gz//'`; tar -xvf $newfile; done

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.