1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 7 .Linux文件目录类——pwd ls cd mkdir rmdir touch cp rm mv cat more

7 .Linux文件目录类——pwd ls cd mkdir rmdir touch cp rm mv cat more

时间:2018-10-30 19:40:17

相关推荐

7 .Linux文件目录类——pwd ls cd mkdir rmdir touch cp rm mv cat more

1. pwd 指令

基本语法 pwd (功能描述:显示当前工作目录的绝对路径)

注意:绝对路径可以简单的认为从根目录开始定位

相对路径从当前位置开始定位

[root@wangweicentos test]# pwd/home/test

2. ls 指令

基本语法 ls 【选项】【目录或者是文件】

常用选项:-a 显示当前目录所有的文件和目录,包括隐藏的

-l 以列表的方式显示信息

3. cd 指令

基本语法:cd 【参数】 ( 功能描述:切换到指定目录)

理解:绝对路径和相对路径

cd ~ 或者 cd 回到自己的家目录,比如你是 root cd ~ 回到 /root

cd .. 回到当前目录的上一级目录

例子:

1)使用绝对路径切换到 root 目录,cd /root

2)使用相对路径到 /root 目录,比如在 /home/tom cd ../../root

4. mkdir 指令

mkdir 指令用于创建目录

基本语法:mkdir 【选项】 要创建的目录 (只能默认创建一级目录)

常用选项: -p 创建多级目录

[root@wangweicentos /]# mkdir -p /home/animal/dog[root@wangweicentos /]# cd /home[root@wangweicentos home]# lsanimal mydate.txt test wangwei[root@wangweicentos home]# cd animal[root@wangweicentos animal]# lsdog

5. rmdir 指令

rmdir 指令删除空目录

基本语法:rmdir 【选项】要删除的空目录

注意:rmdir 删除的是空目录,如果文件下有内容时无法删除

如果非要删除非空目录,需要使用 rm -rf 要删除的目录

[root@wangweicentos animal]# cd /home[root@wangweicentos home]# lsanimal mydate.txt test wangwei[root@wangweicentos home]# rm -rf animal[root@wangweicentos home]# lsmydate.txt test wangwei

6. touch 指令

touch 指令创建空文件

基本语法: touch 文件名称

7. cp 文件

cp 指令拷贝文件到指定目录

基本语法: cp 【选项】source dest 即 cp 拷贝的哪个文件 把文件拷贝到哪个地方

[root@wangweicentos ~]# cd /home[root@wangweicentos home]# cp hello.txt bbb[root@wangweicentos home]# lsbbb hello.txt mydate.txt test wangwei[root@wangweicentos home]# cd bbb[root@wangweicentos bbb]# lshello.txt

常用选项: -r 递归复制整个文件夹

强制覆盖不提示的方法: \cp

[root@wangweicentos bbb]# cd /home[root@wangweicentos home]# lsbbb hello.txt mydate.txt test wangwei[root@wangweicentos home]# cp -r bbb test[root@wangweicentos home]# cd test[root@wangweicentos test]# lsbbb tangshi.txt[root@wangweicentos test]# cd /home[root@wangweicentos home]# \cp bbb testcp: omitting directory ‘bbb’[root@wangweicentos home]# \cp -r bbb test[root@wangweicentos home]#

8. rm 指令

说明:rm 指令移除文件或目录

基本用法: rm 【选项】要删除的文件或目录

常用选项: -r 递归删除整个文件夹

-f 强制删除文件不提示 【小心使用】

9. mv 指令

mv 移动文件与目录或者重命名

基本语法: mv oldNameFile newNameFile (功能描述:重命名)前提是在同一个目录下

mv /temp/movefile /targetFolder (功能描述:移动文件)

[root@wangweicentos test]# cd ..[root@wangweicentos home]# lshello.txt mydate.txt test wangwei[root@wangweicentos home]# mv hello.txt /rootmv: overwrite ‘/root/hello.txt’? y[root@wangweicentos home]# lsmydate.txt test wangwei

10. cat 指令

cat 查看文件内容 (更安全)

基本语法:cat 【选项】要查看的文件

常用选项:-n 显示行号

使用细节: cat 只能浏览文件,而不能修改文件,为了浏览方便,一般会带上管道命令 |more

(管道命令:把前面得到的结果交给下一个指令来处理)

[root@wangweicentos ~]# cat /etc/profile | more# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# Path manipulationif [ "$EUID" = "0" ]; thenpathmunge /usr/sbinpathmunge /usr/local/sbinelsepathmunge /usr/local/sbin after--More--

11. more指令

more 指令是一个基于vi编辑器的文本过滤器,它以全屏幕的方式按页显示文本文件的内容,more指令中内置了若干快捷键(交互指令),详见操作说明。

基本语法:more 要查看的文件

12. less 指令

基本语法:less 要查看的文件

less指令用来分屏查看文件内容,它的功能与 more 相似,但是她比 more 指令功能更强大,支持各种显示终端,less指令在显示的文件内容时,并不是一次将整个文件加载之后才显示,而是根据显示需要 加载内容,对于显示大型文件具有较高的效率。

13. echo 指令

echo 输出内容到控制台,即终端。

基本语法: echo [选项][输出内容]

例如:使用 echo 指令输出环境变量:

[root@wangweicentos ~]# echo $HOSTNAMEwangweicentos[root@wangweicentos ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[root@wangweicentos ~]#

14. head 指令

head 用于显示文件的开头部分内容,默认情况下 head 指令显示文件的前十行内容。

基本语法:

head 文件 (功能描述:查看文件头10行内容)

head -n 5 文件 (功能描述:查看文件头5行内容,5可以是任意数)

例如:查看 /etc/profile 的前5行代码

[root@wangweicentos ~]# head -n 5 /etc/profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc

15. tail 指令

tail 指令用于输出文件中尾部的内容,默认情况下 tail 指令显示文件的尾10行内容。

基本语法:

1)tail 文件 (功能描述:查看文件尾 10 行内容)

2)tail -n 5 文件(功能描述:查看文件尾5行的内容,5可以是任意数)

3)tail -f 文件 (功能描述:实时追踪该文档的所有更新)

16.>指令和 >>指令

> 输出重定向和 >> 追加

基本语法:

1)ls -l > 文件 (功能描述:列表的内容写入文件a.txt中 (覆盖写))

2)ls -al >> 文件 (功能描述:列表的内容追加到文件 aa.txt 的末尾)

3)cat 文件1>文件2 (功能描述:将文件1中的内容覆盖到文件2)

4)echo "内容" >> 文件(追加)

例子:

(1)将 /home 目录下的文件列表写入到 /home/info.txt 中,覆盖写入。【如果info.txt 没有,则会创建】

ls -l /home > /home/info.txt

(2)将当前日历信息追加到 /home/mycal 文件中

cal >> /home/mycal

(7.15 7.16 举例)

17. ln 指令

软链接也称为符号链接,类似于 windows 里的快捷方式,主要存放了链接其他文件的路径。

基本语法:

ln -s [原文件或目录][软连接名] (功能描述:给原文件创建一个软链接)

应用实例:

(1)在 /home 目录下创建一个软链接 myroot ,连接到 /root 目录

ln -s /root /home/myroot

(2)删除软链接 myroot

rm /home/myroot

18. history 指令

查看已经执行过的历史命令,也可以执行历史指令。

基本语法:

history (功能描述:查看已经执行过的历史命令)

应用实例:

(1)显示最近使用过的10个指令。 history 10

(2)执行历史编号为 5 的指令。!5

7 .Linux文件目录类——pwd ls cd mkdir rmdir touch cp rm mv cat more less echo head tail > 重定向 >> 追加 history

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。