From personal use - Windows - Scripting - Bash - Awk - Distributions - Debian - Configuration management software - To explore - See also

This page is a quick references for common problems I had and the quick fix to move on. There is no complex script here, check instead shell_scripts for an attempt at structuring the small scripts I use often and thus try to maintain.

From personal use

^ : Control key
meta : Alt key

Windows cmd.exe shell

  • cygwin/mingw
    • notes on path (e.g. interpreter like ruby, no probleme with java paths, ...)
    • MingW system variables are available as $UP not%UP%
  • sc delete servicename : remove the service
    • still require to first stop it then delete it from the registry
  • ifconfig /flushdns : force to discard the current DNS cache (useful if hosts configuration has been updated)
  • attrib changes attributes of files and directories
  • devcon to unmount devices including USB keys
    • devcon remove @usb\vid*
  • Windows Server 2003 Resource Kit Tools including timeit
  • fsutil volume diskfree C: : free space (in bytes) in the C: hard drive
  • shutdown -r -t 0 : reboot now
    • shutdown -a : abort shutdown
  • cd /D x:\path\
    • actually switches to the other directory on the other drive
  • packing and sending daily backup
    • set dt=%date:~10,4%%date:~4,2%%date:~7,2%
    • 7z a internalwiki_%dt%.tar wiki
    • 7z a internalwiki_%dt%.tar.bz2 internalwiki_%dt%.tar
    • del internalwiki_%dt%.tar
    • pscp internalwiki_%dt%.tar.bz2 user@server.tld:/home/user/backups_path/
  • tasklist : list the active processes
    • WMIC PROCESS get Caption,Commandline,Processid
  • doskey /history > mycommands.txt : save the commands you typed in the mycommands.txt file
  • path %path%;c:\myother\bin\path\; : appends the directory to the current path
    • note that this is not a permanent change
  • 7z : use 7zip command-line interface
    • 7z a internalwiki.tar wiki then 7z a internalwiki.tar.bz2 internalwiki.tar
  • Stupid Command Prompt Tricks by Jeff Atwood, Coding Horror 2005
  • Windows : Command Processor, PC Tools
  • PowerShell by Microsoft
    • recommended by Jonathan

PuTTY suite

  • pscp
    • does require the -agent option to check for Pageant running instances
    • and obviously a working key pair
    • yet... it sometimes seem to work without!?
  • pageant
  • PuTTY Tray improved version of PuTTY (Win32). It features some cosmetic changes, and a number of addons to make it more useful and much more fun to use.
  • KiTTY as recommended in #tmux on freenode


Warning, this section is really shell specific (i.e. bash != zsh ...)

  • sed
    • expression1\|expression2 = Matches expression1 or expression (esp with GNU sed)
    • see Vi and PmWiki for other regular expressions
    • crontab -l | sed "/^SSH_AUTH_SOCK/s,[^=]*$,$SSH_AUTH_SOCK," | crontab
      • no need for `` or $() since it is a global variable
      • delimiter changed to take into account the slashes in the path
  • note that sed does allow access to environment variables and even to execute command but the ouput should not in include the delimiter
    • e.g. x=`whoami`; echo "fff" | sed "s/ff/$x /" will work
      • but fail if there is / in the username
        • if it is the case and you can predict with certainty the character then change the delimiter e.g. x=`whoami`; echo "fff" | sed "s|ff|$x |"

Check my ~/backups/*.sh and ~/bin/*.sh for examples


  • from Bash guide
    • see also the associated #bash channel on freenode
  • history especially as with screen ~/.bash_history does no cover all the commands
    • practical also to get the lat commands via e.g. tail and to output them into a future script
      • history | tail -30 > my_new_bash_script
  • Making sure it is being executed in the right environment
    • #!/bin/bash
  • Link to the motivation and the context
    • # http://related/wiki/URL
  • Testing for explicit help or improper number of argument
    • EXP_ARGS=1
      if [ "$1" = "--help" -o "$1" = "-h" -o $# -lt $EXP_ARGS ]
        echo "Check against dead link for PmWiki"
        echo "usage: $0 [PmWiki_path]"
        echo "if the second parameter is omitted path is assumed to be ..."
    • should be generalized to most of ~/bin scripts following Path:/pub/
  • Handling omitted arguments
    • # if $2 is empty, use the last part of the URI
      if [ $# -lt 2 ]
  • date -d @1234909950 to convert unixtime time stamp to the default format
  • for loop
    • for X in $(ls $1/path/* | grep -v ExcludeThis | grep -v Site | sed "s/.*wiki\.d\///")
       this $1/path/$PAGE > $1/other_path/$;
       that $1/other_path/$;
  • LANG=en_EN.utf-8 (required in the terminal and the application too)
  • $@ to handle every arguments passed to the script
  • PS1="[\u@\w]$ " set permanently in in ~/.bashrc
  • seq -w -s" " 1 12 returns 01 02 03 04 05 06 07 08 09 10 11 12
  • $((do some math))
  • echo $(( $(cat file | sed "s/.*\d//" | wc -l) * 1024))

See also env, export, printenv, etc...


  • awk '{print $2}'
  • grep action=edit page_generated.txt | awk '{ SUM += $2} END {print SUM}'



Configuration management software

See also the WebWorkersCampParis talk and the "infrastructure as code" paradigm presented during Automated Infrastructure is on the Menu with Chef, O'Reilly Webcast July 2010

  • Nimbus open source toolkit that allows you to turn your cluster into an Infrastructure-as-a-Service (IaaS) cloud.

To explore

See also


My notes on Tools gather what I know or want to know. Consequently they are not and will never be complete references. For this, official manuals and online communities provide much better answers.