Linux Tools Quick Tutorial
Linux基础
原文地址在上面,此处是我复习Linux 命令的.
Linux 基础 帮助命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [root@caoxl ~] ls (1 ) - list directory contents[root@caoxl ~] ... [root@caoxl ~] ... [root@caoxl ~] ... [root@caoxl ~] alias ls='ls --color=auto' /usr/bin/ls [root@caoxl ~] ls: /usr/bin/ls /usr/share/man/man1/ls.1 .gz
总结 whatis
info
man
which
whereis
文件及目录管理 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 [root@caoxl ~] [root@caoxl ~] [root@caoxl dir] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] /root [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] 1 .log 2 .log 3 .log[root@caoxl ~] rm: remove regular empty file ‘1 .log’? y rm: remove regular empty file ‘2 .log’? y rm: remove regular empty file ‘3 .log’? y [root@caoxl ~] [root@caoxl dir] 4 [root@caoxl ~] ./dir2: directory ./dir2/dir: directory ./dir: directory [root@caoxl ~] ./dir/2 .log ./dir/1 .log ./dir/3 .log [root@caoxl dir] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] total 0 -rw-r--r-- 1 root root 0 May 6 11 :28 test.php [root@caoxl ~] [root@caoxl ~] total 0 -rw-r--r-- 1 www www 0 May 6 11 :28 test.php [root@caoxl ~] [root@caoxl ~] total 0 -rwxr-xr-x 1 www www 0 May 6 11 :28 test.php [root@caoxl ~] [root@caoxl ~] total 0 -rwxrwxrwx 1 www www 0 May 6 11 :28 test.php [root@caoxl ~] adm crash empty gopher lib lock mail opt run tmp yp cache db games kerberos local log nis preserve spool www suss! [root@caoxl ~] <?php echo 1024 ;[root@caoxl ~] [root@caoxl ~] <?php echo 1024 ;hello [root@caoxl ~] 1
总结 文件管理,目录的创建、删除、查询、管理: mkdir
rm
mv
cp
文件的查询和检索: find
locate
查看文件内容: cat
vi
head
tail
more
diff
文件所有者、权限: chown
chmod
**管道和重定向: |
&&
>
**
文本处理
1 2 [root@caoxl ~] root 1437 32022 0 14 :44 pts/1 00 :00 :00 grep --color=auto mysql
1 2 [root@caoxl ~] <?php echo 1024 ; hello
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@caoxl ~] <?php echo 1024 ;hello hello [root@caoxl ~] echo 1024 ;hello <?php [root@caoxl ~] hello
1 2 3 4 5 6 7 8 9 10 11 [root@caoxl ~] 5 test.php[root@caoxl ~] 5 test.php[root@caoxl ~] 30 test.php
总结 find
grep
xargs
sort
uniq
wc
磁盘管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [root@caoxl ~] Filesystem Size Used Avail Use% Mounted on /dev/vda1 40 G 7.7 G 30 G 21 % / devtmpfs 1.9 G 0 1.9 G 0 % /dev tmpfs 1.9 G 0 1.9 G 0 % /dev/shm tmpfs 1.9 G 488 K 1.9 G 1 % /run tmpfs 1.9 G 0 1.9 G 0 % /sys/fs/cgroup tmpfs 379 M 0 379 M 0 % /run/user/0 [root@caoxl ~] Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 40 G 7.7 G 30 G 21 % / devtmpfs devtmpfs 1.9 G 0 1.9 G 0 % /dev tmpfs tmpfs 1.9 G 0 1.9 G 0 % /dev/shm tmpfs tmpfs 1.9 G 488 K 1.9 G 1 % /run tmpfs tmpfs 1.9 G 0 1.9 G 0 % /sys/fs/cgroup tmpfs tmpfs 379 M 0 379 M 0 % /run/user/0 [root@caoxl ~] 8.0 K test
-h: human缩写,以易读的方式显示结果(即带单位:比如M/G,如果不加这个参数,显示的数字以B为单位) -s 递归整个目录的大小
1 2 3 4 5 6 7 8 9 10 11 [root@caoxl test] [root@caoxl test] [root@caoxl test] [root@caoxl test]
总结 查看磁盘空间: df -Th
查看目录大小: du -sh
打包/解包&&压缩/解压缩: tar -cvf
tar -xvf
gzip
gunzip
bzip
进程管理 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 $ 查询进程 [root@caoxl ~] root 900 1 0 Jan28 ? 00 :05 :12 php-fpm: master process (/usr/local/php/php56/etc/php-fpm.conf) www 903 900 0 Jan28 ? 00 :00 :00 php-fpm: pool www www 904 900 0 Jan28 ? 00 :00 :00 php-fpm: pool www root 2936 32022 0 15 :14 pts/1 00 :00 :00 grep --color=auto php [root@caoxl ~] 2563 sshd19320 sshd32019 sshd[root@caoxl ~] PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 0 1 1 1 ? -1 Ss 0 7 :30 /usr/lib/systemd/systemd --swit 0 2 0 0 ? -1 S 0 0 :00 [kthreadd] 2 3 0 0 ? -1 S 0 0 :05 [ksoftirqd/0 ] 2 5 0 0 ? -1 S< 0 0 :00 [kworker/0 :0 H] 2 7 0 0 ? -1 S 0 0 :07 [migration/0 ] [root@caoxl ~] top - 15 :20 :40 up 98 days, 4 :24 , 2 users, load average: 0.00 , 0.01 , 0.05 Tasks: 81 total, 1 running, 80 sleeping, 0 stopped, 0 zombie %Cpu (s): 0.2 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3880936 total, 2290276 free, 178560 used, 1412100 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 3397572 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 51728 3484 2192 S 0.0 0.1 7 :30.73 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0 :00.05 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0 :05.38 ksoftirqd/0 [root@caoxl ~] COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 3947 mysql 21 u IPv6 2088379 0 t0 TCP *:mysql (LISTEN) [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] root 4325 32022 0 15 :37 pts/1 00 :00 :00 grep --color=auto redis [root@caoxl ~] 32022 : -bash0000000000400000 884 K r-x-- bash00000000006 dd000 4 K r---- bash00000000006 de000 36 K rw--- bash00000000006e7000 24 K rw--- [ anon ]000000000110e000 2576 K rw--- [ anon ]...
总结 ps
top
lsof
kill
pmap
性能监控 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 [root@caoxl ~] Linux 3.10 .0 -862.14 .4 .el7.x86_64 (caoxl) 05 /06 /2019 _x86_64_ (2 CPU) 12 :00 :01 AM CPU %user %nice %system %iowait %steal %idle12 :10 :01 AM all 0.01 0.00 0.01 0.00 0.00 99.97 12 :20 :01 AM all 0.01 0.02 0.01 0.00 0.00 99.95 12 :30 :01 AM all 0.01 0.00 0.01 0.00 0.00 99.98 [root@caoxl ~] Linux 3.10 .0 -862.14 .4 .el7.x86_64 (caoxl) 05 /06 /2019 _x86_64_ (2 CPU) 03 :40 :06 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked03 :40 :07 PM 0 126 0.00 0.01 0.05 0 03 :40 :08 PM 0 126 0.00 0.01 0.05 0 Average: 0 126 0.00 0.01 0.05 0 [root@caoxl ~] Linux 3.10 .0 -862.14 .4 .el7.x86_64 (caoxl) 05 /06 /2019 _x86_64_ (2 CPU) 03 :42 :14 PM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty03 :42 :15 PM 2192724 1688212 43.50 334600 702232 1055296 17.65 726812 530364 0 03 :42 :16 PM 2192724 1688212 43.50 334600 702232 1055296 17.65 726812 530364 0 Average: 2192724 1688212 43.50 334600 702232 1055296 17.65 726812 530364 0 [root@caoxl ~] total used free shared buff/cache available Mem: 3789 263 2141 0 1384 3228 Swap: 2047 0 2047 [root@caoxl ~] Linux 3.10 .0 -862.14 .4 .el7.x86_64 (caoxl) 05 /06 /2019 _x86_64_ (2 CPU) 03 :44 :38 PM pswpin/s pswpout/s03 :44 :39 PM 0.00 0.00 03 :44 :40 PM 0.00 0.00 03 :44 :41 PM 0.00 0.00 Average: 0.00 0.00 [root@caoxl ~] Filesystem Size Used Avail Use% Mounted on /dev/vda1 40 G 7.8 G 30 G 21 % / devtmpfs 1.9 G 0 1.9 G 0 % /dev tmpfs 1.9 G 0 1.9 G 0 % /dev/shm tmpfs 1.9 G 488 K 1.9 G 1 % /run tmpfs 1.9 G 0 1.9 G 0 % /sys/fs/cgroup tmpfs 379 M 0 379 M 0 % /run/user/0 [root@caoxl ~] procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 2192772 334600 1083488 0 0 0 4 2 1 2 1 98 0 0 0 0 0 2192748 334600 1083520 0 0 0 0 91 87 0 0 100 0 0 0 0 0 2192748 334600 1083520 0 0 0 0 88 90 0 0 100 0 0 [root@caoxl ~]
总结 sar
top
free
df -h
watch
网络工具 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 32 33 34 35 36 [root@caoxl ~] Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhos:x11-ssh-offset 0.0 .0.0 :* LISTEN ... [root@caoxl ~] tcp6 0 0 :::3306 :::* LISTEN 3947 /mysqld [root@caoxl ~] Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0 .0.0 172.18 .63.253 0.0 .0.0 UG 0 0 0 eth0169.254 .0.0 0.0 .0.0 255.255 .0.0 U 1002 0 0 eth0172.18 .48.0 0.0 .0.0 255.255 .240.0 U 0 0 0 eth0[root@caoxl ~] --2019 -05 -06 15 :56 :44 -- http: Resolving caoxl.com (caoxl.com)... 47.107 .169.233 Connecting to caoxl.com (caoxl.com)|47.107 .169.233 |:80 ... connected. HTTP request sent, awaiting response... 200 OK ... [root@caoxl ~] [root@caoxl ~] [root@caoxl ~]
总结 netstat
lsof
route
ping
wget
ssh
sftp
scp
用户管理工具
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [root@caoxl ~] [root@caoxl ~] Changing password for user caoxl. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@caoxl ~] [root@caoxl ~] su: user caoxl does not exist
1 2 3 4 5 [root@caoxl ~] [root@caoxl ~]
字母方式
1 chmod userMark (+|-)PermissionsMark
userMark取值:
u
: 用户
g
: 组
o
: 其它用户
a
: 所有用户
PermissionsMark取值:
1 2 3 4 5 6 7 8 9 10 [root@caoxl ~] total 0 -rw-r--r-- 1 root root 0 May 6 16 :07 test1.php -rw-r--r-- 1 root root 0 May 6 16 :07 test2.php [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] total 0 -rwxr-xr-x 1 root root 0 May 6 16 :07 test1.php -rw-rw-r-- 1 root root 0 May 6 16 :07 test2.php
数字方式
使用三位八进制数字的形式来表示权限,第一位指定属主的权限,第二位指定组权限,第三位指定其他用户的权限,每位通过4(读)、2(写)、1(执行)三种数值的和来确定权限。如6(4+2)代表有读写权,7(4+2+1)有读、写和执行的权限。
1 2 3 4 5 [root@caoxl ~] [root@caoxl ~] total 0 -rwxr-xr-x 1 root root 0 May 6 16 :07 test1.php -rwxrwxrwx 1 root root 0 May 6 16 :07 test2.php
1 2 3 4 5 6 [root@caoxl ~] [root@caoxl ~] [root@caoxl ~] total 0 -rwxr-xr-x 1 www root 0 May 6 16 :07 test1.php -rwxrwxrwx 1 www root 0 May 6 16 :07 test2.php
总结 useradd
passwd
userdel
usermod
chmod
chown
系统管理及IPC资源管理 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 32 33 34 35 36 37 38 39 40 41 42 43 44 [root@caoxl ~] Linux caoxl 3.10 .0 -862.14 .4 .el7.x86_64 [root@caoxl ~] LSB Version: :core-4.1 -amd64:core-4.1 -noarch Distributor ID: CentOS Description: CentOS Linux release 7.5 .1804 (Core) Release: 7.5 .1804 Codename: Core [root@caoxl ~] [root@caoxl ~] 2 [root@caoxl ~] MemTotal: 3880936 kB MemFree: 2194292 kB MemAvailable: 3311360 kB ... [root@caoxl ~] x86_64 [root@caoxl ~] Mon May 6 16 :17 :04 CST 2019 [root@caoxl ~] ------ Message Queues -------- key msqid owner perms used-bytes messages ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status ------ Semaphore Arrays -------- key semid owner perms nsems
总结 uname
sar
arch
date
ipcs
Linux 工具进阶 程序调试 程序优化 Linux 工具参考篇
gdb
调试利器
ldd
查看程序依赖库
lsof
一切皆文件
ps
进程查看其
pstack
跟踪进程栈
strace
跟踪进程中的系统调用
ipcs
查询进程间通信状态
top
linux下的任务管理器
free
查询可用内存
vmstat
监视内存使用情况
iostat
监视I/O子系统
sar
找出系统瓶颈的利器
readelf elf
文件格式分析
objdump
二进制文件分析
nm
目标文件格式分析
size
查看程序内存映象大小
wget
文件下载
scp
跨机远程拷贝
crontab
定时任务