December 2008
The Archives
-
12.10.08Statistics on a program’s running time$ 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.08Ctrl-X-EWith 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.08apropos$ apropos intro Lists man pages related to 'intro'.
-
12.04.08Extracting the filename from a path$ basename /path/to/this/file file
-
12.02.08Quiet grepUsually 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 ...