一.基础命令
***** history
1.上下光标键进行查看
2.Ctrl+R然后输入关键字后按右键:
[root@lee7 /]# ll
总用量 32
lrwxrwxrwx. 1 root root 7 12月 6 22:54 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 12月 11 13:21 boot
drwxr-xr-x. 20 root root 3320 12月 11 13:20 dev
drwxr-xr-x. 141 root root 8192 12月 11 13:20 etc
drwxr-xr-x. 3 root root 25 12月 6 23:20 home
lrwxrwxrwx. 1 root root 7 12月 6 22:54 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 12月 6 22:54 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 media
drwxr-xr-x. 2 root root 6 4月 11 2018 mnt
drwxr-xr-x. 3 root root 16 12月 6 23:11 opt
dr-xr-xr-x. 230 root root 0 12月 11 13:20 proc
dr-xr-x---. 17 root root 4096 12月 11 13:29 root
drwxr-xr-x. 43 root root 1340 12月 11 13:25 run
lrwxrwxrwx. 1 root root 8 12月 6 22:54 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 4月 11 2018 srv
dr-xr-xr-x. 13 root root 0 12月 11 13:20 sys
drwxrwxrwt. 74 root root 8192 12月 11 13:24 tmp
drwxr-xr-x. 13 root root 155 12月 6 22:54 usr
drwxr-xr-x. 20 root root 282 12月 6 23:33 var
[root@lee7 /]#
[root@lee7 /]#
[root@lee7 /]#
(reverse-i-search)`':
3.!number 可以根据!后加数据执行以前操作的命令,后输出结果
95 cd /etc/yum.repos.d
96 cd /
97 cd etc/yum.repos.d
98 ll
99 cd ..
100 ll
101 cd ~
102 cd /
103 cd
104 clear
105 cd /
106 cd ~
107 ll
108 cd /
109 ll
110 tree
111*
112 ll
113 tree
114 cd /
115 tree
116 history
117 ifconfig
118 ll
119 ll
120 history
[root@lee7 /]# !95
cd /etc/yum.repos.d
[root@lee7 yum.repos.d]#
[root@lee7 yum.repos.d]#
[root@lee7 yum.repos.d]# ll
总用量 4
-rw-r--r--. 1 root root 2523 8月 4 15:04 CentOS-Base.repo
[root@lee7 yum.repos.d]#
[root@lee7 yum.repos.d]#
4.4.!字符串 该命令从历史命令中,区别从后到前的相同的命令执行
5.history命令隐藏
set +o history 执行该名后后 操作后面的命名就隐藏看不见了
set -o history 执行该名后后 操作后面的命名就取消隐藏历史命令
[root@lee7 /]#
[root@lee7 /]#
[root@lee7 /]#
[root@lee7 /]#
[root@lee7 /]# cat /etc/pa
pam.d/ passwd passwd-
[root@lee7 /]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@lee7 /]# history
1 ll
2 ls -all
.
.
.
121 cd /etc/yum.repos.d
122 ll
123 clear
124 history
125 cd /
126 tree
127 set +o history
[root@lee7 /]#
6.删除历史命令:
history -d number
110 tree
111*
112 ll
113 tree
114 cd /
115 tree
116 history
117 ifconfig
118 ll
119 ll
120 history
121 cd /etc/yum.repos.d
122 ll
123 clear
124 history
125 cd /
126 tree
127 set +o history
128 history
[root@lee7 /]#
[root@lee7 /]#
[root@lee7 /]#
[root@lee7 /]# history -d 111
[root@lee7 /]# history
1 ll
2 ls -all
.
.
.
108 cd /
109 ll
110 tree
111 ll
112 tree
113 cd /
114 tree
115 history
116 ifconfig
117 ll
118 ll
119 history
120 cd /etc/yum.repos.d
121 ll
122 clear
123 history
124 cd /
125 tree
126 set +o history
127 history
128 history -d 111
129 history
[root@lee7 /]#
二.帮助命令快捷键:
Ctrl+C :终止程序
Ctrl+D :退出
Ctrl+L :clear 清屏
Ctrl+R :搜索历史记录
Ctrl+A :返回该条命令的首字母
Ctrl+e :返回该条命令的尾字母
Ctrl+方向键 :以单词为单位移动
Ctrl+Shift+++:终端页面放大
Ctrl+- :终端页面缩小
tab :补全命令
!$ :引用上一条命令的最后一条参数
三.文件系统和目录结构:
3-1.文件系统慨念:
计算机的文件系统是一种存储和组织计算机数据的方法,它使得对其访问和查找变得容易。
文件系统使用文件和树形目录的抽象逻辑慨念,用户使用文件系统来保存数据不必关心数据实际保存在硬盘的地址为多少的数据块上,只需要记住这个文件的所属目录和文件名即可。
绝对路径:绝对路径是从linux中最底层的根目录“/”开始算,绝对是以“/”作为路径的开头
相对路径:相对于当前位置的路径开始算,不是以“/”作为路径的开头
3-2.Linux主要目录及用途
| 目录名 | 主要存放的文件以及其用途 |
|---|---|
| /bin | bin是binary的缩写,这个目录存放着经常使用的命令。 |
| /boot | 存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件。 |
| /dev | dev是Device的缩写,该目录下存放的是linux的外部设备,在linux中访问设备的方式和访问文件的方式相同。 |
| /etc | 这个目录用来存放所有的系统管理所需要的配置文件和子目录。 |
| /home | 用户的主目录,在Linux中每个用户都有一个自己的目录,一般该目录名是以用户的账号命令的。 |
| /lib | 这个目录里存放着系统最基本的动态链接共享库,其作用类似于windows里的DLL文件。几乎所有的应用程序都需要用到这些共享库。 |
| /mnt | 系统提供该目录是为了让用户临时挂载别的文件系统的。 |
| /opt | 这是给主机额外安装软件所摆放的目录。 |
| /proc | 系统内映射的虚拟目录,可以通过直接访问这个目录来获取信息 |
| /root | 该目录为系统管理员,超级权限者的用户主目录 |
| /sbin | 存放的是系统管理员使用的系统管理程序 |
| /srv | 该目录存放的启动之后需要提取的数据 |
| /tmp | 该目录存放一些临时文件 |
| /usr | 这是一个非常重要的目录,用户很多应用程序和文件都放在这个目录下,类似于windows下的program files目录,其中/usr/bin是系统用户使用的应用程序;/usr/sbin是超级用户使用的比较高级的管理程序和系统守护程序;/usr/src是内核源代码默认的放置目录 |
| /var | 习惯将那些经常被修改、不断扩充的目录放在这个目录下,包括各种日志文件 |
| /run | 是一个临时文件系统,存储系统启动以来的信息,当系统启动时被清理或删除。 |
3-3.文件管理相关的命令
touch 命令用于创建空文件,也可以用于修改文件的时间戳
3-3-1.创建一个空白文件;且时间为当前时间
[root@lee7 test]# touch lee
[root@lee7 test]# ll
总用量 0
-rw-r--r--. 1 root root 0 12月 11 20:27 lee
[root@lee7 test]#
[root@lee7 test]# stat lee
文件:"lee"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:19928469 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:default_t:s0
最近访问:2022-12-11 20:27:56.120454312 +0800
最近更改:2022-12-11 20:27:56.120454312 +0800
最近改动:2022-12-11 20:27:56.120454312 +0800
创建时间:-
[root@lee7 test]#
3-3-2:仅修改文件访问时间
[root@lee7 test]# touch -a lee
[root@lee7 test]# stat lee
文件:"lee"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:19928469 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:default_t:s0
最近访问:2022-12-11 20:32:12.482712241 +0800
最近更改:2022-12-11 20:27:56.120454312 +0800
最近改动:2022-12-11 20:32:12.482712241 +0800
创建时间:-
[root@lee7 test]#
3-3-3:仅修改文件内容时间
[root@lee7 test]# touch -m lee
[root@lee7 test]# stat lee
文件:"lee"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:19928469 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:default_t:s0
最近访问:2022-12-11 20:32:12.482712241 +0800
最近更改:2022-12-11 20:35:01.484517261 +0800
最近改动:2022-12-11 20:35:01.484517261 +0800
创建时间:-
[root@lee7 test]#
mkdir:命令用于创建目录(文件夹)
mkdir [选项]目录名
选项:-p 创建多个目录
[root@lee7 test]# mkdir -p a/b/c
[root@lee7 test]# mkdir -p a/b/c/d/f
[root@lee7 test]# tree
.
├── a
│ └── b
│ └── c
│ └── d
│ └── f
└── lee
5 directories, 1 file
[root@lee7 test]# ll
总用量 0
drwxr-xr-x. 3 root root 15 12月 11 20:50 a
-rw-r--r--. 1 root root 0 12月 11 20:35 lee
[root@lee7 test]#
-v 创建详细信息
[root@lee7 test]# mkdir -pv a/b/c/d/f/h/i/j
mkdir: 已创建目录 "a/b/c/d/f/h"
mkdir: 已创建目录 "a/b/c/d/f/h/i"
mkdir: 已创建目录 "a/b/c/d/f/h/i/j"
[root@lee7 test]#
[root@lee7 test]# mkdir -v ccdd
mkdir: 已创建目录 "ccdd"
[root@lee7 test]#
-m 直接根权限
[root@lee7 test]# mkdir lee
[root@lee7 test]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 11 20:55 lee
[root@lee7 test]# mkdir -m 777 leee
[root@lee7 test]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 11 20:55 lee
drwxrwxrwx. 2 root root 6 12月 11 20:56 leee
[root@lee7 test]#
rm 用于删除文件或者目录
rm [选项] 目录或者文件名
选项
-v :显示进行删除步骤
-r:全部目录和子目录均递归地删除
-f:强制删除文件,不会询问而直接删除
rm -v 文件名 :该命令只能文件不能删除目录
[root@lee7 test]# tree
.
├── lee
└── leee
2 directories, 0 files
[root@lee7 test]#
[root@lee7 test]#
[root@lee7 test]# rm -v leee
rm: 无法删除"leee": 是一个目录
[root@lee7 test]# rm -v lee
rm: 无法删除"lee": 是一个目录
[root@lee7 test]# touch leeee
[root@lee7 test]# rm -v leeee
rm:是否删除普通空文件 "leeee"?y
已删除"leeee"
[root@lee7 test]#
rm -r 文件名 此删除命令会一步一步提醒删除
[root@lee7 lee]#
[root@lee7 lee]# rm -r 123
rm:是否删除普通空文件 "123"?n
[root@lee7 lee]#
[root@lee7 lee]#
[root@lee7 lee]# vim 123
[1]+ 已停止 vim 123
[root@lee7 lee]# cat 123
[root@lee7 lee]#
[root@lee7 lee]#
[root@lee7 lee]# vim 123
[root@lee7 lee]# cat 123
123jcuwbfujbcjbwufbjdkhwdieu
[root@lee7 lee]#
[root@lee7 lee]#
[root@lee7 lee]# rm -r 123
rm:是否删除普通文件 "123"?n
[root@lee7 lee]#
[root@lee7 lee]#
[root@lee7 lee]#
[root@lee7 lee]# cd -
/test
[root@lee7 test]# ll
总用量 0
drwxr-xr-x. 2 root root 33 12月 11 21:10 lee
drwxrwxrwx. 2 root root 6 12月 11 20:56 leee
[root@lee7 test]#
[root@lee7 test]#
[root@lee7 test]#
[root@lee7 test]# rm -r lee
rm:是否进入目录"lee"? y
rm:是否删除普通文件 "lee/.123.swp"?y
rm:是否删除普通文件 "lee/123"?
rm:是否删除目录 "lee"?y
rm: 无法删除"lee": 目录非空
[root@lee7 test]#
rm -f 文件名 该命令只能删除文件 不能删除目录 最好的办法 选项的中的rf结合使用
[root@lee7 test]# rm -f leee
rm: 无法删除"leee": 是一个目录
[root@lee7 test]# cd leee/
[root@lee7 leee]# touch 123
[root@lee7 leee]#
[root@lee7 leee]#
[root@lee7 leee]# ll
总用量 0
-rw-r--r--. 1 root root 0 12月 11 21:16 123
[root@lee7 leee]#
[root@lee7 leee]#
[root@lee7 leee]#
[root@lee7 leee]# rm -f 123
[root@lee7 leee]# ll
总用量 0
[root@lee7 leee]#
cp 用于复制文件或者目录
rm [选项] 目录或者文件名
选项
-p :复制文件的内容,同时还把修改时间和访问权限也复制到新文件中
-r:若给出源文件是一个目录文件,此时将复制该目录下所有的子目录和文件
cp -p 源文件 复制到当前地址,加-p和不加-p的区别在于以下:
[root@lee7 test]# cp /etc/passwd ./
[root@lee7 test]# stat /etc/passwd
文件:"/etc/passwd"
大小:2338 块:8 IO 块:4096 普通文件
设备:fd00h/64768d Inode:16787326 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:system_u:object_r:passwd_file_t:s0
最近访问:2022-12-11 20:11:57.977522416 +0800
最近更改:2022-12-06 23:20:47.495895784 +0800
最近改动:2022-12-06 23:20:47.496895784 +0800
创建时间:-
[root@lee7 test]# stat passwd
文件:"passwd"
大小:2338 块:8 IO 块:4096 普通文件
设备:fd00h/64768d Inode:19928469 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:default_t:s0
最近访问:2022-12-11 21:51:37.757084136 +0800
最近更改:2022-12-11 21:51:37.757084136 +0800
最近改动:2022-12-11 21:51:37.757084136 +0800
创建时间:-
[root@lee7 test]#
[root@lee7 test]# cd leeqiangguo/
[root@lee7 leeqiangguo]# cp -p /etc/passwd ./
[root@lee7 leeqiangguo]# ll
总用量 4
-rw-r--r--. 1 root root 2338 12月 6 23:20 passwd
[root@lee7 leeqiangguo]# stat passwd
文件:"passwd"
大小:2338 块:8 IO 块:4096 普通文件
设备:fd00h/64768d Inode:33790870 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:default_t:s0
最近访问:2022-12-11 20:11:57.977522416 +0800
最近更改:2022-12-06 23:20:47.495895784 +0800
最近改动:2022-12-11 22:00:34.696338281 +0800
创建时间:-
[root@lee7 leeqiangguo]#
cp -r 源目录 当前目录
[root@lee7 test]# cp /etc ./ #不加参数目录复制不到当前目录下
cp: 略过目录"/etc"
[root@lee7 test]# cp -r /etc ./
[root@lee7 test]# ll
总用量 16
drwxr-xr-x. 141 root root 8192 12月 11 22:06 etc
drwxr-xr-x. 2 root root 20 12月 11 22:00 leeqiangguo
-rw-r--r--. 1 root root 2338 12月 11 21:51 passwd
[root@lee7 test]#