| Command | Description |
|---|---|
| cd .. | Move up one level to upper directory. |
| cd /root | Move |
| pwd | Show working directory (your current position). |
| ls -lah | Show all files and directory in working dir with format as list, all (show hidden files) and human readable size (eg. with Mb). I use it as general listing. |
| ls -ltr | ls with order by date. |
| ls | wc -l | Count files on a directory. |
| ls -lahS | ls with order by file size. |
| df -h | Check disk space. |
| du -hd 1 /root | Check disk usage for every directories under |
| wget -c -url- | Use |
| grep -Rnw '/path/to/search' -e 'pattern' | find in files, use |
Showing posts with label bash tips. Show all posts
Showing posts with label bash tips. Show all posts
Linux Commad Quick Reference
Get Current Month As Number in BASH
Use bc to convert month from current date to eliminate character zero ('0') when returned month is under 10.
This useful when you need to do some numeric operation using month.
sample :
# retrieve month ( assume current date is September, 17 2012 )
M1=`date -%m` # result: 09
M2=`date -%m|bc` # result: 9
# numeric operation
let "M1=$M1-1" # error: -bash: let: M1 = 09: value too great for base (error token is "09")
let "M2=$M2-1" # result: $M2 is 8
This useful when you need to do some numeric operation using month.
sample :
# retrieve month ( assume current date is September, 17 2012 )
M1=`date -%m` # result: 09
M2=`date -%m|bc` # result: 9
# numeric operation
let "M1=$M1-1" # error: -bash: let: M1 = 09: value too great for base (error token is "09")
let "M2=$M2-1" # result: $M2 is 8
Subscribe to:
Posts (Atom)