Labels

Showing posts with label Frequently Used Commands. Show all posts
Showing posts with label Frequently Used Commands. Show all posts

Three basic Git commands




1) git add -A

git add -A is equivalent to  git add .; git add -u.

git add .  ( This will add all files but does not remove files )
git add -u ( This will add only changes but will not add any new files created )

So we use

git add -A ( this will take care of both the commands )

2) git commit -m “Commit changes text ex: I have added new function xyz to the file

3) git push origin  


example of branch name : develop


Another 3 frequently used commands include :

git pull
git status 
git merge origin/Branchname

Linux list all processes based on memory consumption .

list top 5 processes
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

list all processes in assending order .
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS


How to copy directory structure in linux

Sometimes we need to copy only directory structure leaving content ( files )

find . -type d >dirs.txt

xargs mkdir -p

How to drop cache or in-memory cache on linux and free up some memory ?

$ echo 1 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache
$ echo 2 | sudo tee /proc/sys/vm/drop_caches  # drop dentries and inodes
$ echo 3 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache, dentries and inod

Also we can use 

echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches



This is also used when we take benchmarks of server.

Get CPU RAM MEMORY of all the servers on the network


In order to accomplish this you have to have an account with password less login for all the server on the network you want to retrieve data

Here is my tutorial for password less login

Create a file "ips" which should contain all the ip's you want to retrive data for ( 1 ip per line )


for i in `cat ips`;do ssh -t $i 'echo -e -n `uname -n `"   '$i' " ;cat /proc/cpuinfo | grep "cpu cores" | uniq';done > cpucores

( This one will not work in single core cpu's or vm's )

for i in `cat ips`;do ssh -t $i 'echo -e -n `uname -n `"   '$i'" ;grep MemTotal /proc/meminfo   ';done > Mem_details


for i in `cat ips`;do ssh -t $i 'echo -e -n `uname -n `"   '$i'  " ; sudo /sbin/fdisk -l | grep Disk ';done >hdd_details 

( This one will not work in single core cup's or vm's )

After you run all the three commands you will have three files in your directory

1) cpucores - list servername ip-address and number of cores
2) Mem_details - list servername ip-address and memory details in kb
3) hdd_details - list servername ip-address and drive and size.

How to check syntax of dhcpd (dhcpd.conf file )

/usr/sbin/dhcpd -t -cf /etc/dhcpd.conf

 Some other quick tips:




1. Syntax checking for dhcpd files:



/usr/sbin/dhcpd -t -cf /etc/dhcpd.conf



This will do a basic syntax check to find those missing ; or other odd things.



2. host {} are global. You will see this warning if you place the host in a subnet zone. This is because when ISC will parse the file and make hostnames work globally (you can also make it do neat if then things but that makes my head hurt.) For the most part it is useful to put hosts in a group setting. This keeps them out of subnets, and also allows you to put common items with them (say for PXE booting with cobbler).



group {

next-server rhn.example.com;

filename “pxelinux.0″;



host noah {

hardware ethernet 00:11:00:11:00:11;

fixed-address 192.168.1.121;

}

}

How to get list of all cron jobs ( crontab ) in a server

Run below as root :


for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done


If you want to see who owns that cron job run below :

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done


getent passwd cut -d: -f1 perl -e'while(<>){chomp;$l = `crontab -u $_ -l 2>/dev/null`;print "$_\n$l\n" if $l}'

Some Find commands regularly used for finding disk usage


find . -size +500000 -print

du -ch | grep total ( total size of directory)

du -sk * | sort -nr | head -3

find /home -type f | xargs ls -s | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head

find / -type f -size +300000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

du -hs /home/* | grep G

du -hs /home/* | grep M

Command to import SSL certificate need for java applications

keytool -import -alias anotherdomainname -file /tmp/certificatename.cer -keystore $JAVA_HOME/jre/lib/security/cacerts