Linux 系统核心命令

简介: cat /etc/sysconfig/i18nLANG="zh_CN.UTF-8"www.google.com,www.bing.com,www.baidu.

cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"

www.google.com,www.bing.com,www.baidu.com

shutdown -r now
shutdown -h now
init 0 关机
init 6 重启
/etc/inittab
shutdown -h +1 1分钟后关机
shutdown -r 11:00 11点重启
halt/poweroff/reboot

logout exit
pwd -P 显示链接文件的源目录

./bashrc profile

cd - 上一次的环境
{1..5}

目录克隆:
tree -fid --noreport /data>>/root/a.txt
mkdir -p 'cat /root/a.txt'

touch -a -m t yymmddhhmm.ss
ls -t
ls -r
ls -S
ls -X
ls -c
ls -u
ls|xargs rm -rf

mv -n 不覆盖
mv -f 覆盖
mv -u 新旧

find . ! -type d
depth -maxdepth
-name "." -o -name "zz"
xargs -i 倒
xargs -p 提示
for n in seq 14

find . -type f -mtime +7|xargs rm -rf
find . -name x|xargs -i mv {} /data
-print0|xargs -0 xx find的print0是用来处理带空格的文件的

rename from to file
basename /path/file == file
dirname /path/file == /path

lsattr test
chattr +a test
chattr +i

file xx
md5sum file
chown user
chown :group
chown user:gourp

chmod a= file
u,g,o
chmod 文件和文件夹的区别


img_a2e904217d169d06646828e3ac3ac89d.png
image.png

??文件的权限不能为1


img_7bc3f5a4331cbaa39911a3d280a51ca6.png
image.png

目录的起始权限777 文件666


img_dd4db370e578e14f9335c33accdfad73.png
image.png

echo $UID
id -un id -gn
umask -S
sed -n "61,69p" /s


img_4d991d70f7a186abd18247a69c51f256.png
image.png

sork -k 4 log 按第4列排列文件
more -3 显示3行
more +3 从第3行开始
!调用shell,=输出当前行号,/查找,v调用vi
ls /ddd/more -10
less -i 忽略大小写
-N 行号,
n/N
G移动到第一行,g移动到最后一行
head -n 8 file

tail -5 末尾5行
tailf
cut -d ":" 分割符


img_fb1ba3b3a5254584f5fa50b3fb9880c2.png
image.png

cut -d : -f 1 /file
cut -d : -f 3-4 /file

每500k分割一次文件
split -b 500k -d lvm lvm_

paste 合并文件的例子


img_b400b000da95b4ebbb0cac5409fbdeea.png
image.png

img_3f02b70114ea32dcd4be37645150f27e.png
image.png

sort -n 按数值排序,-u 重复行去掉,-t 指定分隔符,-k 按指定区间排序


img_7e398ad7c606278dec7a9e906a6343df.png
image.png

img_c406b0fd0f03b97e51e0bea5e7fc0d28.png
image.png

sort 默认字符,-n数字

join


img_ac2685ae09b002f9a2d388bffa4e918b.png
image.png

img_f5b509bf784d9e449cb488393ee96e60.png
image.png

uniq file
uniq -c file
sort -n file|uniq -c
awk -F "/" '{print $3}' file|sort|uniq -c|sort -rn
cut -d "/" -f 3 file|sort|uniq -c|sort -rn


img_a80bfe880829e80acd65160547885acd.png
image.png

wc -c 字节,-w 单词,-l 行数,
who | wc -l:目前几个人登录

iconv -f he -t ha xx
cat -A file;dos2unix file
diff a b
diff -y a b
diff -y -W 30 a b

vimdiff a b 可视化
diff -u a b
diff -y a b 常用
rev 反向输出

tr ‘a’ 'b' <file 替换
小写转大写
tr [a-z] [A-Z] < file
tr -d 'a' < file
echo "aaaaaaabbbbbbbbbbccccccc"|tr -s abc 连续字符压缩成一个
tr -c '0-9' * <file 除了0-9,所有都替换

tee 标准输出和其他
tee -a 追加

vi


img_7a1fe6f0f2a6655513553269530e97c5.png
image.png
img_3bb1bbcc090fab09c77ee2f3e225bafa.png
image.png
img_0531f014063c765078257d66d64c663e.png
image.png

u


img_08b7f3cd225c5c96b7cd904d6ee64d9f.png
image.png
img_17cb61861437dcbf6af75188a94a1717.png
image.png

img_57ff3b99d492a725cf83e1eaeb291718.png
image.png

grep


img_77e4a1b39a35e6ce3547642739b08645.png
image.png

grep -Ev "^|#" file [! -dpath] && mkdir -p path; if [UID -ne 0 ];then
exit 1;
fi
if [# -ne 2 ];then exit 1; fi case "1" in
"add")
exit
;;
"del")
exit
;;
*)
exit
;;
esac

sed -i 没有i,不会影响文件
a 追加 d删除 i 插入,p 打印,s替换
sed -i '2a sldjfldskj' file
sed -i "2d" file
sed -i "2,3d"
sed -i "s/ss/sss/g" x

awk "NR==20,NR==30" file
awk '{sum+=0}END{printsum}' file
END{for(key in arrary)print key,array[key]}
awk $0整行

awk 'NR==2,NR==6{print NR,0}' file1,3,NF
awk替换
awk '{gsub("/a","/b",0);print0}'
取IP地址
ifconfig ens160|awk 'NR==2{print $2}'

awk -F "" '{print $3}'|sort|uniq -c
域名访问次数统计

img_54c6ff5088bee8c99ca86aa279566aae.png
image.png

img_cd1b7c02e9995abfb7f9cc3a46bd228b.png
image.png

dmesg 查看系统启动异常
stat file


img_73f3fb81ffc75ecc1762896a5be7a999.png
image.png

stat -c %a file

du -a du -a du -s du --exclude --max-depth
du -h --max-depth=2 /usr/local --exclude=
日期


img_eb3984babc2ce7dce308fc6c46858f9b.png
image.png

date +%F -d "-1 day"


img_1f969f06236694e8ad10f71661e10cd7.png
image.png

date -d "" +%Y %m %d %H %M %S
date -s xx
%F %T


img_625b016c382e5434023878a3be9ce276.png
image.png

watch -n 2 -d
which whereis locate

tar zxvf xx.tar.gz
tar zcvf xx.tar.gz llj dsklfj
tar jxvf
tar jcvf
--exclude=


img_7732b3bbead68c41901f0022edb96903.png
image.png

gzip -9 xx
gzip -d xx
gzip -l xx

zip unzip -d


img_0098168120dc46791d621f58579ccff9.png
image.png

rsync -v 详细输出
-z 传输时进行压缩
-a 保留所有+递归
-r 递归
-t 保持时间属性
-o 保持所
-p
-g
-D
-l
全部是保留
-e
--exclude
--exclude-file
--delete

rsync -av /data/ /data2
删除文件
rsync -av --delete /null/ /tmp/
rsync -av 10.0.0.9:/tmp /tmp
rsync -av -e 'ssh -p 22' /tmp ///
rsync -avz


useradd


img_8c45abaa355d88e87cc3c24ace2fdbe9.png
image.png

usermod


img_efb3b1795f9394b6b1b55c96f78265c8.png
image.png

userdel -f
passwd


img_f30abc6432ea17cf81411b1bff349e5e.png
image.png

passwd -n 7 -x 60 -w 10 -i 30 username
7天内不能修改密码,60天后修改,10天前通知,过期后30天禁用

10个用户,设置随机密码


img_8b26e250bec98920a195aca4c516ad6d.png
image.png
img_716a26ea8f4b74aaff7b51ee3e797d81.png
image.png

chpass 批量修改密码


img_4ffbc51babbec26b1bf53dfa272dea7f.png
image.png

img_bc80bcf8535fd37b1e1258516b05febb.png
image.png

img_f0f9ceec78ea4f6c1d6c04e329add9e3.png
image.png

a ALL=(ALL) NOPASSWD:ALL
a ALL=(ALL) ALL


img_c770092f01fea49dbf2a99d83afa8cfd.png
image.png

last

lastb 失败记录
lastlog 所有

partprobe /dev/sdb 不重启,让内核分区表更改
非分区式


img_0b22bdec15d44d44992b48a40bd02e4b.png
image.png

tune2fs调整文件系统
resize2fs 调整
fsck

dd if=/dev/sdb1 of=a.img
dd if=/dev/zero of=/dev/sdb1
dd if=/dev/zero of=test.data bs=1M count=2


img_673d095491d9906db5242f4a6db99193.png
image.png

img_e81ac44a4d44b5e3b3a15ef8c2b0bbd9.png
image.png

sync 刷新
kill


img_35caef321ee7a09923b56efc3e429cf2.png
image.png

killall
pkill

top -d 3

追踪nginx的调用信息
strace -tt -f /nginx/sbin/nginx
ltrace 跟踪进程调用库函数
runlevel
0 停机《 1单用户 2无网络多用户 3多用户 5图形界面多用户 6重启
init

route add -net 10.0.0.1/24 gw xxx


img_e4c89f9bd58cd907ca98ce61c9b5d073.png
image.png

img_5d7feba30419ad30753a7ec2030921f3.png
image.png

img_ebf91c15692b33c9ba585b170edba0c6.png
image.png

arp
arp -n


img_3a72c8bfd1a494ea5b55248ab8f20f39.png
image.png

ss 安装,yum install -y iproute
ss -s 统计


img_d455745eaaec34166ef0640aea0d2fa0.png

ss -ano|more

ping -s 1024 www.xx

img_18e9394dd698e9944bf1489889390062.png
image.png

trouroute

nc ip port
nc -z ip 20-30
nc -u -z ip 20-30

ssh ip "free -m"


img_071facc00ab9c88dc482d3829454a535.png
image.png

wget --limit-rate=3k
wget -c
wget -b 后台
监控网站是否正常
wget -q -T 3 --tries=1 --spider www.baidu.com&&echo $?

dig www.baidu.com
dig -X 172.xx

nmap
nmap -O -sV xxx
nmap -sn xxx
nmap -sT xxx
namp -sU xxx


img_4c5d027533cde02ff8490c4059d748f2.png
image.png
img_623723d7eb7af93ca9ea7aaf8b4f9f40.png
image.png

tcpdump
tcpdump -i eth0
tcpdump -q
tcpdump -n host 10.0.0.1
tcpdump -n src host 10.0.0.1
tcpdump -n dst host 10.0.0.1
tcpdump -n port 22
tcpdump -n port 22 and ! 10.0.0.1


lsof -c ls
lsof -i:22
lsof -p 33
lsof file

uptime 运行时间和负载
free -m
vmstat -a 2 5 虚拟内存统计信息,每2秒一次,5次
vmstat -m 内存使用xinxi
vmstat -d 磁盘读写
vmstat -p /dev/sdb1
mpstat 5 6
mpstat -P ALL
iostat


sar
sar -u
sar -P ALL
显示CPU
sar -r
显示内存
sar -n DEV
网卡
sar -d
磁盘

chkconfig:2345 20 80

目录
相关文章
|
7天前
|
SQL 缓存 监控
|
7天前
|
前端开发 Linux Shell
|
1天前
|
Linux 网络安全 数据库
linux centos系统搭建samba文件服务器 NetBIOS解析 (超详细)
linux centos系统搭建samba文件服务器 NetBIOS解析 (超详细)
|
1天前
|
存储 安全 Linux
深入理解 Linux 用户和用户组的基本概念 + 相关命令 (一篇就够)
深入理解 Linux 用户和用户组的基本概念 + 相关命令 (一篇就够)
|
1天前
|
Linux 数据库
Linux 常用基础命令(2024年最新篇)新手小白必看 初识Linux
Linux 常用基础命令(2024年最新篇)新手小白必看 初识Linux
|
1天前
|
存储 监控 Ubuntu
Linux 中常用的 systemd 命令讲解
Linux 中常用的 systemd 命令讲解
|
1天前
|
存储 移动开发 Linux
Linux系统之部署h5ai目录列表程序
【5月更文挑战第3天】Linux系统之部署h5ai目录列表程序
11 1
|
1天前
|
存储 缓存 Linux
【Linux常见基本命令,一文速通(一)】
【Linux常见基本命令,一文速通(一)】
5 0
|
2天前
|
Linux 数据库
如何在 Linux 中使用帮助命令?
【5月更文挑战第5天】
19 1
如何在 Linux 中使用帮助命令?
|
2天前
|
数据可视化 搜索推荐 Linux