【Linux】作业03

在这里插入图片描述

  1. 创建目录test
[root@localhost ~]# ls
 anaconda-ks.cfg   Desktop   Documents   Downloads   F1  'index.html?id=508944'   Music   original-ks.cfg   Pictures   Public   Templates   Videos
[root@localhost ~]# mkdir test
[root@localhost ~]# ls
 anaconda-ks.cfg   Documents   F1                      Music             Pictures   Templates   Videos
 Desktop           Downloads  'index.html?id=508944'   original-ks.cfg   Public     test
[root@localhost ~]# 
  • 使用两种方法创建文本文件 test1.txt,test2.txt文件
//1.使用touch命令
[root@localhost ~]# cd test
[root@localhost test]# touch test1.txt test2.txt
[root@localhost test]# ls
test1.txt  test2.txt
[root@localhost test]# 
//2. 使用vim命令

[root@localhost ~]# vim test1.txt  //进入vim 文本编辑器,按a,i,o,任意一键进入编辑模式
//输入要求的文本内容
welcome to my Linux!
you are best!
this is my first file to create my Linux                                                                                                                             
                                                                                                                            
-- INSERT --    
/*
在输入模式下按ESC退回命令行模式,再按 :进入末行模式
输入set nu 设置行号
*/                                                                                         
  1 welcome to my Linux!
  2 you are best!
  3 this is my first file to create my Linux!
~                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                              
:set nu

/*
在末行模式下输入 :% s/my/your/g 可以将 全文的 my 全部替换为 your
*/
  1 welcome to your Linux!
  2 you are best!
  3 this is your first file to create your Linux!
~        

/*
在末行模式下输入 :w new_test1.txt 可以另存为其他文件
*/      

[root@localhost test]# ls
new_test1.txt  test1.txt
                                    

在这里插入图片描述
在根目录下创建test2目录

[root@localhost ~]# mkdir test2
[root@localhost ~]# ls
 anaconda-ks.cfg   Documents   F1                      Music             P
 Desktop           Downloads  'index.html?id=508944'   original-ks.cfg

//将test中的文件复制到test2中,并将test1.TXT重命名为test111.txt
[root@localhost test]# cp test1.txt /root/test2/test111.txt
[root@localhost test]# cp test2.txt /root/test2/

[root@localhost test2]# ls
test111.txt  test2.txt

//在test2目录中建立test111.txt的硬链接文件test111_symb.tx
//在test2目录中建立test111.txt的软链接文件test111_hard.txt
[root@localhost test2]# ln test111.txt test111_symb.txt
[root@localhost test2]# ln -s test111.txt test111_hard.txt

 [root@localhost test2]# ls -l
total 0
lrwxrwxrwx. 1 root root 11 Apr 11 10:27 test111_hard.txt -> test111.txt
-rw-r--r--. 2 root root  0 Apr 11 10:05 test111_symb.txt
-rw-r--r--. 2 root root  0 Apr 11 10:05 test111.txt
-rw-r--r--. 1 root root  0 Apr 11 10:09 test1.txt
-rw-r--r--. 1 root root  0 Apr 11 10:01 test2.txt 

//删除test目录中的test1.txt文件
[root@localhost test]# rm test1.txt
rm: remove regular empty file 'test1.txt'? y
[root@localhost test]# ls
test2.txt
[root@localhost test]# 

//删除目录test
[root@localhost ~]#  rm -rf test
[root@localhost ~]# ls
 anaconda-ks.cfg   Documents   F1                      Music             Pictures   Templates   Videos
 Desktop           Downloads  'index.html?id=508944'   original-ks.cfg   Public     test2
[root@localhost ~]# 

  1. 将echo “this is my first time to use pipe” 内容输出到屏幕上,且保存到pipe_data.txt中
[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   Documents   F1                      Music             Pictures        Public      test    Videos
 Desktop           Downloads  'index.html?id=508944'   original-ks.cfg   pipe_data.txt   Templates   test2
[root@localhost ~]# 

在这里插入图片描述

//a. 使用 cat -a 命令带行显示
[root@localhost ~]# cat -n /etc/passwd
     1	root:x:0:0:root:/root:/bin/bash
     2	bin:x:1:1:bin:/bin:/sbin/nologin
     3	daemon:x:2:2:daemon:/sbin:/sbin/nologin
     4	adm:x:3:4:adm:/var/adm:/sbin/nologin
     5	lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
     6	sync:x:5:0:sync:/sbin:/bin/sync
     7	shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
     8	halt:x:7:0:halt:/sbin:/sbin/halt
[root@localhost ~]# 

// b. 使用 more 命令 最多显示10行
[root@localhost ~]# cat -n /etc/passwd | more -10
     1	root:x:0:0:root:/root:/bin/bash
     2	bin:x:1:1:bin:/bin:/sbin/nologin
     3	daemon:x:2:2:daemon:/sbin:/sbin/nologin
     4	adm:x:3:4:adm:/var/adm:/sbin/nologin
     5	lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
     6	sync:x:5:0:sync:/sbin:/bin/sync
     7	shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
     8	halt:x:7:0:halt:/sbin:/sbin/halt
     9	mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    10	operator:x:11:0:operator:/root:/sbin/nologin

//c. 查看前5行和后五行内容
// 前五行
[root@localhost ~]# cat -n /etc/passwd | head -5
     1	root:x:0:0:root:/root:/bin/bash
     2	bin:x:1:1:bin:/bin:/sbin/nologin
     3	daemon:x:2:2:daemon:/sbin:/sbin/nologin
     4	adm:x:3:4:adm:/var/adm:/sbin/nologin
     5	lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@localhost ~]# 
//后五行
[root@localhost ~]# cat -n /etc/passwd | tail -5
    44	sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    45	avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
    46	rngd:x:975:973:Random Number Generator Daemon:/var/lib/rngd:/sbin/nologin
    47	tcpdump:x:72:72::/:/sbin/nologin
    48	xuan:x:1000:1000:xuan:/home/xuan:/bin/bash
[root@localhost ~]# 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值