Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jan 012010
 

How to reverse print a file?

Answer:

Normally, you can print a file to standard out by using

cat test.txt

It will show something like:

a
b
c

However, if you want to start from the last line, you can use tac (actually it is reverse of the cat command)

tac test.txt

It will give:

c
b
a

Dec 312009
 

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.

Dec 312009
 

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