Tuesday, August 9, 2016

IMP Linux Command

Route add (Linux)

/sbin/route add -host 10.200.186.1/32 gw 192.168.10.249

/sbin/route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.10.253

route add 192.168.5.0 mask 255.255.255.0 192.168.2.253 -p  --- (Window's)

Route Delete

route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.10

######################  END  #################################

Delete multiple files through awk command in linux

ls -lrth|egrep -v "Jul 27"|awk {'print $9'}|xargs rm -rfv

ls -lrth -----list file

egrep ---for exclude 

awk {'print $9'} ---print value

xargs rm -rfv --- remove file 

######################  END  #################################

du-sch * | grep G  -------------------   Search files size  in GB


du-sch * | grep M  -------------------   Search files size  in MB

ls -lrth |grep ^d | awk {'print $9'}|xargs du -sch  ---- Search  directory size only 

######################  END  #################################

Exclude 9, 10 Aug day & bzip2 format files & list all .txt files and zip 

ls -lrth *.txt|egrep -v "Aug  9|^d|bz2|Aug 10" l awk {'print$9'}lxargs bzip2 &

######################  END  #################################

rsync -rave "ssh -i /root/backupmlkey.pem" *_error_reporting_*_20160629* root@192.168.10.X:/mnt/logs_bkp_archive/sa1/

######################  END  #################################


Move 60000 logs files


# var/log/httpd/  ----log path

#mv `ls -lrth | head -n 60000 | awk {'print $9'}` /mnt/archive_logs/192.168.10.x/apache_bkp/  

######################  END  #################################

gzip files which has space in name 


for i in `ls -ltrh | awk {'print $9'} | sed 's/\ /\\\ /g` ; do gzip $i ; done


######################  END  #################################



Check httpd process 

ps aux  | awk '{print $6/1024 " MB\t\t" $11}'  | sort -n


######################  END  #################################
Search & replace work in vim mode

:%s/existing name/new name/g
######################  END  #################################


Go to first line in a file in vim


  • gg,
  • :1,
  • 1G,
  • or 1gg.
Go to last line in a file in vim

shift + G
######################  END  #################################
FIND THE FILES FROM 3 MONTHS OLD AND REMOVE


find /yourdir -type f -name "filename.*" -mtime +90 -exec rm {} \;


#find . -name *.log* -mtime +90 -exec rm {} \;
but before that get a listing to see what you are about to delete
#find . -name *.log.* -mtime +90 -exec ls -tl {} \;
Search and remove is a potentially dangerous command make sure you are in the directory where you are deleting files find . means present directory



sudo find /var/log -type f -name "*.1.gz" -delete

######################  END  #################################

finds files in a directory that are older than 30 days and remove them

find /home/amit/log/ -mtime +30 -exec rm {} \;  

find . -mtime +30 | xargs rm

######################  END  #################################

Linux / UNIX create soft link with ln command 

ln -s /path/to/file /path/to/symlink


No comments:

Post a Comment