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 print out a newline character using the echo command?

Answer:

If you try

echo "foo\nbar"

It will print out

foo\nbar

But if you want the two words separate by an actual newline, you can use

echo -e "foo\nbar"

Output would be

foo
bar

You can combine the "-e" flag with other control characters such as "\t", "\r", "\v"... as well.

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.