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.

List 10 most often used commands

Answer:

You can list the top 10 most often used commands in your Linux, by the following method.

# history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head 

135 ls
63 cd
48 exit
46 sudo
34 tail
30 cat
29 df
18 date
17 vi
12 pwd

How to truncate a file?

Answer:

Assume you have a file named "test.txt", now you want to truncate (remove the content) of the file, you can use:

> test.txt

That's all.

Move a long running job to background

Answer:

Assume you have a job running for a very long time, and you might want it to run in background, even you have logged out from the SSH session.

1. Suspend it

# [Ctrl-Z]

2. Make it run in background

# bg && disown

You can now safely logout from the SSH session.

Find all files on a system larger than X MB

Answer:

To find all files on a system larger than X MB, is easy with the find command

# find / -type f -size +100M

All files larger than 100M will be returned.

What is the file dead.letter in my home folder?

Answer:

The file dead.letter is usually created by mail client such as /usr/bin/mail, when you abort the message being sent, a copy of the message will be saved in your home folder: dead.letter.