Linux显示操作类命令
1、显示系统信息命令
1、(1)who:查看用户登录信息。
[root@ll ~]# who
root seat0 2024-07-25 14:27 (login screen)
root tty2 2024-07-25 14:27 (tty2)
root pts/0 2024-07-25 14:27 (192.168.75.1)
[root@ll ~]#
(2)who -a: who -a:显示所有用户信息
[root@ll ~]# who -a
系统引导 2024-07-25 14:26
运行级别 5 2024-07-25 14:27
root ? seat0 2024-07-25 14:27 ? 2283 (login screen)
root + tty2 2024-07-25 14:27 04:36 2283 (tty2)
root + pts/0 2024-07-25 14:27 . 2511 (192.168.75.1)
[root@ll ~]#
2、whoami:显示当前操作用户
[root@ll ~]# whoami
root
[root@ll ~]#
3、(1)hostname 主机名:临时修改主机名,重启之后打开会话会失效
[root@ll ~]# hostname luo
[root@ll ~]# bash
[root@luo ~]#
(2)、hostnamectl set-hostname 主机名:永久修改主机名,重启之后打开会话依旧有效。
root@ll ~]# hostnamectl set-hostname luo
[root@ll ~]# bash
[root@luo ~]#
4、(1)date:显示当前时间\日期
[root@luo ~]# date
2024年 07月 25日 星期四 19:15:28 CST
[root@luo ~]#
(2)、date +“%Y-%m-%d %H:%M:%S”(2024-07-23 14:30:50):以格式化的形势输出
[root@luo ~]# date +"%Y-%m-%d %H:%M:%S"
2024-07-25 19:16:03
[root@luo ~]#
(3)date -s “2000-01-01 10:10:10”:更改时间为2000年一月一号,10点10分10秒
[root@luo ~]# date -s"2000-01-01 10:10:10"
2000年 01月 01日 星期六 10:10:10 CST
[root@luo ~]#
5、(1)cal:显示日历
[root@luo ~]# cal
一月 2000
一 二 三 四 五 六 日
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@luo ~]#
(2)cal 年份:显示指定年份日历
[root@luo ~]# cal 2024
2024
一月 二月 三月
一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六 日
1 2 3 4 5 6 7 1 2 3 4 1 2 3
8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10
15 16 17 18 19 20 21 12 13 14 15 16 17 18 11 12 13 14 15 16 17
22 23 24 25 26 27 28 19 20 21 22 23 24 25 18 19 20 21 22 23 24
29 30 31 26 27 28 29 25 26 27 28 29 30 31
四月 五月 六月
一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六 日
1 2 3 4 5 6 7 1 2 3 4 5 1 2
8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9
15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23
29 30 27 28 29 30 31 24 25 26 27 28 29 30
七月 八月 九月
一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六 日
1 2 3 4 5 6 7 1 2 3 4 1
8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8
15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15
22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22
29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29
30
十月 十一月 十二月
一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六 日
1 2 3 4 5 6 1 2 3 1
7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
30 31
[root@luo ~]#
6、clear:清除屏幕(快捷键CTRL+l)
2、文件及目录显示类命令
1、pwd:显示当前工作目录
[root@luo ~]# pwd
/root
[root@luo ~]#
2、(1)显示当前工作目录
[root@luo ~]# pwd
/root
[root@luo ~]#
(2)、cd ~:表示当前用户的工作目录
[root@luo etc]# cd ~
[root@luo ~]#
(3)cd ~用户名:表示切换到指定用户的主目录
[root@luo ~]# cd ~ll
[root@luo ll]#
(4)cd . :代表当目录
[root@luo ~]# cd .
[root@luo ~]#
(5)cd … :代表父级目录
[root@luo ~]# cd /etc/path
[root@luo path]# cd ..
[root@luo etc]#
(6)cd -:代表上次所在目录
[root@luo etc]# cd
[root@luo ~]# cd -
/etc
[root@luo etc]#
3、(1)ls:显示当前目录
[root@luo ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg
[root@luo ~]#
(2)、ls -l : 以长格式显示文件的详细信息
[root@luo ~]# ls -l
总用量 4
drwxr-xr-x. 2 root root 6 7月 19 2024 公共
drwxr-xr-x. 2 root root 6 7月 19 2024 模板
drwxr-xr-x. 2 root root 6 7月 19 2024 视频
drwxr-xr-x. 2 root root 6 7月 19 2024 图片
drwxr-xr-x. 2 root root 6 7月 19 2024 文档
drwxr-xr-x. 2 root root 6 7月 19 2024 下载
drwxr-xr-x. 2 root root 6 7月 19 2024 音乐
drwxr-xr-x. 2 root root 6 7月 19 2024 桌面
-rw-------. 1 root root 1018 7月 19 2024 anaconda-ks.cfg
[root@luo ~]#
(3)ls -a :列出当前所有内容,包括隐藏文件的信息
[root@luo ~]# ls -a
. 公共 视频 文档 音乐 anaconda-ks.cfg .bash_logout .bashrc .config .lesshst .ssh
.. 模板 图片 下载 桌面 .bash_history .bash_profile .cache .cshrc .local .tcshrc
[root@luo ~]#
(4)ls -d:指定查看目录
[root@luo ~]# ls -d test
test
[root@luo ~]#
4、stat:显示文件或文件系统状态信息
[root@luo ~]# stat test
文件:test
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:18919815 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2000-01-01 10:39:04.081948284 +0800
最近更改:2000-01-01 10:39:04.081948284 +0800
最近改动:2000-01-01 10:39:04.081948284 +0800
创建时间:2000-01-01 10:39:04.081948284 +0800
[root@luo ~]#
3、文件及目录操作类命令
1touch:创建文件或修改文件的时间
(1)touch filename:创建空文件
[root@luo ~]# rm -rf test
[root@luo ~]# touch test
[root@luo ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test
[root@luo ~]#
(2)touch existingfile:更新文件时间戳
[root@luo ~]# touch test
[root@luo ~]# stat test
文件:test
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:18919815 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2000-01-01 10:49:05.595193173 +0800
最近更改:2000-01-01 10:49:05.595193173 +0800
最近改动:2000-01-01 10:49:05.595193173 +0800
创建时间:2000-01-01 10:48:24.025665508 +0800
[root@luo ~]#
(3)touch file1 file2:并写创建多个文件
[root@luo ~]# touch test01 test02
[root@luo ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test test01 test02
[root@luo ~]#
(4)touch file{1,2,3}:命令行展开创建多个文件
[root@luo ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test test01 test02 yun1 yun2 yun3
[root@luo ~]#
(5)touch {1…n}:命令行展开创建多个文件
[root@luo ~]# touch test{1..10}
[root@luo ~]# ls
公共 视频 文档 音乐 anaconda-ks.cfg test01 test1 test2 test4 test6 test8 yun1 yun3
模板 图片 下载 桌面 test test02 test10 test3 test5 test7 test9 yun2
[root@luo ~]#
(6)touch -d 202401010000 filename:创建文件指定时间戳
[root@luo ~]# touch -d 2021-07-07 00:00:00 yun02
[root@luo ~]# stat yun02
文件:yun02
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:18919834 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2021-07-07 00:00:00.000000000 +0800
最近更改:2021-07-07 00:00:00.000000000 +0800
最近改动:2000-01-01 11:00:20.900474313 +0800
创建时间:2000-01-01 11:00:20.900474313 +0800
[root@luo ~]#
2、(1)mkdir directory:创建目录
[root@luo ~]# mkdir test
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test
[root@luo ~]#
(2)mkdir -v directory:创建目录时显示信息
[root@luo ~]# mkdir -v test01
mkdir: 已创建目录 'test01'
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test test01
[root@luo ~]#
(3)mkdir -p directory/path/to:递归创建(此选项会将指定目录中不存在的父级目录一并创建)
[root@luo ~]# mkdir -p yun/path/to
[root@luo ~]# cd yun/path/to
[root@luo to]#
(4)mkdir -m mode directory:创建目录时指定权限,mode表示权限,数字表示法777、755等,字母表示法,ugo=rwx,a=rwm.
root@luo ~]# stat test1
文件:test1
大小:6 块:0 IO 块:4096 目录
设备:fd00h/64768d Inode:18919817 硬链接:2
权限:(0777/drwxrwxrwx) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2000-01-01 11:11:57.535818897 +0800
最近更改:2000-01-01 11:11:57.535818897 +0800
最近改动:2000-01-01 11:11:57.535818897 +0800
创建时间:2000-01-01 11:11:57.535818897 +0800
[root@luo ~]#
(5)mkdir test1 test2:并写创建多个目录
[root@luo ~]# mkdir yun1 yun2
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test test01 test1 yun yun1 yun2
[root@luo ~]#
(6)mkdir tets{1,2,3}:命令展开创建多个目录
[root@luo ~]# mkdir test{6,7,8}
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test test01 test1 test2 test3 test4 test6 test7 test8 yun yun1 yun2
[root@luo ~]#
(7)mkdir test{1…10}:命令展开创建多个目录
[root@luo ~]# mkdir test{1..10}
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test1 test10 test2 test3 test4 test5 test6 test7 test8 test9 yun yun1 yun2
[root@luo ~]#
3、(1)rmdir 空目录:删除空目录
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test1 test10 test2 test3 test4 test5 test6 test7 test8 test9 yun yun2
[root@luo ~]# rmdir yun2
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test1 test10 test2 test3 test4 test5 test6 test7 test8 test9 yun
[root@luo ~]#
(2)、rmdir -v 空目录:显示删除指令详细信息
[root@luo ~]# rmdir -v test1
rmdir: 正在删除目录,'test1'
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test10 test2 test3 test4 test5 test6 test7 test8 test9 yun
[root@luo ~]#
(3)、rmdir -p 空目录:递归删除空目录
[root@luo ~]# rmdir -p path/to
[root@luo ~]#
4、rm:删除文件或目录
(1)、rm -f 强制删除
[root@luo ~]# ls
00:00:00 10 3 5 7 9 模板 图片 下载 桌面 path test1 test2 test4 test6 test8
1 2 4 6 8 公共 视频 文档 音乐 anaconda-ks.cfg test test10 test3 test5 test7 test9
[root@luo ~]# rm -f test
[root@luo ~]# ls
00:00:00 10 3 5 7 9 模板 图片 下载 桌面 path test10 test3 test5 test7 test9
1 2 4 6 8 公共 视频 文档 音乐 anaconda-ks.cfg test1 test2 test4 test6 test8
[root@luo ~]#
(2)rm -r:删除某个目录及其所有文件及子目录全部删除
[root@luo ~]# rm -r path/to/go
rm:是否删除目录 'path/to/go'?y
[root@luo ~]# cd path/to/go
-bash: cd: path/to/go: 没有那个文件或目录
[root@luo ~]#
(3)rm -rf:强制删除目录
[root@luo ~]# mkdir path/
mkdir: 无法创建目录 “path/”: 文件已存在
[root@luo ~]# rm -rf path/
[root@luo ~]#
5cp:复制文件或目录
(1)cp source_file destination_file:复制单个文件
[root@luo ~]# cp test01 yun01
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test01 yun01
[root@luo ~]#
(2)cp -p source_file destination_file:复制并保留文件属性
[root@luo ~]# cp -p yun01 yun02
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg test01 yun01 yun02
[root@luo ~]#
(3)cp file1 file2 /path/to/destination:复制多个文件到同一目录
root@luo ~]# cp yun01 yun02 path/
[root@luo ~]# cd
[root@luo ~]# cd path/
[root@luo path]# ls
yun01 yun02
[root@luo path]#
(4)cp -r source_directory destination_directory:递归复制
[root@luo ~]# cp -r test01 path/to
[root@luo ~]# cd path/to
[root@luo to]# ls
test01
[root@luo to]#
(5)、cp -f source_file destination_file:强制复制
[root@luo to]# cp -f test01 test
[root@luo to]# ls
test test01
[root@luo to]#
6、mv:移动文件或目录
(1)mv oldname newname:重命名文件
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg path test01 yun01 yun02
[root@luo ~]# mv yun01 yun
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg path test01 yun yun02
[root@luo ~]#
(2)mv /filename /path/to/directory/:移动文件到另一个目录
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg path test01 yun yun02
[root@luo ~]# mv yun path/to
[root@luo ~]# cd path/to
[root@luo to]# ls
test test01 yun
[root@luo to]#
(3)、mv file1 file2 /path/to/directory/:移动多个文件到另一个目录
[root@luo ~]# ls
00:00:00 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg path test01 yun02
[root@luo ~]# mv test01 yun02 path/to
mv:是否覆盖'path/to/test01'? y
[root@luo ~]# cd path/to
[root@luo to]# ls
test test01 yun yun02
[root@luo to]#
(4)、mv dorectory /path/to/newlocation/:移动目录
[root@luo ~]# mv go/ path/to
mv:是否覆盖'path/to/go'? y
[root@luo ~]# cd path/to/go
[root@luo go]#
7、tar:打包、归档文件或目录
(1)、tar -cvf archive_name.tar file_or_directory:创建归档文件
[root@luo ~]# tar -cvf test.tar yun
yun
[root@luo ~]#
[root@luo ~]# ls
00:00:00 模板 图片 下载 桌面 test.tar
公共 视频 文档 音乐 anaconda-ks.cfg yun
[root@luo ~]#
(2)、tar -czvf archive_name.tar.gz file_ordirectory:压缩并归档文件
[root@luo ~]# ls
00:00:00 模板 图片 下载 桌面 test.tar yun
公共 视频 文档 音乐 anaconda-ks.cfg test.tar.gz
[root@luo ~]#
(3)、tar -xvf archive_name.tar:释放归档文件
[root@luo ~]# tar -xvf test.tar
yun
[root@luo ~]# ls
00:00:00 模板 图片 下载 桌面 test.tar yun
公共 视频 文档 音乐 anaconda-ks.cfg test.tar.gz
[root@luo ~]#
(4)、tar -xzvf archive_name.gz:解压释放归档文件
[root@luo ~]# tar -xzvf test.tar.gz
yun
[root@luo ~]#
(5)、tar -tvf archive_name.tar:查看归档文件的内容
[root@luo ~]# tar -tvf test.tar
-rw-r--r-- root/root 0 2024-07-28 19:32 yun
[root@luo ~]#
(6)、tar -cvf archive_name.tar /path/to/directory:递归创建目录的归档文件
[root@luo ~]# tar -cvf yun.tar path/to/go
path/to/go/
path/to/go/yun.tar
[root@luo ~]# cd path/to/go
[root@luo go]# ls
yun.tar
[root@luo go]
8、du:查看文件或目录内容的大小
(1)、du -h filename:以kb,mb,gb为单位提高文件可读性
[root@luo ~]# du -h anaconda-ks.cfg
4.0K anaconda-ks.cfg
[root@luo ~]#
(2)、du -b filename:显示文件或目录大小时,以byte为单位
[root@luo ~]# du -b anaconda-ks.cfg
1018 anaconda-ks.cfg
[root@luo ~]#
(3)、du -hs directory:仅显示总和,即当前目录容量大小
[root@luo ~]# du -hs path
0 path
[root@luo ~]#
(6)、tar -cvf archive_name.tar /path/to/directory:递归创建目录的归档文件
```bash
[root@luo ~]# tar -cvf yun.tar path/to/go
path/to/go/
path/to/go/yun.tar
[root@luo ~]# cd path/to/go
[root@luo go]# ls
yun.tar
[root@luo go]
8、du:查看文件或目录内容的大小
(1)、du -h filename:以kb,mb,gb为单位提高文件可读性
[root@luo ~]# du -h anaconda-ks.cfg
4.0K anaconda-ks.cfg
[root@luo ~]#
(2)、du -b filename:显示文件或目录大小时,以byte为单位
[root@luo ~]# du -b anaconda-ks.cfg
1018 anaconda-ks.cfg
[root@luo ~]#
(3)、du -hs directory:仅显示总和,即当前目录容量大小
[root@luo ~]# du -hs path
0 path
[root@luo ~]#