Tuesday, May 4, 2010

Linux - Basic & useful commands

How to find CPU & Memory detail of linux
cat /proc/cpuinfo (CPU)
cat /proc/meminfo (Memory)


How to find if any service is listening on particular port or not ?
netstat -an grep {port no}
For example if you know that tomcat is running on 8080 port so to check if tomcat service is listening or not then use
netstat -an grep 8080

How to sort files based on Size of file ? ( useful to find large files in log directory to delete in case disk is full )
ls -l sort -nrk 5 more

How to delete files older than N number of days ? (Useful in delete log, trace, tmp file )
find . -name ‘*.*’ -mtime +[N in days] -exec rm {} \; ( This command will delete files older then N days in that directory, always good to use it when you are in applcsf/ tmp,out,log directory)


How to create symbolic link to a file ?
ln -s pointing_to symbolic_name

e.g. If you want to create symbolic link from a -> b
ln -s b a
(Condition:you should have file b in that directory & there should not be any file with name a)

How to find the Unix/Linux version of a particular host ?
uname -a

How to set/unset line numbers in vi editor?
To set line number
:set number

To unset line number
:set nonumber

Total number of files in particular directory

find /usr/local/perl-5.10.1 -ls wc -l


How to set an alias for complex/different commands?

alias l=“ls –alF”
alias cls=clear




/Proc file system - Various Kernel Statistics
/proc file system provides detailed information about various hardware devices and other Linux kernel information.

cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/zoneinfo
cat /proc/mounts


Search the particular key word content in a file

grep -iR <phrase>
< phrase > -> word you want to search if you want to search a sentence enclose within '' (single quotes)

To make your search more faster if you know what type of files to be searche use the following


find -iname "*.xml" | xargs grep -iR <phrase>

Disk Usage listing with depth one level depth:
du -h --max-depth=1 .

No comments:

Post a Comment