您的位置:首页 > 运维架构 > Linux

Linux命令总结

2016-04-24 21:46 357 查看
Linux常用命令总结

目录和文件基本操作
Pwd 查看当前所在目录
[root@localhost html]# pwd
/application/nginx/html
[root@localhost html]# pwd –P 查看链接的目录
/application/nginx-1.8.0/html

cd 切换目录
[root@localhost html]# cd /usr/src/ 切换到/usr/src/目录
[root@localhost src]# cd .. 切换上一级目录
[root@localhost usr]# cd - 切换/usr/src目录
/usr/src

touch创建文件
[root@localhost ~]# touch xiaohu
mkdir 创建目录
[root@localhost ~]# mkdir qiqi

cp 复制
[root@localhost ~]# cp -r xiaohu/ /etc/ -r代表递归一般复制目录需要加上

rm 删除文件或目录
[root@localhost ~]# rm 1.txt
rm:是否删除普通空文件 "1.txt"?y
[root@localhost ~]# rm -rf xiaohu/ 删除目录且不提示

mv移动重命名 文件或者目录
[root@localhost ~]# mv qiqi/ qq

find 查找文件 他可以按时间,大小名字用户查找
[root@localhost ~]# find -name dan.sh 按名字
./dan.sh
[root@localhost ~]# find /root/ "*.log" 查找root目录下以log结尾的文件

[root@localhost ~]# find ./ -size +10M 查找当前目录下大于10M的文件
./mysql-5.5.32-linux2.6-x86_64.tar.gz
./mysql-cluster-gpl-7.4.6-linux-glibc2.5-i686.tar.gz

du计算文件或目录的容量

[root@localhost ~]# du -h /root/ 人性化显示
12K/root/.ssh
4.0K/root/qq
639M/root/
[root@localhost ~]# du -s /root/ 只显示当前目录的容量
654028/root/
[root@localhost ~]# du -sh /root/ 查看当前目录的容量总和
639M/root/

Cat 查看文件的内容
[root@localhost ~]# cat /etc/inittab
[root@localhost ~]# cat -n /etc/inittab 显示行号,包括空白行
[root@localhost ~]# cat -b /etc/inittab 显示行号,不包括空白行

head 默认查看文件前10行
[root@localhost ~]# head /etc/init.d/mysqld 显示前10行默认
[root@localhost ~]# head -11 /etc/init.d/mysqld head –n可以显示前多少航都可以
head -c 11k /etc/init.d/mysqld 查看文件前11k的内容

tail命令 默认查看默认10行
[root@localhost ~]# tail /etc/init.d/mysqld 显示默认10行内容
[root@localhost ~]# tail -11 /etc/init.d/mysqld 末尾几行都可以可以变
[root@localhost ~]# tail -c 11k /etc/init.d/mysqld 查看末尾11k的内容

wc 显示文件的行,单词和字节的统计信息
[root@localhost ~]# wc -l /etc/init.d/mysqld 显示行数
390 /etc/init.d/mysqld
[root@localhost ~]# wc -c /etc/init.d/mysqld 字节统计
10892 /etc/init.d/mysqld
[root@localhost ~]# wc -w /etc/init.d/mysqld 单词统计
1381 /etc/init.d/mysqld

grep 查找关键字并打印匹配的行数
[root@localhost ~]# grep e /etc/init.d/mysqld 查看文件包含e的行
[root@localhost ~]# grep --color e /etc/init.d/mysqld 匹配的字符显示颜色
[root@localhost ~]# grep -i e /etc/init.d/mysqld 查看e的行不区分大小写
[root@localhost ~]# grep -v e /etc/init.d/mysqld 过滤不包含e的行 取反

存储管理命令常用
查看磁盘分区
[root@localhost ~]# fdisk -cul

Disk /dev/sda: 21.5 GB, 21474836480 bytes 第一块21.5G两个分区

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
第二块和第3块没分区
Disk /dev/dm-0: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders, total 36847616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

性能监控命令
监控cpu使用情况命令uptime
[root@localhost ~]# uptime
22:33:54 up 1:40, 2 users, load average: 0.00, 0.00, 0.00
从上面可以看出是在22.00登录两个用户 3个0.00 代表cpu从最近1分钟5分钟15分钟的负载情况,这里进程为0 代表cpu很闲,如果进程个数越多,说明cpu越忙

监控内存及交换分区情况 free
[lubaoxin@AY131218153639958171Z ~]$ free
total used free shared buffers cached
Mem: 1018804 947528 71276 0 188340 463988
-/+ buffers/cache: 295200 723604
Swap: 2106264 35440 2070824

第一行代表内存total代表总容量服务器启动的时候内存会自动划分内存给buffers cached作为进程使用,userd指的是buffer和cached 划分的内存容量,buffers代表buffer剩余容量,cached代表cached剩余容量
第二行代表buffer和cache used代表使用的容量,free代表划分给buffer剩余的容量
第3行代表交换分区使用情况total代表总容量userd代表使用的容量free代表剩余容量

监控磁盘使用情况df
-h 人性化显示容量信息
-T 显示文件类型
-i 显示磁盘inode使用信息
磁盘inode : 里面存储除了文件名字和大小的信息都会储存在inode里面,比如文字字节数,文件拥有者ID ,文件读写权限
df –hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvda1 ext4 20G 11G 7.7G 59% /
tmpfs tmpfs 498M 0 498M 0% /dev/shm
/dev/xvdb2 ext4 48G 7.7G 38G 18% /dataspace
Xvda分区文件类型ext4 总共20G 已使用11G 剩余7.7,使用率59% 挂在根目录下

[root@AY131218153639958171Z ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/xvda1 1310720 229052 1081668 18% /
tmpfs 127350 1 127349 1% /dev/shm
/dev/xvdb2 3145728 906 3144822 1% /dataspace

根目录下的inode有1310720个,使用了2229052,剩下1081668个,使用了百分之18

这里的inode节点代表该分区可以创建的文件个数,有多少个inode节点,就可以创建多少文件

监控网络情况命令
Ifconfig查看网络ip地址

netstat 打印网络连接路由表网络接口统计的信息
[root@AY131218153639958171Z ~]# netstat -nlp
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:80 0.0.0.0:* LISTEN 611/httpd
tcp 0 0 0.0.0.0:3699 0.0.0.0:* LISTEN 2463/svnserve

监控进程使用命令

Ps命令
ps –e 查看进程信息
ps –ef 全格式进程信息

[root@localhost ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Apr17 ? 00:00:01 /sbin/init
root 2 0 0 Apr17 ? 00:00:00 [kthreadd]
root 3 2 0 Apr17 ? 00:00:00 [migration/0]
root 4 2 0 Apr17 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 Apr17 ? 00:00:00 [watchdog/0]
root 6 2 0 Apr17 ? 00:00:00 [events/0]
[root@localhost ~]# ps -axu
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 19244 1428 ? Ss Apr17 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S Apr17 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Apr17 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S Apr17 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S Apr17 0:00 [watchdog/0]
root 6 0.0 0.0 0 0 ? S Apr17 0:00 [events/0]
root 7 0.0 0.0 0 0 ? S Apr17 0:00 [cpuset]
root 8 0.0 0.0 0 0 ? S Apr17 0:00 [khelper]
UID代表执行用户,PID代表唯一编号,PPID代表父进程编号,%cpu代表进程cpu占用率,%mem代表内存占用率,VSZ代表进程占用的虚拟内存大小,RSS代表进程占用真实内存大小

Top
动态查看进程信息 选项-d 刷新时间间隔默认3秒
-p 查看指定pid进程信息
[root@localhost ~]# top -d 1
top - 01:11:22 up 4:18, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 92 total, 1 running, 90 sleeping, 1 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1013496k total, 454020k used, 559476k free, 135004k buffers
Swap: 2031608k total, 0k used, 2031608k free, 94140k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2365 root 20 0 97440 3680 2852 S 0.3 0.4 0:01.44 sshd
1 root 20 0 19244 1428 1156 S 0.0 0.1 0:01.44 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
6 root 20 0 0 0 0 S 0.0 0.0 0:00.16 events/0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 命令总结