7.绝对文件路径?相对文件路径?快捷方式?
绝对文件路径:描述了在虚拟目录结构中该目录的确切位置,以虚拟目录跟目录开始,相当于目录全名。
以正斜线(/)开始,比如 /usr/local。
相对文件路径:允许用户执行一个基于当前位置的目标文件路径。
比如:当前在/usr/local
local ls
Caskroom Frameworks bin go lib sbin var
Cellar Homebrew etc include opt share
local cd go
快捷方式(在相对路径中使用):
单点符(.) : 表示当前目录; 双点符(..) : 表示当前目录的父目录。 8.迷路,我的当前位置在哪?
pwd 显示当前目录
[root@iz2ze76ybn73dvwmdij06zz local]# pwd
/usr/local
[attach]53352[/attach]
9.如何切换目录?
语法: cd destination
destination : 相对文件路径或绝对文件路径
可以跳到存在的任意目录。 10.如何查看目录中的文件?区分哪些是文件哪些是目录?递归查?
ls 命令会用最基本的形式显示当前目录下的文件和目录:
local ls
Caskroom Frameworks bin go lib sbin var
Cellar Homebrew etc include opt share
可以看出默认是按照字母序展示的
一般来说,ls命令回显示不同的颜色区分不同的文件类型,如果没有安装颜色插件可以用ls -F来区分哪些是目录(目录带/),哪些是文件(文件不带/)
ls -R 递归展示出目录下以及子目录的文件,目录越多输出越多。
[attach]53353[/attach]
11.创建文件?创建目录?批量创建?
创建文件:touch 文件名
批量创建文件: touch 文件名 文件名 …
test touch a
test ls
a
test touch b c
test ls
a b c
创建目录:mkdir 目录名
批量创建目录: mkdir 目录名 目录名 …
test mkdir aa
test mkdir bb cc
test ls
a aa b bb c cc
test ls -F
a aa/ b bb/ c cc/ 12.删除文件?强制删除?递归删除?
语法: rm destination
-i 询问是否删除,-r 递归删除,-f 强制删除。
rm不能删除有文件的目录,需要递归删除。
xktest rm jdk
rm: jdk: is a directory
xktest rm -r jdk
xktest ls
rm -i 询问删除,建议大家平时删除多用 -i,确定一下再删除。
xktest touch tomcat
xktest rm -i tomcat
remove tomcat? n
rm -rf 会直接删除,没有警告信息,使用必须谨慎**。
[attach]53354[/attach]
13.制表符自动补全?
有的时候文件的名字很长,很容易拼出错即使拼写对了也很浪费时间。
xktest ls java*
javaxiaokaxiu
比如操作javaxiaokaxiu这个文件时,输入到java的时候,然后按制表键(tab)就会补全成javaxiaokaxiu,是不是方便多了。 14.复制文件
语法: cp source target
如果target不存在则直接创建,如果存在,默认不会提醒你是否需要覆盖,需要加-i就会询问你是否覆盖,n否y是。
xktest cp a c
xktest cp -i a c
overwrite c? (y/n [n]) y
xktest ls
a c 15.重新命名文件?移动文件?
语法 : mv soucre target
重命名:
xktest ls
xktest touch java
xktest ls
java
xktest mv java java1.8
xktest ls
java1.8
移动文件:
新建jdk目录把java1.8文件移动到jdk目录下。
xktest ls
java1.8
xktest mkdir jdk
xktest mv java1.8 jdk
xktest ls -R
jdk
./jdk:
java1.8 16.什么是链接文件?
如过需要在系统上维护同一文件的两份或者多份副本,除了保存多分单独的物理文件副本之外。还可以采用保存一份物理文件副本和多个虚拟副本的方法,这种虚拟的副本就叫做链接。
[attach]53355[/attach]
17.查看文件类型?字符编码?
语法: file destination
apache file tomcat
tomcat: ASCII text
可以看出,file命令可以显示文件的类型text以及字符编码ASCII 18.查看整个文件?按照有文本显示行号?无文本显示行号?
语法 : cat destination
-n 显示行号,-b 有文本的显示行号。 (默认是不显示行号的)
apache cat -n tomcat
1 text
2 text
3
4 start
5 stop
6 restart
7 end
apache cat -b tomcat
1 text
2 text 19.查看部分文件
语法 : tail destination
默认情况会展示文件的末尾10行。 -n 行数,显示最后n行。
apache tail -n 2 tomcat
restart
end
语法: head destination
默认情况会展示文件的开头10行。 -n 行数,显示开头n行。
apache head -n 2 tomcat
text
text
[attach]53356[/attach]
24.Linux广泛使用的归档数据方法?
虽然zip命令能压缩和解压单个文件,但是更多的时候广泛使用tar命令来做归档。
语法: tar function [options] obj1 obj2
[attach]53359[/attach]
apache tar -cvf service.tar service1 service2 // 创建规定文件service.tar
a service1
a service2
apache tar -tf service.tar //查看文件中的目录内容
service1
service2
apache tar zxvf service.tar //解压
x service1
x service2 25.如何查看命令历史记录?
history 命令可以展示你用的命令的历史记录。
4463 touch service1 service2
4464 ls
4465 tar -cvf service.tar service1 service2
4466 tar -tf service.tar
4467 tar zxvf service
4468 tar zxvf service.t
4469 tar zxvf service.tar
4470 ls
4471 tar -zxvf service.tar
4472 ls 26.查看已有别名?建立属于自己的别名?
alias -p 查看当前可用别名
[root@iz2ze76ybn73dvwmdij06zz ~]# alias -p
alias cp='cp -i'
alias egrep='egrep —color=auto'
alias fgrep='fgrep —color=auto'
alias grep='grep —color=auto'
alias l.='ls -d .* —color=auto'
alias ll='ls -l —color=auto'
alias li = 'ls -li' 创建别名
[attach]53360[/attach]
48.如何用sed只打印第5行?删除第一行?替换字符串?
只打印第5行:
apache sed -n "5p" tomcat
stop
删除第一行:
[root@xiaoka ~]# cat story
Long ago a lion and a bear saw a kid.
They sprang upon it at the same time.
The lion said to the bear, “I caught this kid first, and so this is mine.”
[root@xiaoka ~]# cat story
They sprang upon it at the same time.
The lion said to the bear, “I caught this kid first, and so this is mine.”
替换字符串:
apache cat story
Long ago a lion and a bear saw a kid.
They sprang upon it at the same time.
The lion said to the bear, “I caught this kid first, and so this is mine.”
apache sed 's#this#that#g' story
Long ago a lion and a bear saw a kid.
They sprang upon it at the same time.
The lion said to the bear, “I caught that kid first, and so that is mine.” 49.打印文件第一行到第三行?
文件tomcat中内容:
apache cat tomcat
text21
text22
text23
start
stop
restart
end
apache head -3 tomcat
text21
text22
text23
apache sed -n '1,3p' tomcat
text21
text22
text23