Post

linux(CentOS7) 目录管理、系统管理

目录管理命令

nkdri

  • 指定权限创建
  • -p递归创建
1
2
3
4
5
6
[root@Cc 20200326]# mkdir -m777 mkdira
[root@Cc 20200326]# ll
总用量 8
drwxrwxrwx 2 root root 4096 3月  25 22:52 mkdira
drwxr-xr-x 2 root root 4096 3月  25 22:39 pwd
[root@Cc 20200326]#

rmdir

  • 删除

ls

  • ls -lk k、h 为 k、M、G
  • 大小显示排序
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@Cc lichaocheng]#  ls -lhS
总用量 31M
-rw-r--r-- 1 root  root   25M 11月  7 23:31 gogs_0.11.91_linux_amd64.tar.gz
-rw-r--r-- 1 root  root  5.8M 2月  26 09:29 hugo.filepart
drwxr-xr-x 2 root  root  4.0K 2月   7 12:51 C
drwxr-xr-x 3 root  root  4.0K 12月 17 11:31 file
drwxr-xr-x 3 root  root  4.0K 1月  17 17:34 frp
drwxr-xr-x 2 root  root  4.0K 11月 13 10:37 frp1
drwxr-xr-x 8 admin admin 4.0K 1月  16 16:54 gogs
drwxr-xr-x 3 root  root  4.0K 11月 28 20:26 harbor
drwxr-xr-x 2 root  root  4.0K 12月 19 15:54 hf
drwxr-xr-x 3 root  root  4.0K 2月  28 23:03 hugo

pwd

  • 当前目录

cd

  • cd -
  • cd /root

tree

  • 查看目录

tar

  • 打包不压缩
1
2
3
4
5
6
7
8
[root@Cc tar]# tar -cvf tarTest.txt.tar tarTest.txt
tarTest.txt
[root@Cc tar]# ll
总用量 16
drwxr-xr-x 2 root root  4096 3月  25 22:59 lcc
-rw-r--r-- 1 root root     0 3月  25 23:01 tarTest.txt
-rw-r--r-- 1 root root 10240 3月  25 23:01 tarTest.txt.tar
[root@Cc tar]#
  • 打包并使用 gzip 压缩
1
2
3
4
5
6
7
8
9
10
11
12
[root@Cc tar]# tar -zcvf tarTest.txt.tar.gz ./lcc/
./lcc/
./lcc/b
./lcc/a
[root@Cc tar]# ll
总用量 20
drwxr-xr-x 2 root root  4096 3月  25 22:59 lcc
-rw-r--r-- 1 root root     0 3月  25 23:01 tarTest.txt
-rw-r--r-- 1 root root 10240 3月  25 23:01 tarTest.txt.tar
-rw-r--r-- 1 root root   144 3月  25 23:02 tarTest.txt.tar.gz
[root@Cc tar]#

  • 使用 bzip2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@Cc tar]# tar -jcvf tarTest.txt.tar.bz2 ./lcc/
./lcc/
./lcc/b
./lcc/a
tar (child): bzip2:无法 exec: 没有那个文件或目录
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[root@Cc tar]# ll
总用量 20
drwxr-xr-x 2 root root  4096 3月  25 22:59 lcc
-rw-r--r-- 1 root root     0 3月  25 23:01 tarTest.txt
-rw-r--r-- 1 root root 10240 3月  25 23:01 tarTest.txt.tar
-rw-r--r-- 1 root root     0 3月  25 23:04 tarTest.txt.tar.bz2
-rw-r--r-- 1 root root   144 3月  25 23:02 tarTest.txt.tar.gz
[root@Cc tar]#
  • 查看当前压缩包
1
2
3
4
5
[root@Cc tar]# tar -ztvf tarTest.txt.tar.gz
drwxr-xr-x root/root         0 2020-03-25 22:59 ./lcc/
-rw-r--r-- root/root         0 2020-03-25 22:59 ./lcc/b
-rw-r--r-- root/root         0 2020-03-25 22:59 ./lcc/a
[root@Cc tar]#
  • 解压之中指定文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@Cc tar]# rm -rf lcc/
[root@Cc tar]# ll
总用量 16
-rw-r--r-- 1 root root     0 3月  25 23:01 tarTest.txt
-rw-r--r-- 1 root root 10240 3月  25 23:01 tarTest.txt.tar
-rw-r--r-- 1 root root     0 3月  25 23:05 tarTest.txt.tar.bz2
-rw-r--r-- 1 root root   144 3月  25 23:02 tarTest.txt.tar.gz
[root@Cc tar]# tar -zxvf tarTest.txt.tar.gz ./lcc/b
./lcc/b
[root@Cc tar]# tree
.
├── lcc
│   └── b
├── tarTest.txt
├── tarTest.txt.tar
├── tarTest.txt.tar.bz2
└── tarTest.txt.tar.gz

1 directory, 5 files
[root@Cc tar]#
  • 保留文件属性 [root@Cc tar]# tar -zxvpf tarTest.txt.tar.gz ./lcc/
  • 排除某些文件 tar --exclude /home/*log -zcvf tarTest.txt.tar.gz ./lcc/

zip/uzip

gzip/gunzip

bzip2/bunzip2

以上三种自己百度谷歌,我有时间会补上去

系统管理

man

可以查看 yum 命令手册,按 q 退出

1
2
3
[root@Cc system]# man -c
您需要什么手册页?
[root@Cc system]# man yum

export(导出环境变量)

  • 修改 go 环境变量为例
1
2
3
4
5
6
[root@Cc system]# go env |grep GOPATH
GOPATH="/opt/gopath"
[root@Cc system]# export GOPATH="/root"
[root@Cc system]# go env |grep GOPATH
GOPATH="/root"
[root@Cc system]# export GOPATH="/opt/gopath"
  • export -n

    删除指定变量

history(查看历史)

  • 将当前写入到文件
1
[root@Cc history]# history -w history.txt
  • 清楚当前 history history -c
  • 删除所有历史命令
1
2
[root@Cc history]# rm -rf ~/.bash_history
[root@Cc history]# history -c
  • 可以配合history |grep [docker]查找

date(时间操作)

不让费时间了

clear(清除屏幕)

ctrl + l

uptime(查看系统负载)

1
2
3
[root@Cc history]# uptime
 23:33:15 up 5 days, 14:18,  2 users,  load average: 0.21, 0.32, 0.31
[root@Cc history]#

free(显示系统内存状况)

[root@Cc history]# free -m

dd(转换或者复制)

百度 填补

任务管理

at(单词任务)

指定时间输入到文件内部 [root@Cc history]# at 17:20 tomorrow

crond(周期任务)

TODO 找时间填补

关机命令

shutdown (关机)

halt

reboot(重启)

poweroff(终止系统运行)

init(改变系统允许级别)

  • 0 停机
  • 1 单用户模式
  • 2 多用户模式
  • 3 完全多用户模式
  • 4 么有用到
  • 5 X11
  • 6 重新启动

    配置 /etc/inittab

文本操作

  • vi
  • vim

最后总结(个人 shell)

用所学的 shell 备份重要的文件目录

下次补上

This post is licensed under CC BY 4.0 by the author.