All my command lines

Featured

Here is a collection of commands lines, code and configuration snippets I collected for several years while working as an Open-Source Software Engineer:

For the context, you can read this introduction.

Website Backup Script Updated: Take Care of Hidden Files now.

I’ve updated my website-backup python script.

Change log:

  • Use set ftp:list-options -a command to force lftp to download hidden files (like .htaccess and so on).
  • Use --force parameter to allow auto-deletion of multiple outdated rdiff-backup increments.
  • Defensive incremental backup policy: keep 32 last backups instead of 32 days of backup.

I also added a debug mode as suggested by Sacha.

Text, Date & Document processing commands

  • 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 -xdev -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 -xdev -type f -not -regex ".*\/\.svn\/.*" -not -iname "*\.zip" -print -exec sed -i 's/str1/str2/g' "{}" \;
    
  • 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
    
  • 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.

How-To fix UTF-8 Issues on Mandriva 2007 Upgrade

bad-file-character-encoding-utf-81 If you updated your Mandriva from 2006 to 2007 and you’ve done that manually, some of your files in your home directory may look like the one on the screenshot. This is due to the adoption of UTF-8 as the default character encoding for file systems in Mandriva. Normally the conversion is done automatically at install, so if you’ve upgrade your Mandriva manually…

Well, to fix this, it’s quite easy and explained on the following Mandriva wiki page: UTF8 issue when reinstalling and keeping a previous /home that was not in UTF8. The convert-filenames-to-utf8.pl script will do everything for you !