General
xargs command
To run commands on standard output of some command instead of using for loop.
# ls | xargs -t -n1 ls -l
Use -i or -I {} for inserting filenames in the middle of command line. For example, To rename all the files in a directory with an .old extension
# ls | xargs -t -i mv {} {}.old
sudo
The default configuration file for sudo is /etc/sudoers. Do not directly edit the /etc/sudoers file. Always use visudo command. If visudo command opens some other editor other than vi, we can correct it setting EDITOR variable. (eg. export EDITOR=vi)
There are four kinds of aliases in sudoers file
- User_Alias
- Runas_Alias
- Host_Alias
- Cmnd_Alias
Each alias definition is of the form
Alias_Type NAME = item1, item2, ... user or group hosts or or (Useralias) (hostalias)= (run-as alias) (command alias)
Converting time to epoch and viceversa
To get the current time in epoch seconds (On HP-UX and Linux)
# date +%s 1214425649 # perl -le "print (time)" 1214426325
Convert from human readable date to epoch (On Linux)
# date +%s -d"Jan 1, 1980 00:00:01" 315561601 # perl -e perl -e "use Time::Local; print timelocal($sec, $min, $hours, $mday, $mon, $year)" # perl -e "use Time::Local; print timelocal(20, 56, 16, 25, 05, 2008)" 1214438180
To convert from epoch to Human readable format (On Linux)
# date -d @1190000000
Sun Sep 16 20:33:20 PDT 2007
or
perl -e "print scalar(localtime(1190000000))"
Sun Sep 16 20:33:20 2007