Đống b-lăm (các câu lệnh linux) của mình

Đôi khi không phải lướt qua mà đọc kỹ bài viết này một chút bạn sẽ thấy nó giá trị. Đống note này mình không thống kế và chi tiết cho nó bởi vì mình còn phải lục lại và xem lại. 

1 - show physical disk using
df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"
2- Helpful alias to grep for the PID.
alias pfind='ps aux | grep '

~/blacktest$ sed -e 's/ENGINE=InnoDB/ENGINE=BLACKHOLE/g' \
> master_struct.sql > master_black.sql

Change string in many files at once and more.
Find all files that contain string XXX in them, change the string from XXX to YYY, make a backup copy of the file and save a list of files changed in /tmp/fileschanged.
find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'

recursive search and replace old with new string, inside files
recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found
grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'

service --status-all | grep running

find files containing text
-l outputs only the file names
-i ignores the case
-r descends into subdirectories
grep -lir "some text" *

Find corrupted jpeg image files
Finds all corrupted jpeg files in current directory and its subdirectories. Displays the error or warning found.
The jpeginfo is part of the jpeginfo package in debian.
Should you wish to only get corrupted filenames, use cut to extract them :
find ./ -name *jpg -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR" | cut -d " " -f 1
find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"

extract email adresses from some file (or any other pattern)
Simply more email-adresses matched
grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})' fiel.html

Print line number
grep -n . datafile ;

Find all files containing a word
This command will find all files recursively containing the phrase entered, represented here by "searchphrase". This particular command searches in all php files, but you could change that to just be html files or just log files etc.
find . -name "*.php" | xargs grep -il searchphrase

If you don't have nl on your system, this achieves a similar effect, the default behavior in nl is to not number blank lines, but this does.
grep -n "^" <filename>

php -i | grep php.ini
Find the location of the currently loaded php.ini file
Quick and easy way to find out which php.ini file is being used. Especially useful if you just need to find the location of the file for editing purposes.

grep -r -i "phrase" directory/
Recursively grep thorugh directory for string in file.
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.

grep -c ^processor /proc/cpuinfo
Returns the number of cores in a linux machine.

ifconfig -a| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
Get mac address listed for all interfaces.

grep -i "$(date +%b" "%d )13:4[0-5]" syslog
Grep log between range of minutes
Returns logs between HH:M[Mx-My], for example, between 13:40 and 13:45.

grep -i "$(date +%b\ %d\ %H)" syslog
Grep syslog today last hour
Uses date to grep de logfile for today and uses it to get the last hour logs. Can be used to get last minute logs or today's logs.

sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' ips.txt | grep ip | sed 's/ip//'| sort | uniq
Extract ip addresses with sed
Extracts ip addressess from file using sed. Uses a tag(ip) to grep the IP lines after extracting. Must be a way to just output regex matched on sed.

grep -Eo \([0-9]\{1,3\}[\.]\)\{3\}[0-9] file | sort | uniq
Extract IPv4 addressess from file

top -b -n 1 |grep httpd|wc -l
Show the number of current httpd processes
Of course, the httpd can be replaced with any other process name

kill -9 `ps -xaw -o state -o ppid | grep Z | grep -v PID | awk '{print $2}'`
Kill all Zombie processes (Guaranteed!)
It identifies the parents of the Zombie processes and kill them. So the new parent of orphan Zombies will be the Init process and he is already 
waiting for reaping them. Be careful! It may also kill your useful processes just because they are not taking care and waiting for their children (bad parents!)

upper() { echo ${@^^}; }
Convert text to uppercase
Usage: upper [STRING]...

lower() { echo ${@,,}; }
Convert text to lowercase
Usage: lower [STRING]...

ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
Check if a machine is online
c 1 limits to 1 pinging attempt
q makes the command quiet (or silent mode)
/dev/null 2>&1 is to remove the display
&& echo ONLINE is executed if previous command is successful (return value 0)
|| echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself).
I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done.
Asking for the machine name or IP
Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).

for user in $(getent passwd|cut -f1 -d:); do echo "### Crontabs for $user ####"; crontab -u $user -l; done
Show crontabs for all users
added echo "### Crontabs for $user ####"; to make clear whose crontab is listed.

Find folder store more than 1gb
du -h --max-depth=1 / | grep '[0-9]G\>'
du -h --max-depth=1 /data_nas/smsgw2 | grep '[0-9]G\>'

Delete more file same one word
rm more file same one word
find /tmp -type f -name word\* -exec rm {} \;

Delete more folder same one word
rmdir rm more folder same one word
find /tmp -name *\2016-12-27\* -exec rmdir () \;

find . -user chichio
find . -group oracle
find . -size +1G | xargs ls -lhd
find . -name '*.py' -print

find . -name '*.py' -fprint file.out
cat file.out

Tao nhieu folder cung luc
mkdir directory{1,2,3}{a,b,c}

Tao nhieu file cung luc
touch file{a .. z}

Copy tu server nay sang server khac dung scp 
scp -v sakila.sql root@

ip add show

Show all port on centos
netstat -tulpn

setenforce 0
setenforce 1
cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.

restart network ubuntu
sudo /etc/init.d/networking restart

cd /etc  && ls -ltr && grep 

history | grep ssh