接着书接上回,我们继续文件操作命令的其他操作。
(3)cp:copy,复制命令
<1>命令的格式:cp [选项] 源文件 目标文件
<2>cp可以做到复制,粘贴的时候重命名, 注意:copy的时候,一定要注意使用绝对路径还是相对路径。
<3>参数

(4)mv:move,移动文件或目录
<1>剪切操作不同于复制操作,因为它会把源文件删除掉,只保留剪切后的文件。如果在同一个目录中将某个文件剪切后还粘贴到当前目录下,其实本质就是对文件进行了重命名操作,操作示例如下:

我们从图中可以看到,对test进行mv操作之后,test被我们要求替换成的test1所替代。
(5)rm:remove,删除文件或者目录
<1>格式:rm [选项] 文件或目录名及路径 。
<2>功能:删除文件或目录,可包含一个或多个文件名(各文件间用空格分隔)或用通配符表达,以实现删除多个文件或目录。
<3>参数:

示例如下:
[root@bogon gousheng]# rm -r test1 我们在这里递归的删除了test1目录树
rm: descend into directory 'test1'?y 此下都为系统的确认删除提示,若要系统直接删除不提示,可-rf连用。
rm: descend into directory 'test1/test1'? y
rm: descend into directory 'test1/test1/test2'? y
rm: descend into directory 'test1/test1/test2/test3'? y
rm: remove regular empty file 'test1/test1/test2/test3/file1'? y
rm: remove regular empty file 'test1/test1/test2/test3/file3'? y
rm: remove directory 'test1/test1/test2/test3'? y
rm: remove directory 'test1/test1/test2'? y
rm: remove directory 'test1/test1'? y
rm: remove directory 'test1'? y
(5)ln:link,为文件或目录建立链接。
<1>命令格式: ln [选项] 被链接的源文件或目录 链接文件或目标目录。
<2>选项:
-s:建立符号链接(软链接),不加该选项时为硬链接。
-f:删除已经存在的目标文件与源文件之间的链接关系。
-i:交互式的删除目标文件与源文件之间的链接关系。
<3>硬链接与软链接的异同点:

【9】Vim文本编译器:相当于windows中的记事本,可以进行编程,文版编辑等操作。
(1)三种模式:1.命令模式:控制光标移动,可对文本进行复制粘贴,删除查找等工作。
2.输入模式:正常的文本录入。
3.末行模式:保存或退出文档,以及设置编辑环境。
以下为三者的切换方式:

(2)操作按键

(3)命令模式基本操作
<1>文件内容查找

<2> 撤销编辑及保存

(3)末行模式基本操作
<1>保存并退出

<2>打开新文件或读入其他文件

<3>文件内容替换

【10】pipe:管道文件
(1)管道文件的作用:传输,起到了连接作用
(2)管道符:|,管道就是由若干条“|”隔开的命令序列。
注:前后两个管道符的关系-前一个命令的输出,使用管道符,作为后一个管道符的输入。
(3)管道符输入格式:command1 | command2 | command3 ....
管道符使用示例:
<1>echo "123" 输出到屏幕上,是标准输出
<2>cat data.txt # 原先输出在屏幕上
cat data.txt | more # cat data.txt 原先输出在屏幕上的内容,通过管道符|传递给more命令,作为more命令的输入
more命令:文件内容浏览: 分页浏览,按页去展示(按空格跳转下一页,按q退出,也可以进行搜索/)
【11】tee命令
(1)用于读取标准输入的数据,并将其内容输出成文件
(2)语法:tee [-ai][--help][--version][文件...]
(3)参数:

下面一道练习来复习以上内容:
1.创建目录test
( 1). 使用两种方式在test目录中创建文本文件text1.txt, text2.txt
使用Vim在文件text1.txt中写入
Welcome to my Linux.
You are the best.
This is my first file to create on linux
设置行号,并将文本中my替换成your,将文件另存为new_test1.txt
(2) 将test中的文件拷贝到test2目录
将test2目录中的test1.txt重命名为test111.txt
在test2目录中新建test111.txt的软链接文件 test111_symb.txt
在test2目录中新建test111.txt的硬链接文件 test111_hard.txt
删除test目录中test1.txt
删除test目录
(3)将echo "This is my first time to use pipe"内容输出到屏幕上,且保存到pipe_data.txt中
(4)文件内容浏览
a.cat查看/etc/passwd文件内容,且输出时带行号
b.使用more/less查看/etc/passwd内容,且每页显示10行
c.使用head/tail分别查看文件前5行内容和后5行内容
答案:(1)
[root@localhost gousheng]# mkdir test 创建文件夹test
[root@localhost gousheng]# cd test 进入文件夹test
[root@localhost test]# touch test1.txt test2.txt 在test中创建test1.txt test2.txt
[root@localhost test]# vim test1.txt 进入test1的vim编译器,在打入要求的三行文字后,点击esc并输入冒号进入设置模式,输入set nu(显示行数)

将文本中所有的my全部替换成your。

保存并退出test1.txt

(2)
[root@localhost gousheng]# mkdir test2 创建test2文件夹
[root@localhost gousheng]# cp -a test test2 保留test将文件拷贝到test2
[root@localhost gousheng]# cd test2 进入test2
[root@localhost test2]# ls 查看test2中文件
test
[root@localhost test2]# cd test 进入test2中拷贝的test
[root@localhost test]# ls 查看其中文件
test1.txt test2 test2.txt
[root@localhost test]# mv test1.txt test111.txt 将test1.txt更名为 test111.txt
[root@localhost test]# ls 查看设置成功
test111.txt test2 test2.txt
[root@localhost test]# ln -s test111.txt test111_symb.txt 设置软文件链接
[root@localhost test]# ls 成功
test111_symb.txt test111.txt test2.txt
[root@localhost test]# ln test111.txt test111_hard.txt 设置硬链接文件
[root@localhost test]# ls 成功
test111_hard.txt test111_symb.txt test111.txt test2.txt 设置软链接文件
[root@localhost gousheng]# rm -rf test 之间删除先前复制的源文件 /test
(3)
[root@localhost ~]# echo "This is my first time to use pipe" |tee pipe_data.txt
This is my first time to use pipe 使用管道符,将上面的话输出在屏幕上并保存
[root@localhost ~]# ls
anaconda-ks.cfg file1 file2 initial-setup-ks.cfg pipe_data.txt test1
[root@localhost ~]# cat pipe_data.txt 查看后成功
This is my first time to use pipe
(4)
使用cat-n命令,显示行号
[root@bogon gousheng]# more -10 /etc/passwd 设定more每次显示的行数
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@bogon gousheng]# head -5 /etc/passwd 显示前五行或后五行
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@bogon gousheng]# tail -5 /etc/passwd
gnome-initial-setup:x:979:977::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
gousheng:x:1000:1000:gousheng:/home/gousheng:/bin/bash
未完接着待续
2528



被折叠的 条评论
为什么被折叠?



