Useful Linux commands from… MY LINUX COMMAND VAULT

Following are are more commonly used and useful commands, that even i use almost everytime:

mount — Shows all mounted drives on the Linux box

du -hs — Shows the folder size in Short forms like MB, GB, KB

ls -l — Shows the files and folders along with permissions inside the current folder or specified folder, much like dir on windows.

chmod — Changes the rights on the current folder or specified folder (-R switch to make it recursively applicable on sub folders)

ps -uax — Shows you all process with their CPU utilization, Mem utilization and process id which can be used in the kill command.

ps -uax | grep <process name> — Shows a specific process with the specified <process name> along with the utilization’s and process id used in the kill command.

kill -9 <processid> — kill a process with the specified process id abruptly, it is always better to kill a process based on id as it is safer nit harming other processes.

touch —  change the access date time of the file.

free — check RAM memory free on the linux box, can be used with -m switch to get sizes in MB.

df -h — shows all drives included the mounted once’s.

top — shows all processes along with other useful info about the process, sort of like taskmanager on windows. i generally use ps instead of this command.

mount /dev/hda1 /mnt/data — mount a attached drive to the local filesystem, if the filesystem of the attached drive is not standard then -t <filesystem> should be used here.

pwd — Shows the full part of where you currently are.

grep -i <string> filename.txt  — search the filename for the specified <string>

whereis <package name> — to find out and check whether the specified <package name> is installed or not and where it is installed.

rpm -qa | grep <package name> — this one is better than the above command and searches for packages installed on your linux box.

updatedb — Updates local filesystem paths into a search db which later on becomes handy for using locate.

locate <filename> — Searches the whole linux box for the specified <filename>. It is advisable that updatedb is run always before executing locate.

scp -r <file or folder name> <user>@<server ip>:/tmp/ — copy a file or a folder from local linux box to another linux box with ip <server ip> and at path /tmp/. check the firewall setting at the server for this to work.

ssh -X <user>@<server ip> — connect a server with ip <server ip> and with user <user> in a graphical mode (-X).

system-config-<service> — Displays settings of the specified <service> like example system-config-samba shows a graphical settings of the samba server. These are located on /usr/bin/ on linux boxes.

cat /proc/mdstat — check out the status of the Software RAID if installed on your linux box.

fdisk /dev/hda — check the partition table or create a new partition table on the attached drive in this case</dev/hda> . This is a very sensitive command.

smartctl –all /dev/hda — displays all SMART information on the specified drive </dev/hda>. Can be used with -d switch in some cases like -d ata at the end.

ifconfig — shows all internet connections and ip adresses on linux box.. same as ipconfig on windows.

wget <URL> — download a file from a URL.

telnet <ip> <port> — checks if the specified <port> is open of the host with <ip>

ping — Pings a system

traceroute <domain name or IP> — traces the route from your linux box till the <host or IP>

sudo passwd root — Change root password.

find / -name *.pid — find any file with .pid extension.

/etc/rc.d/rc.local — startup scripts.

tail -n 100 <filename> — show last 100 lines of the <filename> specified.

cp -rf <org> <dest> — copy files recursively from folder <org> to folder <dest> can be used with –reply=yes switch to say yes to all override questions.

find / -type f -size +20000K — Find large sized files on your linux box.

nohup <script> & — keep the script running even when the remote ssh session is closed with messages kept on a file named “nohup.out”.

fdisk -l —  get all drives info on your linux box.

cat /proc/version  — check OS version and name and architecture (x86_64, i368)

uname -a — check OS version and name and architecture (x86_64, i368)

cat /etc/redhat-version — check red hat version

service <service name> <start | stop | restart> — start/stop/restart the specified service with name <service name>.

passwd -l <username> —  lock user (-l)  and to unlock(-u)

dmesg — displays system messages. can be used with more for page by page viewing.

yum install <package name> — installs specified package along with dependencies. can be used with -y switch if one does not want the confirmation message.

tar <xvf | xvfz | yxf> <filename.tar | .tar.gz | .tar.bz2> — untar the filecontents.

su – — login as a root user from a normal user.

grep -B5 -A5 “search string” largelog.out — search a large log file for a string and display 5 lines before and after the match. more example: grep -B5 -A5 “string” largelog.out > test.txt, grep -R -B5 -A5 “string” /etc/*

cat /dev/null > <hugelogfile> — empty a very huge log file.

du -sch ./* — get sizes of all sub folders.

find /path/to/dir -type f -mtime +3 -exec rm {}\ — Deleting files older than 3 days.

ls -1R | grep -i .*.jpg | wc -l — count all specific extention files(in this case .jpg) in the current folder.

ls -1R | wc -l — count all files in the current folder.

DISCLAMER: as far i can remember i used all these commands and never had problems. But do use them carefully. No one should be held responsible if some damage ever occurs using these commands. Use it at your own risk.




About Dominic

J for JAVA more about me :
This entry was posted in Thechy Stuff. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s