• Convert a PDF to a JPEG file at 150 dpi:

    $ convert -density 150 ./document.pdf ./document.jpg
  • Extract images from a PDF document:

    $ pdfimages -j document.pdf prefix
  • Text replacement:

    $ sed 's/string to replace/replacement string/g' original-file.txt > new-file.txt
  • Replace all occurrences of str1 by str2 in all files below the /folder path:

    $ find /folder -type f -print -exec sed -i 's/str1/str2/g' "{}" \;
  • Same as above but ignore all content of .svn folders and .zip files:

    $ find /folder -type f -not -regex ".*\/\.svn\/.*" -not -iname "*\.zip" -print -exec sed -i 's/str1/str2/g' "{}" \;
  • Remove trailing spaces and tabs in every XML files:

    $ find /folder -iname "*.xml" -exec sed -i 's/[ \t]*$//' "{}" \;
  • Place a new --- line at the start of each .markdown files (see result):

    $ find ./folder -iname "*.markdown" -exec sed -i '1s/^/---\n/' "{}" \;
  • Place a new --- line before the first empty line of each .markdown files (see result):

    $ find ./folder -iname "*.markdown" -exec sed -i '0,/^$/s//---\n/' "{}" \;
  • Remove lines starting with prefix1: or prefix2: in all .markdown files:

    $ find /folder -iname "*.markdown" -exec perl -p -i -e 's/(prefix1|prefix2): .*\n//sg' "{}" \;
  • Append the content of the addendum.txt file to all .markdown files:

    $ find ./folder -iname "*.markdown" -print -exec bash -c 'cat ./addendum.txt >> "{}"' \;
  • In place charset transcoding:

    $ recode utf-8..latin-1 utf8text.txt
  • Remove all accented characters in a string (thanks to Matthieu for the tip):

    $ echo "éÈça-$" | iconv -t ASCII//translit
  • Get the date of last week:

    $ date +"%Y-%m-%d" -d last-week
  • Get the current date in english:

    $ env LC_TIME=en date +"%a %b %d %Y"
  • Get the number of seconds since epoch:

    $ date +%s
  • Convert back epoch time to human-readable date:

    $ date --date=@1234567890
  • Split a PDF into pages:

    $ pdftk doc.pdf burst
  • Merge 2 PDF documents:

    $ pdftk doc1.pdf doc2.pdf cat output newdoc.pdf
  • Same as above, but for all PDFs of the current folder. This also have the nice side effect of removing all DRMs :) :

    $ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=bigfile.pdf ./*
  • VIM: no autoindent on paste.

  • a list of sed one-liners.

Related content