linux基础命令篇四

1.df报告系统磁盘空间的使用情况

df -h人类易读

[root@andy ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 17G 2.0G 16G 12% /
devtmpfs 902M 0 902M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.7M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 183M 0 183M 0% /run/user/0

2.free显示系统中已用和未用的空间总和

free -m以m为单位

[root@andy ~]# free -m
total used free shared buff/cache available
Mem: 1823 118 1509 8 195 1529
Swap: 2047 0 2047

free -h人类易读

[root@andy ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 118M 1.5G 9.0M 195M 1.5G
Swap: 2.0G 0B 2.0G

free -s(间隔秒数)持续观察内存使用情况

[root@andy ~]# free -h -s 3
total used free shared buff/cache available
Mem: 1.8G 118M 1.5G 9.0M 195M 1.5G
Swap: 2.0G 0B 2.0G

total used free shared buff/cache available
Mem: 1.8G 118M 1.5G 9.0M 195M 1.5G
Swap: 2.0G 0B 2.0G

^C

3.date打印、设置系统时间和日期

date -s设置系统时间

[root@andy ~]# date
2019年 10月 30日 星期三 18:43:04 CST
[root@andy ~]# date -s "2019-10-12 16:45"
2019年 10月 12日 星期六 16:45:00 CST
[root@andy ~]# date
2019年 10月 12日 星期六 16:45:03 CST

date“+%F %T”显示系统当前时间

[root@andy ~]# date "+%F %T"
2019-10-12 16:47:19

%F年 %m月 %d日  %H时 %M分 %S秒

[root@andy ~]# date "+%Y"
2019
[root@andy ~]# date "+%m"
10
[root@andy ~]# date "+%d"
12
[root@andy ~]# date "+%H"
17
[root@andy ~]# date "+%M"
04
[root@andy ~]# date "+%S"
14
[root@andy ~]# date "+%Y-%m-%d %H:%M:%S"
2019-10-12 17:05:13
[root@andy ~]# date
2019年 10月 12日 星期六 17:05:27 CST
[root@andy ~]#

clock -w强制把时间写入CMOS  

[root@andy ~]# date
2019年 10月 12日 星期六 17:05:27 CST
[root@andy ~]# clock
2019年10月30日 星期三 19时04分47秒 -0.813873 秒
[root@andy ~]# date
2019年 10月 12日 星期六 17:06:56 CST
[root@andy ~]# clock -w
[root@andy ~]# date
2019年 10月 12日 星期六 17:07:14 CST
[root@andy ~]# clock
2019年10月12日 星期六 17时07分18秒 -0.894695 秒
[root@andy ~]#

4.输出重定向

>:会覆盖掉原先文件的内容

[root@andy ~]# cat test
hello
hello
hello
hello
[root@andy ~]# echo "Hi">test
[root@andy ~]# cat test
Hi

>>:追加输出不会覆盖掉原始文件内容,会在原始文件内容末尾继续添加

[root@andy ~]# cat test
Hi
[root@andy ~]# echo "hello">>test
[root@andy ~]# cat test
Hi
hello
[root@andy ~]#

2>:错误输出,会覆盖掉原始文件内容

[root@andy ~]# cdg 2>test
[root@andy ~]# cat test
-bash: cdg: 未找到命令
[root@andy ~]#

2>>:错误追加输出,不会覆盖原始文件内容,会在原始文件后继续追加内容

[root@andy ~]# dfgs 2>>test
[root@andy ~]# cat test
-bash: cdg: 未找到命令
-bash: dfgs: 未找到命令
[root@andy ~]#

&>:将标准输出与错误输出共同写入到文件中,覆盖原有内容

[root@andy ~]# cat test
-bash: cdg: 未找到命令
-bash: dfgs: 未找到命令
[root@andy ~]# echo "hello" &>test
[root@andy ~]# cat test
hello
[root@andy ~]#

&>>:将标准输出与错误输出共同写入到文件中,(追加到原有文件的后边)

[root@andy ~]# cat test
-bash: sdfg: 未找到命令
[root@andy ~]# sdfg &>>test
[root@andy ~]# cat test
-bash: sdfg: 未找到命令
-bash: sdfg: 未找到命令
[root@andy ~]#

5.管道符 |  的作用是把前一个命令原本要输出到屏幕的标准正常数据当作时后一个命令的标准输入。

统计/etc/passwd中包含root的行数

[root@andy ~]# cat /etc/passwd | grep "root"|wc -l
2
[root@andy ~]#

6.通配符

星号(*)代表匹配零个或多个字符

[root@andy ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2
[root@andy ~]#

问号(?)代表匹配单个字符,单个字符必须存在

[root@andy ~]# ls /dev/sd?
/dev/sda

[root@andy ~]# ls /dev/sd??
/dev/sda1 /dev/sda2

中括号内加上数字[0-9]代表匹配0~9之间的单个数字的字符

[root@andy ~]# ls /dev/sda[0-9]
/dev/sda1 /dev/sda2
[root@andy ~]#

中括号内加上abc则是代表匹配a、b、c三个字符中的任意一个字符。

[root@andy ~]# ls /dev/sd[a-z]
/dev/sda

7.三种引号的作用

单引号(''):转义其中所有的变量为单纯的字符串

双引号(""):保留其中的变量属性不进行转义处理

反引号(``):把其中的命令执行后返回结果

8.软链接硬链接

软链接就相当于windows下面的快捷方式

[root@andy text]# ln -s /root/andy andy2
[root@andy text]# ls -l
总用量 0
-rw-r--r-- 2 root root 0 10月 12 20:26 andy1
lrwxrwxrwx 1 root root 10 10月 12 20:28 andy2 -> /root/andy

硬链接相当于复制黏贴,但是修改源文件中的内容,硬链接中的内容也会跟着改变,修改硬连接内容,源文件也会跟着改变

root@andy text]# ln /root/andy andy1
[root@andy text]# ls
andy1
[root@andy text]# ls -l
总用量 0
-rw-r--r-- 2 root root 0 10月 12 20:26 andy1

创建完成后,源文件,软硬链接均可以查看到文件内容。编辑源文件,软硬链接跟着动。

删除源文件,软链接失效,硬链接无影响,在创建一个与源文件同名的文件,软连接就直接链接到新的文件,而硬链接不改变。因为软连接是按照名称进行链接的

原文地址:https://www.cnblogs.com/yzandy/p/11768434.html