Linux 部分命令总结

查看

head

cat

tail

type

file

lsb_release

uname

last -n 5 | awk '{print $1 "\t" $3}'

head -n 5 /etc/passwd | awk 'BEGIN {FS=":"} {print $1 $2 $3}'

ifconfig | grep inet |sed -n '1p'| awk '{print $2}' | awk 'BEGIN {FS=":"} {print $2}'

grep -v ^# rdis.conf

less
less +F startup.sh

more

uname -r

umask

alias

wc -l /etc/inittab

./shutdown.sh & tailf ../logs/catalina.out

# 
# -lt:sort by ctime
# -l:sort by name otherwise: sort by modification time
ls -clt 	/home
ls -cl 		/home

ls -ld		/home
history

free
wc

帮助

man

info

man 1p diff

man apropos

help -d cd

搜索

whatis

whereis

which

locate

grep

find


find . -name "" -type f -print

# 推荐
find . -name "" -type f -print0

# 搜索*sh,并每两个一行,打印
find . -name "*sh" -type f -print | xargs -L 2 echo

#-l默认为-l 1,现在使用-L max-lines替代
# -I {} 替换标准输入的名称
find . -name "pass*" | xargs -l -I{} cp {} tmp/

# 
find . -type d -empty | xargs rmdir

网络

ifconfig
ifconfig eth0	up | down | status
netstat -ano 	| find 6379

netstat -tunlp 	| grep 6379



service network start

service iptables start

service NetworkManager restart

dig

telnet ip port

man iptables-save
route add -host 192.168.10.2 	gw 192.168.84.1
route del 						gw 192.168.84.1
route del 		192.168.10.2	gw 192.168.84.1

route add -host 192.168.10.2 netmask 255.255.255.0 gw 192.168.84.1


route add -host 10.2.112.2 gw 192.168.84.1 netmask 255.255.255.0

route add -host 10.2.112.2 gw 192.168.84.1
curl www.baidu.com

wget -O /etc/yum.repos.d/CentOS-Base.repo http://allen-hz-bucket.oss-cn-hangzhou.aliyuncs.com/centos/Centos-6-Vault-Official.repo
nss

mill-tool eth0

route [-n]

ip addr ls

进程

ps aux | grep top

ps -i:2181

ps -l

ps -el

ps -ef

ps -ly

lsof -p 3980

lsof -i:6379

lsof -i @localhost:2181

lsof -i tcp@127.0.0.1:2181

lsof -i tcp@:2181

lsof -i tcp:2181

lsof -i tcp


ps -ef | grep name --> pid

top -p pid

kill -l

pkill

任务

jobs

top

fg 1

bg 1

系统状态

uptime

top

nproc

lsproc

lscpu



配置文件

/proc/cpuinfo

/etc/rc.local

/etc/rc.d/rc.lcoal

/etc/init.d/iptables

/etc/sysconfig/iptables

/etc/inittab

/var/run/redis_6379.pid

/var/log/secure

/etc/init.conf

/etc/sudoers

/etc/default/grub


# 6.9
/etc/udev/rules.d/70-persistent0-net.rules
/etc/sysconfig/network-scripts/ifcfg-eth0

/etc/default/grub

/etc/fstab

1、/etc/sudoers
可使用:visudo命令编辑

root	ALL=(ALL) 	ALL
chyong ALL=/sbin/shutdown -c

2、/etc/rc.d/rc.local

JAVA_HOME=/usr/local/jdk
export JAVA_HOME
cd /usr/local/zookeeper/bin
./zkServer.sh start

3、/etc/sysconfig/iptables(6.9)

[root@bwsy redis-cluster]# cat !$
cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Sun Mar 17 07:24:10 2019
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p tcp -m tcp --dport 6379 -j ACCEPT 
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2181 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7001:7006 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited 
#-A INPUT -s 127.0.0.1/32 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT 
#-A INPUT -s 192.168.1.2/32 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT 
-A FORWARD -j REJECT --reject-with icmp-host-prohibited 
COMMIT
# Completed on Sun Mar 17 07:24:10 2019

用户

w

who

last

lastlog [user]

useradd

groupadd

文件

mkdir

chown

chmod

chgrp

ln -s /usr/local/redis/ /root/redis

磁盘

fdisk

mkfs

lsblk

df
df -h | awk '{if (NR>1) {print $1 "\t" $5} }'

du -sh .

# -a:所有文件(不仅文件夹)
# -s:参数的总大小
du

软件管理

rpm
rpm -qa gcc
rpm -qf /bin/ls
rpm -i xxx.rpm

yum search gcc
yum install gcc -y

# 查看那个package提供该文件
yum provides "*/nmcli"


# NetworkManager command line
nmcli con | sed -n '1,2p'

sed -i 's/HISTSIZE=1000/HISTSIZE=10000/g' /etc/profile && source /etc/profile

yum clean packages
yum clean headers
yum clean metadata
yum clean plugins
# 上面全部
yum clean all
tar
tar -zxvf 	redis-3.0.0.tar.gz
tar -cxf 	redis-3.0.0.tar.gz	-C /usr/local/redis

开关机



shutdown -h now

reboot

环境

set
env

参数

$?
$$
$-
!$

测试

ab 
ab -n 4 -c 2 https://www.baidu.com

其他

sync

exit

su - user

passwd

logout

init

pwd

# -P:物理目录(软连接)
cd -L:默认
cd [-P]

# -e:开启解析backslash escape(反斜杠转义)
echo -e '\a'

# ``和$()等价
echo `date`
echo $(date)
echo $LANG
echo tmp/* | xargs -t mv {} .



diff

comm

printf '%s %s\n' 1 2 3 4 5 6

setup

runlevel
bash 	hello.sh
. 		hello.sh
source	hello.sh
./hello.sh

常用软件命令

redis-server redis.conf
redis-cli -p 6379 shutdown


zkServer.sh start
zkServer.sh status
上一篇:Http简介


下一篇:http请求头中的Accept的用处和常用的值