December 2008

The Archives

  • 12.10.08
    Statistics on a program’s running time cmd | rafacas | (0)
    $ time script.sh real 1m0.004s user 0m30.020s sys 0m20.030s Runs script.sh (it could be any program). When script.sh finishes, time command outputs a message on stdout giving timing statistics about this program's running time. These contain the elapsed real time between invocation and termination, the user's CPU time, and the system's CPU time.
  • 12.08.08
    Ctrl-X-E shell | n0str0m0 | (0)
    With this keystroke combination, you open the editor specified by the $EDITOR variable (or emacs if the variable is not set). Once you write the file and quit, bash will execute the commands written in the editor. This is especially useful when you want to write a small script.
  • 12.06.08
    apropos cmd | pfortuny | (0)
    $ apropos intro Lists man pages related to 'intro'.
  • 12.04.08
    Extracting the filename from a path cmd | rafacas | (0)
    $ basename /path/to/this/file file
  • 12.02.08
    Quiet grep automated, shell | pfortuny | (0)
    Usually during an cron job, one needs to check for an expression in a log file, or in the output of a command, without generating any cumbersone new output (such as a standard grep would do): this is exactly the use of the -q option of grep. For example: for i in `grep -v '^#' /etc/passwd | cut -f1 -d:` grep $i /var/log/samba/log.smbd | grep -q 'failed to authenticate' if [ $? == 0 ] ; then mail -s 'Error in samba' $i <<EOM ...