使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和l技巧, 当然,有些命令我能记住,但我不敢说能记得如何用它执行某个特定任务。
grep -R "toUppercase()" *
find . -name "autom4te.in"
du -sh barrier_packages/
df -h
iptables -A INPUT -p tcp --dport 111 -j DROP
iptables -A INPUT -p tcp --dport 111 -j ACCEPT
netstat -tunpl
netstat -lntu
-l = only services which are listening on some port
-n = show port number, don't try to resolve the service name
-t = tcp ports
-u = udp ports
-p = name of the program
uname -a
uname -mrs
echo "export PATH=/usr/share/java/bin:\$PATH" >> /etc/profile
lscpu
或
less /proc/cpuinfo
ifconfig
jamvm -verbose[:class|gc|jni]
:class print out information about class loading, etc.
:gc print out results of garbage collection
:jni print out native method dynamic resolution
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head
STAT: 该行程的状态,linux的进程有5种状态:
注: 其它状态还包括W(无驻留页
), <(高优先级进程
), N(低优先级进程
), L(内存锁页
).
echo >/dev/tcp/8.8.8.8/53 && echo "open"
Ctrl + z
fg
apt-cache --names-only search xxxx
openssl rand -hex n
source /home/user/file.name
${variable:0:5}
ssh -vvv user@ip_address
ssh user@ip_address -i key.pem
wget -r --no-parent --reject "index.html*" http://hostname/ -P /home/user/dirs
mkdir -p /home/user/{test,test1,test2}
ps axwef
jar -cvf name.war file
dd if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm -rf /tmp/output.img
hdparm -Tt /dev/sda
echo -n "text" | md5sum
xmllint --noout file.xml
tar zxvf package.tar.gz -C new_dir
curl -I http://www.example.com
touch -t 0712250000 file
wget -m ftp://username:password@hostname
LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
cp some_file_name{,.bkp}
smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir
!100
unzip package_name.zip -d dir_name
cat > test.txt
> test.txt
ntpdate ntp.ubuntu.com
netstat -lnt4 | awk '{print $4}' | cut -f2 -d: | grep -o '[0-9]*'
qemu-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img \
precise-server-cloudimg-amd64-disk1.raw
watch ps -ef
getent passwd
mount -o remount,rw /
mount -o loop /dev/sr0 /mnt
mount -r -t auto /dev/sr0 /mnt
mount --bind /source /destination
mount -o loop /path/to/iso /mnt
vi /etc/yum.repos.d/centosdvdiso.repo
[centosdvdiso] name=CentOS DVD ISO baseurl=file:///mnt enabled=1 gpgcheck=0 gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-6
yum --showduplicates list xxxx | expand
nsupdate < <EOF
update add $HOST 86400 A $IP
send
EOF
grep -r "some_text" /path/to/dir
grep -R --include="*.txt" "foo" ~/projects/
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB "$9 }' | sort -n -u | tail
free -m | grep cache | awk '/[0-9]/{ print $4" MB" }'
vim + some_file_name
!cat:p
!cat
find /home/user -maxdepth 1 -type d -empty
< test.txt sed -n '50,60p'
sudo !!
mount -t tmpfs tmpfs /tmpram -o size=512m
Grep whole words:
grep -w "name" test.txt
echo "some text" | sudo tee -a /path/file
kill -l
kill -9 $$
nmap -p 8081 172.20.0.0/16
git config --global user.email "me@example.com"
To sync with master if you have unpublished commits:
git pull --rebase origin master
find -iname "*txt*" -exec mv -v {} /home/user \;
paste test.txt test1.txt
pv data.log
echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000
expand test.txt > test1.txt
Skip bash history:
< space >cmd
cd -
split –b 100m /path/to/large/archive /path/to/output/files
cat files* > archive
curl -sL -w "%{http_code}\\n" www.example.com -o /dev/null
/usr/bin/mysql_secure_installation
Ctrl + \
stat -c %U file.txt
lsblk -f
find . -type f -exec egrep -l " +$" {} \;
find . -type f -exec egrep -l $'\t' {} \;
printf '%100s\n' | tr ' ' =
ip addr or just ip a
ip link set dev <interface> up/down
ip addr add <ip>/<masklen> dev <interface>
ip route or just ip r
ip r add <net>/<netmasklen> via <gateway>
jar vfu /d/dev/xxx.jar org/apache/hadoop/hbase/filter/
scp local_file remote_user@host:remote_folder
sqlplus user/pass@local_SID
sqlplus> @path.sql
chown hadoop:hadoop datafolder
systemctl stop firewalld
systemctl disable firewalld
datetimectl
datetimectl set-time 2015-11-13
datetimectl set-time 14:15:30
https://stedolan.github.io/jq/
cat << EOF > /tmp/yourfilehere
These contents will be written to the file.
This line is indented.
EOF
touch hbase-fix.sh
cat a.txt | \
while read line; do
echo "hadoop fs -rmr "$line >> hbase-fix.sh
done
uname -r
[root@centos6 ~]# date 010611272012
Fri Jan 6 11:27:00 MYT 2012
less /etc/sysconfig/clock
use tzselect or ln -s /usr/share/zoneinfo/xxxx /etc/localtime
例如 ntp server为192.168.0.1
/etc/rc.d/init.d/ntpd start
service ntpd start
[root@linux ~] # ntpstat
最后提及一点,ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd 文件。
在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes
这样,就可以让硬件时间与系统时间一起同步
hwclock --systohc
This will set the hardware clock to the current system time. You can also do the inverse:
hwclock --hctosys
To display what date/time the hardware clock is currently set to:
hwclock --show
lsof |wc -l
lsof -p pid |wc -l