Ellioh Thot'o > Home

Some shell commands

15 Feb 2013, Tagged in : shell, command-line, and linux

  1. Repeat previous command
!!
  1. Copy a directory with scp
scp -r user@server:/path/directory .
  1. Display memory use under the current directory
du -h -d 2
  1. Open a file directly from a SVN server
svn cat svn://svn_server/project/branches/path/file|less
  1. Open a previous version of a file without doing ‘svn update’ or ‘svn checkout’
svn cat -r r49441 working_dir/path/file
  1. Svn log get revisions by date : below we retrieve revision of 15th Feb 13
svn log --revision {2013-02-15}:{2013-02-16}|less
  1. Use grep –exclude. For example, exclude svn hidden directory.
 grep  earchedterm . -nR --exclude="*\.svn*"  2>/dev/null
 grep pattern -Rn --exclude=*\.{svn,html,log} . 2>/dev/null
  1. Open a file returned by grep. We use the option ‘-l’ to “clean” the path.
grep  checkStep1 . -lR  2>/dev/null|xargs vim -o
  1. Remove redondant information from apache logs (referer, error, etc.)
tail -f /var/log/apache2/mahara-test.error.log | perl -pe 's/, referer:.*//'
tail -f /var/log/apache2/mahara-test.error.log | perl -pe 's/\[error\]\s+\[client.*?\]\s+//; s/, referer:.*//'

More details : http://nigel.mcnie.name/blog/removing-the-referer-part-of-php-error-messagse-from-apache-logs

  1. Display files containing a pattern (in php files):
find . -type f -name "*.php" -exec grep -il 'HistoryController' {} \;
grep -iRHs 'HistoryController' . ;