September 2nd, 2009
Masao
Sourcing a script can be useful for exporting variables in the current shell.
However, you can’t use “dirname $0″ to get the directory of the script.
Here’s how to get the same effect of dirname, but still allowing you to export variables.
Relative path:
DIRNAME=${BASH_ARGV[0]%/*}
Full path:
ABSDIR=$PWD/${BASH_ARGV[0]%/*}
If you bash shell prompt is empty when logging in, here’s how to fix it.
Create a ~/.bashrc file:
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Create a ~/.bash_profile file:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
This is how to convert seconds into HH:MM:SS in bash:
$ date -d '1970-01-01 100 sec' +'%H:%M:%S'
00:01:40
Here’s how to monitor multiple cores on Linux:
# mpstat -P ALL
Example:
Monitor all CPU’s in 1 second intervals forever
# mpstat -P ALL 1
February 17th, 2009
Masao
The new short way:
$ date -d '1 day ago' +'%Y/%m/%d'
2009/07/21
Or the longer way:
Yesterday in epoch seconds
$ yesterday=$((`date +'%s'` - 86400))
Get default formatted yesterday's date
$ date -d "1970-01-01 $yesterday sec"
Tue Feb 17 01:27:32 PST 2009
Same thing in YY-MM-DD
$ date -d "1970-01-01 $yesterday sec" +"%Y-%m-%d"
2009-02-17
November 30th, 2008
Masao
For example, the “kill” manpage shows:
SEE ALSO
bash(1), tcsh(1), kill(2), sigvec(2), signal(7)
This is how to view section 7 of the “signal” manpage:
man 7 signal
How to quickly copy a file or directory over SSH using tar:
tar -cf – myfile | ssh target_host tar -xf -
If you want to change the target directory, use this:
tar -cf – myfile | ssh target_host “cd /target_dir; tar -xf -”
Recent Comments