Linux 常用命令

目录

1)du  显示文件或目录占用的磁盘空间大小

2)df  查看文件系统的磁盘空间使用情况

3)netstat  查看端口占用情况

4)lsof  列出被进程打开的文件信息

5)timeout  控制程序运行的时间

6)date 系统时间

7)hwclock 硬件时钟

 8)压缩及解压缩

9)使用命令行一次性复制文件到多个路径下

10){ } 的用法

11)更改dns服务器地址

12)centos 7 查看开机启动项


1)du  显示文件或目录占用的磁盘空间大小

[root@Python ~]# du -h
# 显示该目录下所有目录(包含子目录及子子目录)占用磁盘空间的大小,最后一行统计当前目录所占磁盘空间大小
[root@Python ~]# du -sh
362M	.
# 只统计当前目录占用磁盘空间大小
[root@Python ~]# du -h --max-depth=1
[root@Python ~]# du -h -d 1
193M	./Python-3.7.0
26M	./nginx-1.14.2
362M	.

# 只显示当前目录下的一级目录所占用的磁盘空间大小

2)df  查看文件系统的磁盘空间使用情况

[root@Python ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   17G  5.1G   12G   30% /
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.1M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/sda1               1014M  190M  825M   19% /boot
tmpfs                     98M     0   98M    0% /run/user/0

[root@Python ~]# df -ah

[root@Python ~]# df -hT

3)netstat  查看端口占用情况

[root@Python ~]# netstat -tulnp

4)lsof  列出被进程打开的文件信息

[root@Python ~]# lsof -i:80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   17535  root    6u  IPv4  54228      0t0  TCP *:http (LISTEN)
nginx   17536 nginx    6u  IPv4  54228      0t0  TCP *:http (LISTEN)
# 查询占用某个端口的进程
[root@Python ~]# lsof /usr/sbin/nginx
COMMAND   PID  USER  FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   17535  root txt    REG  253,0  1311736  917 /usr/sbin/nginx
nginx   17536 nginx txt    REG  253,0  1311736  917 /usr/sbin/nginx
# 查询某个文件被那个进程开启的
[root@Python ~]# lsof -c nginx
# 显示某个程序打开的文件信息
[root@Python ~]# lsof -p 17536
# 显示某个进程号打开的文件信息

5)timeout  控制程序运行的时间

      timeout n[s,m,h,d] command

运行指定的命令,如果在指定时间后仍在运行,则杀死该进程,[s,m,h,d]省略时,默认为s秒,

[root@syztoo ~]# timeout 5 ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=52 time=7.95 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=52 time=7.96 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=52 time=7.93 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=52 time=7.90 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=52 time=7.94 ms
[root@syztoo ~]# 

6)date 系统时间

[root@syztoo ~]# date -s "2019-04-15 17:12:00"
# 设置系统时间
[root@syztoo ~]# date +%F
2019-04-15
[root@syztoo ~]# date +%Y%m%d
20190415
# 查看当前年月日
[root@syztoo ~]# date +%T  
17:13:25
[root@syztoo ~]# date +%H%M%S
171334
# 查看当前时分秒
[root@syztoo ~]# date -d "yesterday" +%F
2019-04-14
[root@syztoo ~]# date -d "tomorrow" +%F 
2019-04-16
[root@syztoo ~]# date -d "-2 days" +%F  
2019-04-13
[root@syztoo ~]# date -d "+2 days" +%F        
2019-04-17
[root@syztoo ~]# date -d "5 days ago" +%F             
2019-04-10
[root@syztoo ~]# date -d "1 years ago" +%F    
2018-04-15
# 获取过去和未来某天的日期

7)hwclock 硬件时钟

[root@syztoo ~]# hwclock
Fri 24 May 2019 05:21:07 PM CST  -0.734875 seconds
# 查看硬件时钟
[root@syztoo ~]# hwclock -w
# 将系统时间同步到硬件时钟

 8)压缩及解压缩

1、gzip   **仅对文件,可一次性指定多个文件,然后分别压缩或解压**

[root@syztoo syztoo]# gzip syztoo.log
[root@syztoo syztoo]# gzip -d syztoo.log.gz
[root@syztoo syztoo]# gunzip syztoo.log.gz

2、bzip2  **仅对文件,可一次性指定多个文件,然后分别压缩或解压**

[root@syztoo syztoo]# bzip2 syztoo.log
[root@syztoo syztoo]# bzip2 -d syztoo.log.bz2
[root@syztoo syztoo]# bunzip2 syztoo.log.bz2

3、zip     **可对目录,linux下默认未安装zip解压缩工具,推荐使用gzip和bzip2**

压缩:zip filename.zip dirname
解压:unzip filename.zip

4、tar 打包

tar -cvf examples.tar files|dir
tar -xvf examples.tar (解压至当前目录下)
tar -xvf examples.tar  -C /path (/path 解压至其它路径)

5、tar 打包并压缩

tar -zcvf file.tar.gz dir
tar -zcvf file.tar.gz file1 file2 ...
tar -zxvf file.tar.gz
tar -zxvf file.tar.gz -C /dir

tar -jcvf file.tar.bz2 dir
tar -jcvf file.tar.bz2 file1 file2 ...
tar -jxvf file.tar.bz2
tar -jxvf file.tar.bz2 -C /dir

9)使用命令行一次性复制文件到多个路径下

[root@syztoo ~]# echo /usr/local/redis-cluster/{7001,7002,7003,7004,7005,7006} | xargs -n 1 cp -v /usr/local/redis/bin/*

10){ } 的用法

{ } 可以用作命令展开及替换

[root@master1 ~]# touch ./{test1,test2}
[root@master1 ~]# ls
test1  test2
[root@master1 ~]# cp test1{,.txt} 
[root@master1 ~]# mv test2{,.txt}
[root@master1 ~]# ls
test1  test1.txt  test2.txt

11)更改dns服务器地址

[root@master1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.3.1

12)centos 7 查看开机启动项

systemctl list-unit-files

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值