Edit

unix commands for everyday

Note
There are some useful commands for everyday

… to find the disks

$ fdisk -l
$ parted --list
$ lsblk -aitfo NAME,MAJ:MIN,SIZE,MODEL,TYPE,FSTYPE,LABEL,UUID,MOUNTPOINT
$ ls -gG /dev/disk/by-id/
$ ls /dev/disk/by-path -al
$ ls /sys/block/sd* -al
$ for i in /sys/block/sd* ; do wwn=`scsi_id -g -u /dev/${i##*/}` ; [ "$wwn" != "" ] && echo -e ${i##*/}'\t'$wwn ;done
$ blkid -c /dev/null
$ cat /proc/scsi/scsi

… to find and replace text

$ grep -rl 'text to search' /path for search/
$ grep 'text to search' -P -R -I -l * | xargs sed -i 's/text/replace/g'
$ find . -type f -print0 | xargs -0 perl -i -pe 's/\xEF\xBB\xBF//'
$ find . -type f -name \*.txt -exec sed -i -r 's/text1/text2/g' {} \;
$ find . | xargs grep "text"
$ find . -name "*.txt" | xargs grep "text"
$ sed -i -e 's/\(Three\)/\/\/\1/g' test.txt
$ sed -i -e 's/\(One\).\(Two\).\(Three\)/\3\.\2.\1/g' test.txt
$ sed -i -r 's/Word1\ word2\ word3/\/\/Word1\ word2\ word3/g' * ;
$ cat test.txt
//###==###
//Word1 word12 word3
test text
//###==###
$ sed '/\/\/###==###/,/\/\/###==###/{//!d}' test.txt
//###==###
//###==###
$ sed '/\/\/###==###/,/\/\/###==###/{//d}' test.txt
//Word1 word12 word3
test text
$ sed '/\/\/###==###/,/\/\/###==###/d' test.txt
$ sed -n '/15.09.2015 12:01/,/15.09.2015 12:03/p' perfdbamon.log
$ sed '/PATTERN-1/,$d' test.txt #delete all lines after pattern
$ sed '2,4d' input.txt test.txt #delete line 2 and 4
$ grep -E 'pattern1|pattern2' filename #OR
$ grep -E 'pattern1.*pattern2' filename #AND

… fast way to delete files

$ perl -e 'for(<*.aud>){unlink}'

… way to rotate listener.log file

$ lsnrctl set log_status off
$ mv listener.log listener.`date +"%Y%m%d"`
$ lsnrctl set log_status on

… iptables rules

$ iptables -A INPUT -s ipaddress -j DROP
$ iptables -D INPUT -s ipaddress -j DROP
$ iptables -F INPUT
$ iptables -vnL INPUT
$ iptables --list
$ iptables --list-rules

… stty

$ stty -a
$ stty cols 132
$ stty rows 80
$ echo -n "Enter you very secret password: "
$ stty -echo
$ read password
$ stty echo
$ stty erase \^a
$ stty erase \^H

… screen

$ screen -ls
$ screen -r
$ screen -r 7849.pts-0.mint
$ screen -r 7849
$ screen -r -D 7849.pts-0.mint (if state is attached)
$ screen -L (logging or ctrl-A and H)
$ ctrl-A and d (detach screen)
$ ctrl-A and K (kill screen)
$ ctrl-d (terminate)
$ screen -S (create screen)

… calculate dir size

$ ncdu (option g + a + c + s) - yum localinstall ncdu-1.13-20.1.x86_64.rpm
$ cdu -ndh -i --max-depth 3 -s (make install)
$ df -Ph /u01/app; cdu -ndh -M 4 -s | tail -20
$ df -Ph .; cdu -ndh -M 4 -s -b | tail -20
$ du -hsx * | sort -rh | head -10
$ du -hsc ./*
$ du -hsc /u01/app/
$ du -hsc /u01/app/*
$ du -ah --max-depth=2 (du -h --max-depth=0;du -sh ./)
$ du -h --max-depth=1 /u01/app | grep '[0-9]G\>' (du -h -d 1 /u01/app | grep '[0-9]G\>')
$ du -h -d 1 -t 1G /u01/app | sort -hr
$ du -h --max-depth=1 /u01/app | grep '[0-9]G\>' | sort -hr
$ ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n10
$ find /u01/app -type f -printf "%s %p\n" | sort -rn | head -n 10
$ find /u01/app -xdev -type f -size +500M -exec ls -alh {} \; | sort -nk 5

%23%23%23%20%60unix%20commands%20for%20everyday%60%0A%3E**Note**%0A*There%20are%20some%20useful%20commands%20for%20everyday*%0A%0A%20%20%20...%20to%20find%20the%20disks%0A%60%60%60bash%0A%24%20fdisk%20-l%0A%24%20parted%20--list%0A%24%20lsblk%20-aitfo%20NAME%2CMAJ%3AMIN%2CSIZE%2CMODEL%2CTYPE%2CFSTYPE%2CLABEL%2CUUID%2CMOUNTPOINT%0A%24%20ls%20-gG%20/dev/disk/by-id/%0A%24%20ls%20/dev/disk/by-path%20-al%0A%24%20ls%20/sys/block/sd*%20-al%0A%24%20for%20i%20in%20/sys/block/sd*%20%3B%20do%20wwn%3D%60scsi_id%20-g%20-u%20/dev/%24%7Bi%23%23*/%7D%60%20%3B%20%5B%20%22%24wwn%22%20%21%3D%20%22%22%20%5D%20%26%26%20echo%20-e%20%24%7Bi%23%23*/%7D%27%5Ct%27%24wwn%20%3Bdone%0A%24%20blkid%20-c%20/dev/null%0A%24%20cat%20/proc/scsi/scsi%0A%60%60%60%0A%0A%20%20%20...%20to%20find%20and%20replace%20text%20%0A%60%60%60bash%0A%24%20grep%20-rl%20%27text%20to%20search%27%20/path%20for%20search/%0A%24%20grep%20%27text%20to%20search%27%20-P%20-R%20-I%20-l%20*%20%7C%20xargs%20sed%20-i%20%27s/text/replace/g%27%0A%24%20find%20.%20-type%20f%20-print0%20%7C%20xargs%20-0%20perl%20-i%20-pe%20%27s/%5CxEF%5CxBB%5CxBF//%27%0A%24%20find%20.%20-type%20f%20-name%20%5C*.txt%20-exec%20sed%20-i%20-r%20%27s/text1/text2/g%27%20%7B%7D%20%5C%3B%0A%24%20find%20.%20%7C%20xargs%20grep%20%22text%22%0A%24%20find%20.%20-name%20%22*.txt%22%20%7C%20xargs%20grep%20%22text%22%0A%24%20sed%20-i%20-e%20%27s/%5C%28Three%5C%29/%5C/%5C/%5C1/g%27%20test.txt%0A%24%20sed%20-i%20-e%20%27s/%5C%28One%5C%29.%5C%28Two%5C%29.%5C%28Three%5C%29/%5C3%5C.%5C2.%5C1/g%27%20test.txt%0A%24%20sed%20-i%20-r%20%27s/Word1%5C%20word2%5C%20word3/%5C/%5C/Word1%5C%20word2%5C%20word3/g%27%20*%20%3B%0A%24%20cat%20test.txt%20%0A//%23%23%23%3D%3D%23%23%23%0A//Word1%20word12%20word3%0Atest%20text%0A//%23%23%23%3D%3D%23%23%23%0A%24%20sed%20%27/%5C/%5C/%23%23%23%3D%3D%23%23%23/%2C/%5C/%5C/%23%23%23%3D%3D%23%23%23/%7B//%21d%7D%27%20test.txt%0A//%23%23%23%3D%3D%23%23%23%0A//%23%23%23%3D%3D%23%23%23%0A%24%20sed%20%27/%5C/%5C/%23%23%23%3D%3D%23%23%23/%2C/%5C/%5C/%23%23%23%3D%3D%23%23%23/%7B//d%7D%27%20test.txt%20%0A//Word1%20word12%20word3%0Atest%20text%0A%24%20sed%20%27/%5C/%5C/%23%23%23%3D%3D%23%23%23/%2C/%5C/%5C/%23%23%23%3D%3D%23%23%23/d%27%20test.txt%0A%0A%24%20sed%20-n%20%27/15.09.2015%2012%3A01/%2C/15.09.2015%2012%3A03/p%27%20perfdbamon.log%0A%24%20sed%20%27/PATTERN-1/%2C%24d%27%20test.txt%20%23delete%20all%20lines%20after%20pattern%0A%24%20sed%20%272%2C4d%27%20input.txt%20test.txt%20%23delete%20line%202%20and%204%0A%24%20grep%20-E%20%27pattern1%7Cpattern2%27%20filename%20%23OR%0A%24%20grep%20-E%20%27pattern1.*pattern2%27%20filename%20%23AND%0A%60%60%60%0A%0A%20%20%20...%20fast%20way%20to%20delete%20files%0A%60%60%60bash%0A%24%20perl%20-e%20%27for%28%3C*.aud%3E%29%7Bunlink%7D%27%0A%60%60%60%20%0A%0A%20%20%20...%20way%20to%20rotate%20listener.log%20file%0A%60%60%60bash%0A%24%20lsnrctl%20set%20log_status%20off%0A%24%20mv%20listener.log%20listener.%60date%20+%22%25Y%25m%25d%22%60%0A%24%20lsnrctl%20set%20log_status%20on%0A%60%60%60%0A%0A...%20iptables%20rules%0A%60%60%60bash%0A%24%20iptables%20-A%20INPUT%20-s%20ipaddress%20-j%20DROP%0A%24%20iptables%20-D%20INPUT%20-s%20ipaddress%20-j%20DROP%0A%24%20iptables%20-F%20INPUT%0A%24%20iptables%20-vnL%20INPUT%0A%24%20iptables%20--list%0A%24%20iptables%20--list-rules%0A%60%60%60%0A%0A...%20stty%0A%60%60%60bash%0A%24%20stty%20-a%0A%24%20stty%20cols%20132%0A%24%20stty%20rows%2080%0A%24%20echo%20-n%20%22Enter%20you%20very%20secret%20password%3A%20%22%0A%24%20stty%20-echo%0A%24%20read%20password%0A%24%20stty%20echo%0A%24%20stty%20erase%20%5C%5Ea%0A%24%20stty%20erase%20%5C%5EH%0A%60%60%60%0A%0A...%20screen%0A%60%60%60bash%0A%24%20screen%20-ls%0A%24%20screen%20-r%0A%24%20screen%20-r%207849.pts-0.mint%0A%24%20screen%20-r%207849%0A%24%20screen%20-r%20-D%207849.pts-0.mint%20%28if%20state%20is%20attached%29%0A%24%20screen%20-L%20%28logging%20or%20ctrl-A%20and%20H%29%0A%24%20ctrl-A%20and%20d%20%28detach%20screen%29%0A%24%20ctrl-A%20and%20K%20%28kill%20screen%29%0A%24%20ctrl-d%20%28terminate%29%20%0A%24%20screen%20-S%20%3Cscreen_name%3E%20%28create%20screen%29%0A%60%60%60%0A%0A...%20calculate%20dir%20size%0A%60%60%60bash%0A%24%20ncdu%20%28option%20g%20+%20a%20+%20c%20+%20s%29%20-%20yum%20localinstall%20ncdu-1.13-20.1.x86_64.rpm%0A%60%60%60%0A%60%60%60bash%0A%24%20cdu%20-ndh%20-i%20--max-depth%203%20-s%20%28make%20install%29%0A%60%60%60%0A%60%60%60bash%0A%24%20df%20-Ph%20/u01/app%3B%20cdu%20-ndh%20-M%204%20-s%20%7C%20tail%20-20%0A%60%60%60%0A%60%60%60bash%0A%24%20df%20-Ph%20.%3B%20cdu%20-ndh%20-M%204%20-s%20-b%20%7C%20tail%20-20%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-hsx%20*%20%7C%20sort%20-rh%20%7C%20head%20-10%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-hsc%20./*%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-hsc%20/u01/app/%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-hsc%20/u01/app/*%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-ah%20--max-depth%3D2%20%28du%20-h%20--max-depth%3D0%3Bdu%20-sh%20./%29%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-h%20--max-depth%3D1%20/u01/app%20%7C%20grep%20%27%5B0-9%5DG%5C%3E%27%20%28du%20-h%20-d%201%20/u01/app%20%7C%20grep%20%27%5B0-9%5DG%5C%3E%27%29%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-h%20-d%201%20-t%201G%20/u01/app%20%7C%20sort%20-hr%0A%60%60%60%0A%60%60%60bash%0A%24%20du%20-h%20--max-depth%3D1%20/u01/app%20%7C%20grep%20%27%5B0-9%5DG%5C%3E%27%20%7C%20sort%20-hr%0A%60%60%60%0A%60%60%60bash%0A%24%20ls%20-1Rhs%20%7C%20sed%20-e%20%22s/%5E%20*//%22%20%7C%20grep%20%22%5E%5B0-9%5D%22%20%7C%20sort%20-hr%20%7C%20head%20-n10%0A%60%60%60%0A%60%60%60bash%0A%24%20find%20/u01/app%20-type%20f%20-printf%20%22%25s%20%25p%5Cn%22%20%7C%20sort%20-rn%20%7C%20head%20-n%2010%0A%60%60%60%0A%60%60%60bash%0A%24%20find%20/u01/app%20-xdev%20-type%20f%20-size%20+500M%20-exec%20ls%20-alh%20%7B%7D%20%5C%3B%20%7C%20sort%20-nk%205%0A%60%60%60%0A%0A%20%20%20%0A@%28Postach.io%29%5Bunix%2C%20disks%2C%20bash%2C%20fdisk%2C%20parted%2C%20lsblk%2C%20for%2C%20blkid%2C%20cat%2C%20published%5D