Helpful Linux Commands

Helpful Linux Commands

Find whats on port running on a particular  port : ex port 8098
$ sudo netstat -apn | grep 8098
tcp 0 0 10.224.35.187:8098 0.0.0.0:* LISTEN 19666/beam.smp

Find status of a particular process : ex status of riak
$ sudo /etc/init.d/riak status
riak (pid 19666) is running..

Find a process . Ex. If you want to find cassandra process
$ ps aux | grep cassandra

Search files for a string : ex. search for 127.0.0.1 in current folder
$ grep 127.0.0.1  ./*

Find a file by name: ex. cassandra.yaml file
$ sudo find / -name cassandra.yaml

Restart a service ex. restart cassandra service
$ sudo service cassandra restart

To view tail of the error log . ex: view nginx error log tail
$ tail -f /var/log/nginx/error.log

Grep through the history . ex . find ps in the history of commands
$ history | grep ps
44 cd opscenter-3.1.1/
48 ./opscenter
56 ./opscenter-agent

To find the largest 10 directories
$find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
8.0K ./PZService/Classes
20K ./PZService/Cassandra

Find Release Information:
$ cat /etc/*release*
Amazon Linux AMI release 2013.03
cpe:/o:amazon:linux:2013.03:ga

Linux find out the current running kernel version:
$ cat /proc/version
Linux version 3.4.37-40.44.amzn1.x86_64 (mockbuild@gobi-build-31005) (gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC) ) #1 SMP Thu Mar 21 01:17:08 UTC 2013

Find Memory Info:
$ cat /proc/meminfo
MemTotal: 608480 kB
MemFree: 10932 kB
Buffers: 22908 kB
Cached: 178544 kB
SwapCached: 0 kB
Active: 425812 kB
Inactive: 133708 kB

CPU Info:
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 45
model name : Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz

Environment Variable:
To set environment variable WAIT_FOR_ERLANG .
$export WAIT_FOR_ERLANG=60
To view environment variable WAIT_FOR_ERLANG
 echo $WAIT_FOR_ERLANG

Add Sublime Text as Default Editor:
$ ln -s ?/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl? ~/bin/subl
$ export EDITOR=?subl -w?

Delete files older than specified days. ( files older than 7 days )
$ sudo find . -name ?*.sql? -mtime +7 -exec rm -rf {} \; 

Search files older than specifed date and delete them through KRON Job.

$crobtab -e
0 1 * * * cd /usr/share/nginx/www/kaizen/KRON/DBBackup_Files/&&find . -name ?*.sql? -mtime +4 -exec rm -rf {} \;

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *