Recently, CLI is mostly used by Linux/Unix administrators since most popular linux distros come with a complete set of GUI applications that make the user use less and less the command line. In our previous post, we saw 11 useful commands for Linux/Unix administrators, in this post we will see a list of useful commands useful for both administrators and normal Linux users.
For Linux/Unix administrators:
1- Compare a remote dir with a local dir
$ diff -y <(ssh user@host find /boot|sort) <(find /boot|sort)
2- Trace and view network traffic
tcpdump -s 0 -w - port <port> | tcpdump -r - -A
3- Check if a machine is online
ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
c 1 limits to 1 pinging attempt
q makes the command quiet (or silent mode)
/dev/null 2>&1 is to remove the display
&& echo ONLINE is executed if previous command is successful (return value 0)
|| echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you’re offline yourself).
I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done.
Asking for the machine name or IP
4- Reverse SSH
ssh -f -N -R 8888:localhost:22 [email protected]
this command from the source server and this follow in the destination server:
ssh user@localhost -p 8888
5- Show mounted volumes in a table (Thanks to Shawn):
mount | column -t
6- The fastest way to kill tcp or udp port is to run the following command (Thanks to Sriram):
fuser -k PORT-NUMBER-HERE/tcp fuser -k PORT-NUMBER-HERE/udp
7- edit a file on a remote server using vim from your Linux / Unix / OS X desktop:
Commands for Both Normal users and Linux admins
8- Grep your command history (Thanks to Shawn)
history | grep /pattern/
9- Extract audio from Flash video (*.flv) as mp3 file
ffmpeg -i video.flv -vn -ar 44100 -ac 2 -ab 192k -f mp3 audio.mp3
10- copy hybrid iso images to USB key for booting from it, progress bar and remaining time are displayed while copying
time (pv file.iso | dd bs=1M oflag=sync of=/dev/sdX 2>/dev/null)
11- what model of computer I’m using?
sudo dmidecode | grep Product