概述
cd:进入
[root@moli ss]# cd - // 回到之前的文件路径
[root@moli ss]# cd /usr/bin // 根据绝对路径切换
[root@moli ss]# cd // 快速回到家目录
[root@moli ss]# cd myjava //使用相对路径
[root@moli ss]# cd ../../usr/bin // 根据相对路径使用
ls:列表查看
[root@moli ss]# ls // 列出目录下所有内容
[root@moli ss]# ls -l // 以列表形式打印目录下的内容,缩写 ll,打印目录下所有文件的详细信息
[root@moli tmp]# ls -ld b.txt // 查看指定文件属性
-rwxrwxrwx 1 root root 0 Nov 21 14:30 b.txt
[root@moli ss]# ls -lt // 以列表形式打印,并且以时间进行排序
[root@moli ss]# ls -ltr // 目录内容列表,时间排序,升序,默认倒序
[root@moli ss]# ls -ltr [路径] //列出指定文件下的所有内容
[root@moli ss]# ls -alrt // 列出隐藏文件 -a表示隐藏文件,
[root@moli /]# ls -lrt media mnt // 同时列出多个文件
mnt:
total 0
media:
total 0
pwd:显示当前路径
[root@moli ss]# pwd // 显示当前路径
touch:创建文件
[root@moli ss]# touch a.txt // 创建一个空文件
rm:删除文件
[root@moli ss]# rm a.txt // 删除文件,提示是否删除 注意:此时rm不可以删除目录
[root@moli ss]# rm -rf a.txt // 没有提示,直接删除 注意:此时rm -rf可以删除目录 f 表示强制删除 r表示目录
[root@moli ss]# rm -ri a.txt // -i 提示是否删除目录,确认删除才会被删除
mkdir:创建目录
[root@moli ss]# mkdir wrx // 创建wrx目录
[root@moli ss]# mkdir -p /home/wrx/wrx/wrx // 创建层级目录
rmdir:删除目录
[root@moli ss]# rmdir /home/wrx/wrx/wrx // 删除指定目录
cat: 查看小文件内容
[root@moli ss]# cat a.txt // 查看小文件的内容
[root@moli ss]# cat >a.txt // 写入文件,如果文件不存在,则直接创建
[root@moli ss]# cat -n a.txt // 每行文件内容显示行号
less:查看大文件内容
[root@moli ss]# less aa.txt // 查看大文件的内容
// 空格键:翻页 回车键:更新一行 q:退出 d: 向上更新一行
more:查看大文件内容
[root@moli ss]# more aa.txt // 查看大文件的内容
// 空格键:翻页 回车键:更新一行 q:退出
head: 查看文件前n行内容
[root@moli ss]# head aaa.txt // 默认查看文件前10行
[root@moli ss]# head -20 aaa.txt // 查看文件指定行数内容
[root@moli ss]# head -n 20 aaa.txt // 查看文件指定行数内容
tail 查看文件后n行内容
[root@moli ss]# tail aaa.txt // 默认查看文件后10行
[root@moli ss]# tail -20 aaa.txt // 查看文件指定行数内
[root@moli ss]# tail -n 20 aaa.txt // 查看文件指定行数内容
[root@moli ss]# tail -f access.log // 动态查看日志
cp:复制文件
[root@moli ss]# cp a.txt class/ // 复制文件到指定路径
[root@moli ss]# cp a.txt class/newname.txt // 复制并重命名
[root@moli ss]# cp -a a.txt class/ // 带属性复制,所以可以用来拷贝目录
mv:移动/重命名
[root@moli ss]# mv 123.txt 345.txt // 重命名
[root@moli ss]# mv 123.txt wrx/newname.txt // 移动并重名
[root@moli ~]# mv a.sh ~/tmp
ln:建立链接文件
[root@moli ss]# ln -s ./moli/a.txt . // 建立软连接,将moli文件夹下的a.txt链接到当前,删除a.txt后,软连接将不能用
[root@moli ss]# ll // l表示的就是链接文件
[root@moli ~]#
diff: 比较差异
[root@moli ss]# diff 123.txt 456.txt // 对比两文件的差异
ip addr: 查看ip地址 | ifconfig
[root@moli ss]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:16:3e:18:a2:57 brd ff:ff:ff:ff:ff:ff
inet 172.28.223.163/20 brd 172.28.223.255 scope global dynamic noprefixroute eth0
valid_lft 313714785sec preferred_lft 313714785sec
inet6 fe80::216:3eff:fe18:a257/64 scope link
valid_lft forever preferred_lft forever
[root@moli ss]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.28.223.163 netmask 255.255.240.0 broadcast 172.28.223.255
inet6 fe80::216:3eff:fe18:a257 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:18:a2:57 txqueuelen 1000 (Ethernet)
RX packets 1854014 bytes 476849824 (454.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1385293 bytes 1095569216 (1.0 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ssh: 远程连接主机
ssh root@47.103.206.151 // 远程连接主机,需要输入密码,用户已经指定root
hostname: 主机名
[root@moli ss]# hostname
moli
id: 查看用户信息
[root@moli ss]# id
uid=0(root) gid=0(root) groups=0(root)
[root@moli ss]# id root
uid=0(root) gid=0(root) groups=0(root)
uname:查看系统信息
[root@moli ss]# uname // 查看系统 linux
Linux
[root@moli ss]# uname -a // 查看系统详细信息
Linux moli 4.18.0-193.el8.x86_64 #1 SMP Fri May 8 10:59:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@moli ss]# uname -n // 查看系统主机
moli
uptime:查看服务器信息
[root@moli ~]# uptime
19:46:27 up 18 days, 8:56, 1 user, load average: 0.00, 0.00, 0.00
// 服务器时间 运行时间 用户数 负载情况:1分钟、5分钟、15分钟负载
w:查看系统信息
[root@moli ~]# w // 查看系统信息
19:48:56 up 18 days, 8:59, 1 user, load average: 0.08, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 139.226.109.101 19:35 0.00s 0.01s 0.00s w
free: 查看内存使用情况
[root@moli ~]# free // 查看内存使用情况
total used free shared buff/cache available
Mem: 1870836 201376 929852 1984 739608 1500748
Swap: 0 0 0
[root@moli ~]# free -m // 查看内存使用情况 m显示单位
total used free shared buff/cache available
Mem: 1826 196 908 1 722 1465
Swap: 0 0 0
[root@moli ~]# free -g // 查看内存使用情况 查看模糊,不推荐
total used free shared buff/cache available
Mem: 1 0 0 0 0 1
Swap: 0 0 0
[root@moli ~]# free -h // 查看内存使用情况 人性化 推荐使用
total used free shared buff/cache available
Mem: 1.8Gi 196Mi 908Mi 1.0Mi 722Mi 1.4Gi
Swap: 0B 0B 0B
// Swap: 虚拟内存,交换空间的内存
df:查看文件系统磁盘使用情况
[root@moli ss]# df // 查看磁盘使用情况
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 919952 0 919952 0% /dev
tmpfs 935416 0 935416 0% /dev/shm
tmpfs 935416 448 934968 1% /run
tmpfs 935416 0 935416 0% /sys/fs/cgroup
/dev/vda1 41931756 2704156 39227600 7% /
tmpfs 187080 0 187080 0% /run/user/0
[root@moli ss]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 899M 0 899M 0% /dev
tmpfs 914M 0 914M 0% /dev/shm
tmpfs 914M 448K 914M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/vda1 40G 2.6G 38G 7% /
tmpfs 183M 0 183M 0% /run/user/0
// tmpfs: 关机内存消失
top:实时查看系统情况,如CPU、内存的使用
[root@moli ~]# top // 按住键盘q退出
top - 22:50:18 up 18 days, 12:00, 2 users, load average: 0.01, 0.01, 0.00
Tasks: 91 total, 2 running, 89 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.3 us, 0.7 sy, 0.0 ni, 97.3 id, 0.0 wa, 0.3 hi, 0.3 si, 0.0 st
MiB Mem : 1827.0 total, 858.6 free, 222.4 used, 746.0 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 1424.1 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
50048 root 10 -10 158780 27388 15656 S 1.0 1.5 45:41.86 AliYunDun
1 root 20 0 177000 10864 8156 S 0.3 0.6 0:16.08 systemd
63504 root 20 0 0 0 0 I 0.3 0.0 0:00.15 kworker/0:1-events
top -b // 批处理打印
top -p // 某个进程的pid top -p 22985 -b -d 1 -n 20
top -d // 几秒刷新一次
top -n // 刷新几次
netstat -tunlp | grep nginx :查看网络端口使用情况
[root@moli ss]# netstat -tunlp // t显示tcp端口、u显示udp端口、n以数字形式显示地址和端口号、l指明listen端、p显示进程的pid和名字
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 981/sshd
udp 0 0 127.0.0.1:323 0.0.0.0:* 728/chronyd
udp6 0 0 ::1:323 :::* 728/chronyd
[root@moli ss]# netstat -tunlp | grep nginx // 查看程序端口占用情况
其他的命令:vmstat | iostat | ss
ping:检测网络是否畅通
ping www.baidu.com // 检查网络是否畅通
ping -c 3 -i 30 www.baidu.com // -c次数 -i时间间隔
echo:标准输出命令
[root@moli ~]# echo "this is a echo"
this is a echo
[root@moli ss]# ls
123.txt 456.txt aaa.txt
[root@moli ss]# echo "dhjdshkh" > 123.txt // > 表示
[root@moli ss]# cat 123.txt
dhjdshkh
[root@moli ss]# echo 'xhskjh sk' >> 123.txt // 追加命令
[root@moli ss]# cat 123.txt
dhjdshkh
xhskjh sk
[root@moli ss]# llll
-bash: llll: command not found
[root@moli ss]# echo $? // 判断上条命令使用情况,非0表示上条命令执行错误
127
man:查看linux命令帮助文档
[root@moli ss]# man ls // man + 命令 查看linux命令的帮助文档
// 注意: 帮助文档较多时,点击键盘的/,左下角输入想要查找的内容,回车即显示包含关键字的内容
help: 查看内部shell内置命令帮助文档
[root@moli ss]# help if // 查看内置shell命令帮助文档
[root@moli ss]# ls --help // 结果类似于man ls
[root@moli ss]# sed -h
clear:清屏
[root@moli ss]# clear // 清屏 => ctrl + l
who:查看
root pts/0 2020-08-30 10:35 (139.226.109.101)
root pts/1 2020-08-30 11:24 (139.226.109.101)
[root@moli ss]# whoami // 我是谁
root
wc: 统计行数
[root@moli ss]# wc -l 123.txt // 统计行数
2 123.txt
[root@moli ss]# cat -n 123.txt // 查看最后一行显示的数字即为多少行
1 wrx123
2 234234
grep: 查找
[root@moli ss]# grep '123' 123.txt // 查看有多少符合条件的字符,这种方式不明显
wrx123
[root@moli ss]# grep '123' 123.txt | wc -l // 加上 wc -l 查找加统计 就比较明显了
1
[root@moli ss]# grep -n '234234' 123.txt // 显示匹配的行号
2:234234
[root@moli ss]# grep -c // 统计匹配的行数
[root@moli ss]# grep -o // 仅显示匹配到的字符串
[root@moli ss]# grep -E // 使用ERE,相当于egrep
[root@moli ss]# grep -w '234234' 123.txt // 精确查看
234234
[root@moli ss]# grep -nv '234234' 123.txt // 显示不被匹配的行号
[root@moli ss]# grep -v '234234' 123.txt // 显示不被匹配的行和行号
wrx123
[root@moli ss]# grep -i 'Wrx123' 123.txt // 忽略大小写问题
wrx123
# grep [OPTIONS] PATTERN [FILE...] // grep + 正则 + 文件
find:查找
[root@moli /]# find / -name 123.txt // 查找根目录下指定文件所在的相对路径
/home/ss/123.txt
[root@moli /]# find ./ -name 123.txt // 查找当前路径下指定文件路径
/home/ss/123.txt
[root@moli /]# find ./ -name '*.txt' // 查找当前路径下所有txt文件路径
/home/ss/123.txt
[root@moli /]# find / -type f -name ss // 查看指定目录所在的路径
/usr/sbin/ss
/usr/share/bash-completion/completions/ss
uniq:统计
[root@moli ss]# uniq -c 123.txt // 统计并显示数量
1 wrx123
1 234234
[root@moli ss]# uniq -c 123.txt | sort -rn // 统计并排序 -rn从高到低
1 wrx123
1 234234
[root@moli ss]# uniq -c 123.txt | sort -n // 统计并排序 -n从低到高的排列
1 234234
1 wrx123
[root@moli ss]# grep '234234' 123.txt | uniq -c // 查找统计
1 234234
PS: 查看进程信息
[root@moli ~]# ps
[root@moli ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
[root@moli ~]# ps -ef | grep nginx
root 63488 63459 0 22:30 pts/1 00:00:00 grep --color=auto nginx
[root@moli ~]# ps -ef | grep -v grep | grep nginx
[root@moli ~]# ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Aug11 ? 00:00:16 /usr/lib/systemd/systemd --switched-root --system --deserialize 17
root 2 0 0 Aug11 ? 00:00:00 [kthreadd]
root 3 2 0 Aug11 ? 00:00:00 [rcu_gp]
[root@moli ~]# ps -aux | more
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.5 177000 10864 ? Ss Aug11 0:16 /usr/lib/systemd/systemd --switched-root --system --d
eserialize 17
[root@moli ~]# ps -aux | grep nginx // -aux 显示所有进程,包括用户、分组情况
root 63499 0.0 0.0 12108 1072 pts/1 R+ 22:39 0:00 grep --color=auto nginx
VSZ: 虚拟内存使用量
RSS:固定内存使用量
TTY:终端
STAT:进程状态
START:启动时间
TIME:使用CPU时间
COMMAND:启动程序命令
kill:杀死进程
[root@moli ~]# kill -l // kill的所有信号
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
[root@moli ~]# kill -9 63505 // 杀死 PID 是63505的进程
// CTRL + C 相当于信号SIGINT
du: 统计大小
[root@moli home]# du -sm * // m是单位 *是通配符
0 ss
1 wrx
[root@moli ~]# du -sh // 不加通配符 计算的是总合
76K .
[root@moli ~]# du
4 ./.pip
4 ./.cache/pip/http/f/e/d/0/e
4 ./.cache/pip/http/f/e/d/0
4 ./.cache/pip/http/f/e/d
4 ./.cache/pip/http/f/e
4 ./.cache/pip/http/f
28 ./.cache/pip/http/b/b/8/7/6
28 ./.cache/pip/http/b/b/8/7
28 ./.cache/pip/http/b/b/8
28 ./.cache/pip/http/b/b
28 ./.cache/pip/http/b
32 ./.cache/pip/http
36 ./.cache/pip
36 ./.cache
0 ./.ssh
0 ./.config/procps
0 ./.config
76 .
firewall-cmd --state:查看防火墙状态
[root@moli ~]# firewall-cmd --state
not running
[root@moli ~]# systemctl start firewalld // 开启防火墙
阿里云服务器防火墙相关命令:https://www.cnblogs.com/yuanzipeng/p/10813494.html
cal: 查看日历
[root@moli ss]# cal
August 2020
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
[root@moli ss]# cal 2020
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31
Linux下输入输出错误重定向
1、输入重定向?
把输入的信息写入到指定的文件中去
2、输出重定向?
把要输出的信息写入到一个文件中去,而不是将要输出的文件信息输出到控制台(显示屏)
3、错误重定向?
把错误的信息写入到一个文件中去
Linux中一切皆为文件
文件描述符:
posix名称 文件描述符 用途
/dev/stdin 0 标准输入
/dev/stdout 1 标准输出
/dev/stderr 2 标准错误输出
输入重定向 <
[root@moli wrx]# wc -l < a.txt
2
输出重定向 > 覆盖 >> 追加
cat > a.txt
cat >> a.txt
[root@moli wrx]# grep 123 a.txt
123456
[root@moli wrx]# grep 123 a.txt >c.txt
[root@moli wrx]# cat c.txt
123456
[root@moli wrx]# grep 'd' a.txt >>c.txt
[root@moli wrx]# cat c.txt
123456
dfedgew
错误重定向:2不可以省
[root@moli wrx]# llll 2> d.txt
[root@moli wrx]# cat d.txt
-bash: llll: command not found
[root@moli wrx]# llll 2> /dev/null
[root@moli wrx]# cat /dev/null
[root@moli wrx]#
// /dev/null 无底洞 查看不到信息
几种符号
& 等同于
[root@moli wrx]# cat a.txt b.txt dd.txt 1> aa.txt 2>bb.txt
[root@moli wrx]# cat aa.txt
123456
dfedgew
123456
dsjhdbj
[root@moli wrx]# cat bb.txt
cat: dd.txt: No such file or directory
[root@moli wrx]# cat a.txt dd.txt 1> dd.txt 2>dd.txt
[root@moli wrx]# cat dd.txt
cat: dd.txt: input file is output file
[root@moli wrx]# cat a.txt dd.txt 1> dd.txt 2>&1
[root@moli wrx]# cat dd.txt
123456
dfedgew
cat: dd.txt: input file is output file
&> 不分正确和错误输出
[root@moli wrx]# cat a.txt dd.txt &>dd.txt
[root@moli wrx]# cat dd.txt
123456
dfedgew
cat: dd.txt: input file is output file
| 管道符:管道符左侧命令的输出就会作为管道符右侧命令的输入
[root@moli wrx]# cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
; 代表可以执行多条命令
[root@moli wrx]# cat dd.txt ; pwd
123456
dfedgew
cat: dd.txt: input file is output file
/home/wrx
&& 短路执行 第一个命令执行失败,后面的命令就不会执行了
[root@moli wrx]# 1111 && echo 123
-bash: 1111: command not found
|| 短路执行 第一个命令执行成功,后面的命令就不会执行了
[root@moli wrx]# 11111 || echo 123
-bash: 11111: command not found
123
上传命令 scp
E:>scp code-1.50.1-1602601064.el7.x86_64.rpm root@47.103.206.151:/usr/local
root@47.103.206.151's password:
code-1.50.1-1602601064.el7.x86_64.rpm 57% 51MB 824.8KB/s 00:46 ETA
压缩|解压文件 tar
[root@moli software]# tar -zxvf jdk-8u261-linux-x64.tar.gz // 解压文件 或者使用 tar -xf jdk-8u261-linux-x64.tar.gz
[root@moli software]# tar -zxvf jdk-8u261-linux-x64.tar.gz -C ./moli/ // 解压文件到moli文件夹下
[root@moli software]# tar -zcvf jdk-8u261-linux-x64.tar.gz 1.txt 2.txt // 压缩文件 -z 表示压缩为gz格式
文件编辑 vi | vim
[root@moli software]# vi demo.py
ESC模式下:
i :插入文本
:wq:保存文件
:q! :不保存文件
gg:跳转第一行首位
shift+g:跳转最后一行
$:跳转行尾
^:跳转行首
更新frofile
[root@moli software]# source /etc/profile
解压zip文件
[root@moli software]# unzip a.zip -d a
给文件授权
[root@moli software]# chmod + x ./test.sh // 使脚本具有执行权限
sed:流编辑器,一次处理一次内容,在模式里,原文件没有被改变
sed [-hn][-e<script>][-f<script FILE>][FILE]
-h // 显示帮助
-n // 仅显示script处理后的结果
-e<script> // 以选项中指定的script来处理输入的文本文件
-f<script FILE> // 以选项中指定的script文件来处理输入的文本文件
[FILE]
# 常用动作
a:新增 sed -e '4 a newline' // 在第四行后新增一行 # 没有 -e 也可以
c:取代 sed -e '2,5c No 2-5 number' // 使用c后面的内容取代2-5行的内容
d:删除 sed -e '2,5d' // 删除2-5行的内容
i:插入 sed -e '2i newline' // 在第二行前面插入一个newline # 没有 -e 也可以
p:打印 sed -n '/root/p'
s:取代 sed -e 's/old/new/g' // g表示全局 否则就是只替换每一行的第一个
# 实战:直接修改文件的内容
sed -i 's/root/echo/g' a.sh // 谨慎
# 使用 sed ' | f & ' 连接多个正则
# sed -E 's/(I Love you)/1a/g' b.txt // 在 I Love You 后添加一个字符 a
awk:把文件逐行的读入,以空格为默认分隔符将每片切片,切开的部分在进行后续处理
awk 'pattern + action' [FILE]
- pattern 正则表达式
- action 对匹配的内容执行命令(默认为输出每行内容)
# 常用参数
- FILENAME awk浏览的文件名
- BEGIN 处理文本之前要执行的操作
- END 处理文本之后要执行的操作
- FS 设置输入域分隔符,等价于命令行 -F 选项
- NF 浏览记录的域的个数(列数)
- NR 已读的记录数(行数)
- OFS 输出域分隔符
- ORE 输出记录分隔符
- RS 控制记录分隔符
- $0 整条记录
- $1 表示当前行的第一个域....以此类推
# 实践
# 搜索/etc/passwd有root关键字的所有行,并显示对应的shell
awk -F : '/root/{print $7}' /etc/passwd
# 打印/etc/passwd/的第二行信息
awk -F : 'NR==2{print $0}' /etc/passwd
# 使用begin加入标题,就是打印前输出一行
awk 'BEGIN {print "BEGIN", "BEGIN"}{print $1,$2}' /etc/passwd
# 自定义分隔符
echo "111 222|333 444|555 666" | awk 'BEGIN{RS="|"}{print $0}'
# awk '/正则或者表达式/action' 正则和action 可以省略其一 正则必须使用// 其他表达式可以不使用//
统计内存的使用 - shell
#! /bin/bash
for i in `ps aux | awk '{print $6}' | grep -v 'RSS'`;
do count=$[$count+$i];
done
echo "$count/kb"
curl:服务器传送发送命令
# curl is a tool to transfer data from or to a server
# 支持的协议: DICT、FILE、FTP、FTPS、GOPHER、HTTP、HTTPS、IMAP
# 没有用户交互
# -x 设置代理端口
curl -x 127.0.0.1:8888 https://www.baidu.com/
- get
- -G:使用get请求
- -d:指定请求的数据
- curl https://www.baidu.com/ 默认使用get请求
- curl -G https://www.baidu.com/
- curl -X GET https://www.baidu.com/ -X指定get请求
- post
- -d:指定post请求体
- curl -d ‘login=1234’ https://www.baidu.com/ 此时默认post请求
- curl -X POST https://www.baidu.com/ -X指定POST请求
- other
- -o 保存响应内容:curl -o tmp.html https://www.baidu.com/
- -v 输出通信的整个过程:curl -v https://www.baidu.com/
- -s 不输出错误和进程信息:curl -s https://www.baidu.com/
jq:json工具,安装命令,yum install jq
- jq:是一个json提取器,接受一个输入,生产一个输出
- 官网:https://stedolan.github.io/jq/
- 使用
- . 格式化:
echo '{"a":11, "b":12}' | jq '.'
- 内容提取:echo ‘{“foo”:42,“bar”:“less interesting data”}’ | jq ‘.foo’
- 从数组中提取单个数据:echo ‘[{“a”:1,“b”:2},{“c”:3,“d”:4}]’ | jq ‘.[0]’
- 从数组中提取单个数据:echo ‘[{“a”:1,“b”:2},{“c”:3,“d”:4}]’ | jq ‘.[-1]’
- 从数组中提取所有数据:echo ‘[{“a”:1,“b”:2},{“c”:3,“d”:4}]’ | jq ‘.[]’
- 从数组中过滤多个数据:echo ‘[{“a”:1,“b”:2},{“c”:3,“d”:4}]’ | jq ‘.[0,1]’
- 数据重组成数组:echo ‘{“a”:1,“b”:2,“c”:3,“d”:4}’ | jq ‘[.a,.b]’
- 数据重组成对象:echo ‘{“a”:1,“b”:2,“c”:3,“d”:4}’ | jq ‘{“tmp”:.b, “f1”: .d}’
- 和grep连用:echo ‘{“a”:1,“b”:2,“c”:3,“d”:4}’ | jq ‘{“tmp”:.b, “f1”: .d}’ | grep f
systemctl:启动命令 systemctl
systemctl restart nginx // 重启服务
查看监听的本地端口 ss
# 查看本地监听的端口
[root@moli conf.d]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:8888 0.0.0.0:*
LISTEN 0 128 0.0.0.0:5355 0.0.0.0:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 *:8080 *:*
LISTEN 0 128 *:50000 *:*
LISTEN 0 128 *:8086 *:*
LISTEN 0 128 *:3000 *:*
LISTEN 0 128 [::]:5355 [::]:*
最后
以上就是健忘大树为你收集整理的linux常用命令(一)的全部内容,希望文章能够帮你解决linux常用命令(一)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复