How to perform simple calculations in Linux shell?
Answer:
Use the "bc" commad.
echo "101+1" | bc
It will gives:
102
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to perform simple calculations in Linux shell?
Answer:
Use the "bc" commad.
echo "101+1" | bc
It will gives:
102
Convert IP address to HEX in Bash script
Answer:
The following Bash script is useful to convert IP address to HEX
#!/bin/sh
IP_ADDR=192.168.1.234
printf '%02X' ${IP_ADDR//./ }; echo
How to check the current logrotate status?
Answer:
logrotate will maintain a status file, normally at the location /var/lib/logrotate/status , you can view the content of this file to see the latest status of all log files managed by logrotate.
Example:
logrotate state -- version 2
"/var/log/apache2/access.log" 2008-12-7
"/var/log/apache2/error.log" 2009-1-25
...
Therefore, it is useful to verify if your desired log files are controlled by logrotate or not.
How to mirror a directory to a remote server over SSH?
Answer:
You can use rsync command for this purpose
Assume you want to mirror the local folder "/home/john" to remote server 192.168.1.5, under the folder "/data/backup/", you need to use the following command
rsync -avuz -e ssh /home/john 192.168.1.5:/data/backup/
If you want to dry-run the rsync, use the "n" flag, e.g.
rsync -avuzn -e ssh /home/john 192.168.1.5:/data/backup/
For more options, checkout the rsync document: http://www.samba.org/ftp/rsync/rsync.html
How to adjust the argument position in xargs?
Answer:
Sometimes you might want to adjust the argument position when using the xargs command, e.g.
echo "foo" | xargs echo "bar"
It gives:
bar foo
Instead, you want the piped argument "foo" to be inserted before the "bar", you can use
echo "foo" | xargs -i echo {} "bar"
Now it gives:
foo bar
That's very handy