Useful commands for Linux normal users and administrators
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
PING
parameters
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
Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).
parameters
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
Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).
4- Reverse SSH
ssh -f -N -R 8888:localhost:22 user@somedomain.org
Reverse SSH
this command from the source server and this follow in the destination server:
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:
vim scp://sriram@server1/etc/http/httpd.conf
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
In this post we will see 10 commands that can be useful for any Linux user.
1 Find corrupted JPG image files
This command line allow you to find all corrupted JPG files in current directory and its subdirectories and displays any error or warning found:
$ find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
2 Get all possible problems from any log files
Using the grep command, retrieve all lines from any log files in /var/log/ that have one of the problem states:
$ grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
3 Combine mkdir & cd into single command
This command allow you to create and cd the new directory in a single command:
4 Measure, explain and minimize a computer’s electrical power consumption
Run this command as root to get enough stats. It works on AMD and Intel machines including desktops. If you run on a laptop it’ll give you suggestions on extending your battery life.
You’ll need to install PowerTOP if you don’t have, via ‘apt-get install powertop‘ etc.
To grep the output use:
$ sudo powertop -d | grep ...
5 Convert lowercase letters to upper case and vice versa
The following command is used to convert the letters from lower case to upper case and vice versa. It will be used mainly when creating scripts:
$ echo unixmen | tr '[a-z]' '[A-Z]'
UNIXMEN
$ echo UNIXMEN | tr '[A-Z]' '[a-z]'
unixmen
6 Record your desktop using ffmpeg command
Using the following command we can record our desktop and save as a video file:
$ ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 25 -i :0.0 -vcodec mpeg2video -ar 44100 -s wvga -y -sameq desktop.mpg
The above command will record all your desktop activities and store it in your current working folder.
7 Execute a command at a particular time
It’s similar to cronjob command. It will execute the users command at a given time:
$ echo "cat > sk.txt" | at 15.04
warning: commands will be executed using /bin/sh
job 1 at Wed May 29 15:04:00 2013
The above command will create a new file called sk.txt at 3:04pm.
8 Display top ten running processes sorted by memory usage
$ ps aux | sort -nk +4 | tail
The above command will display the top ten processes which are sorted by their memory usage.
9 Check your system type whether it is 32 or 64bit
The below command will display if the system is 32 or 64 bit. Run the following command in your terminal and verify your system version:
$ getconf LONG_BIT
64
10 Display current Internet usage of applications
The below command will show you which applications are using the internet at present:
$ lsof -P -i -n
No comments:
Post a Comment