绝对路径和相对路径linux
以跟目录开始的叫绝对路径shell
不以根目录开始的叫绝对路径bash
[root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg- ifcfg-ens33 ifcfg-lo [root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg- ifcfg-ens33 ifcfg-lo [root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33 [root@cham3 ~]# ls /root/anaconda-ks.cfg /root/anaconda-ks.cfg [root@cham3 ~]# ls /etc/hostname /etc/hostname [root@cham3 ~]# cat /etc/hostname cham3 [root@cham3 ~]# ls /root/.ssh/authorized_keys 绝对路径 /root/.ssh/authorized_keys [root@cham3 ~]# pwd /root [root@cham3 ~]# ls .ssh/authorized_keys 相对路径 .ssh/authorized_keys [root@cham3 ~]# cd /etc/sysconfig/ [root@cham3 sysconfig]# ls network-scripts/ifcfg-ens33 network-scripts/ifcfg-ens33 相对路径
cd命令ssh
[root@cham3 ~]# cd /etc/sysconfig/ cd进入 etc /sysconfig路径 [root@cham3 sysconfig]# cd - cd - 返回上一次的所在目录,有点相似电视的返看键 /root [root@cham3 ~]# cd - 再cd - 又回到 etc/sysconfig路径 /etc/sysconfig [root@cham3 sysconfig]# pwd /etc/sysconfig [root@cham3 sysconfig]# cd - /root [root@cham3 ~]# cd ~ ~就是家目录,cd ~就是回到加目录 [root@cham3 ~]# cd .. cd .. 返回上一级目录 [root@cham3 /]# cd - cd- 返回到家目录 /root [root@cham3 ~]# pwd 查看所在目录位置
建立和删除目录mkdir/rmdir rm命令spa
1.命令语法命令行
rm 目录code
2.命令描述:排序
rm(remove)的缩写,这个命令既能够删除目录,也能够删除文件。图片
3.命令参数ip
-r 删除目录用的选项,能够删除非空目录。但会询问你是否删除,"y" 或 "n"
-f 表示强制删除。它不会询问你是否删除。若是后面跟一个不存在的文件或目录,则不会报错。在使用-f选项的时候,必定要加上-r选项,不然会报错。
注:通常使用-rf命令,这样删除目录或文件比较方便。
1.History命令语法: #history [n]
#history [-c]
#history [-raw] histfiles
2.命令描述: history(历史的简写)能够列出以前你用的全部命令
3.参数:
n :数字,要列出最近的 n 笔命令列表
-c :将目前的shell中的全部 history 内容所有消除
-a :将目前新增的history 指令新增入 histfiles 中,若没有加 histfiles , 则预设写入 ~/.bash_history
-r :将 histfiles 的内容读到目前这个 shell 的 history 记忆中
-w :将目前的 history 记忆内容写入 histfiles
Linux系统当你在shell(控制台)中输入并执行命令时,shell会自动把你的命令记录到历史列表中,通常保存在用户目录下的.bash_history文件中。默认保存1000条,你也能够更改这个值。
若是你键入 history, history会向你显示你所使用的前1000个历史命令,而且给它们编了号,你会看到一个用数字编号的列表快速从屏幕上卷过。你可能不须要查看1000个命令中的全部项目, 固然你也能够加入数字来列出最近的 n 笔命令列表。
linux中history命令不单单让咱们能够查询历史命令而已. 咱们还能够利用相关的功能来帮咱们执行命令。
列出全部的历史记录: # history
只列出最近10条记录: # history 10 (注,history和10中间有空格)
使用命令记录号码执行命令,执行历史清单中的第99条命令 #!99 (!和99中间没有空格)
重复执行上一个命令 #!!
执行最后一次以rpm开头的命令(!? ?表明的是字符串,这个String能够随便输,Shell会从最后一条历史命令向前搜索,最早匹配的一条命令将会获得执行。) #!rpm
逐屏列出全部的历史记录:# history | more 使用空格看下面的命令记录。
当即清空history当前全部历史命令的记录 #history -c
除了使用history命令,在 shell 或 GUI 终端提示下,你也可使用上下方向键来翻阅命令历史(向下箭头会向前翻阅),直到你找到所需命令为止。这可让咱们很方便地编辑前面的某一条命令,而不用重复输入相似的命令。
1.命令格式:
#mkdir [-mp]目录名称
2.命令描述:
命令mkdir(make directory的简写)用于建立目录。
3.命令参数:
-m:选项用于指定要建立目录的权限.
-p:选项能够建立一大串级联目录,而且当建立一个已经存在的目录时,不会报错。
-pv:加上v选项能够显示建立的过程
1.命令格式:
#rmdir 目录名称
2.命令功能:
命令rmdir(remove directory的简写)用于删除空目录,后面能够是一个目录,也能够是多个目录(用空格分隔)该命令只能删除目录,不能删除文件。
1.命令格式:
touch [选项] [文件]
2.命令描述:
若是有这个文件,则会改变该文件的访问时间,若是没有这个文件,就会建立这个文件。
3.命令参数:
-a 或--time=atime或--time=access或--time=use 只更改存取时间。
-c 或--no-create 不创建任何文档。
-d 使用指定的日期时间,而非如今的时间。
-f 此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。
-m 或--time=mtime或--time=modify 只更改变更时间。
-r 把指定文档或目录的日期时间,通通设成和参考文档或目录的日期时间相同。
-t 使用指定的日期时间,而非如今的时间。
1.命令语法:tree [-aACdDfFgilnNpqstux][-I <范本样式>][-P <范本样式>][目录...]
2.命令描述:以树状图列出目录的内容。
补充说明:执行tree指令,它会列出指定目录下的全部文件,包括子目录里的文件。
3.命令参数:
-a 显示全部文件和目录。
-d 显示目录名称而非内容。
-D 列出文件或目录的更改时间。
-f 在每一个文件或目录以前,显示完整的相对路径名称。
-i 不以阶梯状列出文件或目录名称。
-N 直接列出文件和目录名称,包括控制字符。
-p 列出权限标示。
-s 列出文件或目录大小。
-t 用文件和目录的更改时间排序。
如下是命令行:
make directory Last login: Thu Oct 19 18:23:24 2017 from 192.168.230.1 咱们先登录 [root@cham2 ~]# mkdir /tmp/chamlinux 在tmp下新建一个chamlinux目录 [root@cham2 ~]# ls -ld /tmp/chamlinux 用ls -ld 查看目录 drwxr-xr-x 2 root root 6 10月 23 21:18 /tmp/chamlinux [root@cham2 ~]# date 时间 2017年 10月 23日 星期一 21:19:01 CST [root@cham2 ~]# mkdir /tmp/chamlinux/1/2/ 会提示没有文件或目录 mkdir: 没法建立目录"/tmp/chamlinux/1/2/": 没有那个文件或目录 [root@cham2 ~]# ls -l /tmp/chamlinux 看一下 是空的 总用量 0 [root@cham2 ~]# mkdir -p /tmp/chamlinux/1/2/ 用-p 级联建立 [root@cham2 ~]# ls -l /tmp/chamlinux/ 总用量 0 drwxr-xr-x 3 root root 15 10月 23 21:20 1 [root@cham2 ~]# ls -l /tmp/chamlinux/1 总用量 0 drwxr-xr-x 2 root root 6 10月 23 21:20 2 [root@cham2 ~]# mkdir -p /tmp/chamlinux/2/3/4 [root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/4 -v可视化过程 [root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/4 mkdir: 已建立目录 "/tmp/chamlinux/2/3" mkdir: 已建立目录 "/tmp/chamlinux/2/3/4" [root@cham2 ~]# rmdir /tmp/chamlinux/2 rmdir: 删除 "/tmp/chamlinux/2" 失败: 目录非空 [root@cham2 ~]# rmdir /tmp/chamlinux/2/3/4/ [root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt [root@cham2 ~]# ls /tmp/chamlinux/2/3/ 1.txt [root@cham2 ~]# tree /tmp/chamlinux/ /tmp/chamlinux/ ├── 1 │ └── 2 └── 2 └── 3 └── 1.txt 4 directories, 1 file [root@cham2 ~]# rmdir /tmp/chamlinux/2/3 rmdir: 删除 "/tmp/chamlinux/2/3" 失败: 目录非空 [root@cham2 ~]# rmdir /tmp/chamlinux/1/2/ [root@cham2 ~]# mk mkdict mkfifo mkfs.ext2 mkfs.xfs mknod mkdir mkfs mkfs.ext3 mkhomedir_helper mkswap mkdumprd mkfs.btrfs mkfs.ext4 mkinitrd mktemp mke2fs mkfs.cramfs mkfs.minix mklost+found [root@cham2 ~]# mkdir /tmp/chamlinux/1/2 [root@cham2 ~]# rmdir -p /tmp/chamlinux/1/2/ 这种方法不多用 同样能够级联删除 rmdir: 删除目录 "/tmp/chamlinux" 失败: 目录非空 [root@cham2 ~]# tree /tmp/chamlinux/ 其实是已经删除了1/2已经删除了 /tmp/chamlinux/ └── 2 └── 3 └── 1.txt 2 directories, 1 file [root@cham2 ~]# rm /tmp/chamlinux/2/3/1.txt 使用rm 命令删除 rm:是否删除普通空文件 "/tmp/chamlinux/2/3/1.txt"?y [root@cham2 ~]# tree /tmp/chamlinux/ 看一下 /tmp/chamlinux/ └── 2 └── 3 2 directories, 0 files [root@cham2 ~]# toch /tmp/chamlinux/2/3/1.txt 新建文件 -bash: toch: 未找到命令 [root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt 新建文件 [root@cham2 ~]# touch /tmp/chamlinux/2/3/2.txt [root@cham2 ~]# rm /tmp/chamlinux/2/3/ 使用了TAB命令 1.txt 2.txt [root@cham2 ~]# rm /tmp/chamlinux/2/3/ 1.txt 2.txt [root@cham2 ~]# rm /tmp/chamlinux/2/3/*.txt 用*表示通配 rm:是否删除普通空文件 "/tmp/chamlinux/2/3/1.txt"?n rm:是否删除普通空文件 "/tmp/chamlinux/2/3/2.txt"?n [root@cham2 ~]# rm -f /tmp/chamlinux/2/3/*.txt 加-f 不询问 强制的 [root@cham2 ~]# !tree 小知识,上一次最近的tree开头的命令 tree /tmp/chamlinux/ /tmp/chamlinux/ └── 2 └── 3 2 directories, 0 files [root@cham2 ~]# rm /tmp/chamlinux/2/3/ 删除目录rm不行 rm: 没法删除"/tmp/chamlinux/2/3/": 是一个目录 [root@cham2 ~]# rm -rv /tmp/chamlinux/2/3/ 加-r 就是删除级联的目录 rm:是否进入目录"/tmp/chamlinux/2/3/"? y rm:是否删除普通空文件 "/tmp/chamlinux/2/3/2.txt"?y 已删除"/tmp/chamlinux/2/3/2.txt" rm:是否删除目录 "/tmp/chamlinux/2/3/"?y 已删除目录:"/tmp/chamlinux/2/3/" [root@cham2 ~]# [root@cham2 ~]# rm -r /tmp/chamlinux/2/3/ rm: 没法删除"/tmp/chamlinux/2/3/": 没有那个文件或目录 [root@cham2 ~]# tree /tmp/chamlinux/ /tmp/chamlinux/ └── 2 1 directory, 0 files [root@cham2 ~]# rm -rf /tmp/chamlinux/2/ 加-f 就是不提示,强制删除 [root@cham2 ~]# !tree tree /tmp/chamlinux/ /tmp/chamlinux/ 这时候已经没有任何文件和目录了 0 directories, 0 files [root@cham2 ~]# !tree tree /tmp/chamlinux/2 /tmp/chamlinux/2 [error opening dir] 0 directories, 0 files [root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/ 在建立一下 mkdir: 已建立目录 "/tmp/chamlinux/2" mkdir: 已建立目录 "/tmp/chamlinux/2/3/" [root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt 在新建一个文件 [root@cham2 ~]# touch /tmp/chamlinux/2/2.txt 在新建一个文件 [root@cham2 ~]# tree /tmp/chamlinux/ 看一下 /tmp/chamlinux/ └── 2 ├── 2.txt └── 3 └── 1.txt 2 directories, 2 files [root@cham2 ~]# rm -rfv /tmp/chamlinux/2/3/ 加-v删除,,是可视化。 已删除"/tmp/chamlinux/2/3/1.txt" 先删除文件或者下面的子目录 已删除目录:"/tmp/chamlinux/2/3/" 而后再删除 [root@cham2 ~]# tree /tmp/chamlinux/ /tmp/chamlinux/ └── 2 └── 2.txt 1 directory, 1 file [root@cham2 ~]# rm -rfv /tmp/chamlinux/2/3/ 知识点删除一个不存在的目录,再去删,什么 都不提示 -f 起的做用 [root@cham2 ~]# rm -rv /tmp/chamlinux/2/3/ 取消-f rm: 没法删除"/tmp/chamlinux/2/3/": 没有那个文件或目录