Linux基础之vim

目录

一.创建目录test   

1、使用两种方式在test目录中创建文本文件text1.txt, text2.txt

2、使用Vim在文件text1.txt中写入       Welcome to my Linux.       You are the best.       This is my first file to create on linux

3、设置行号,并将文本中my替换成your,将文件另存为new_test1.txt

4、将test中的文件拷贝到test2目录

5、将test2目录中的test1.txt重命名为test111.txt

6、在test2目录中新建test111.txt的软链接文件 test111_symb.txt

7、在test2目录中新建test111.txt的硬链接文件 test111_hard.txt

8、  删除test目录中test1.txt, 删除test目录   

二.将echo "This is my first time to use pipe"内容输出到屏幕上,且保存到pipe_data.txt中

三.文件内容浏览 

  a.cat查看/etc/passwd文件内容,且输出时带行号

  b.使用more/less查看/etc/passwd内容,且每页显示10行

  c.使用head/tail分别查看文件前5行内容和后5行内容


 

一.创建目录test
   

[root@Gur ~]# mkdir test
[root@Gur ~]# ls
anaconda-ks.cfg  Downloads  file3           initial-setup-ks.cfg  Pictures    test
date.txt         exit       first_text.txt  link_test             Public      video_1750965
Desktop          file1      index.html      Music                 result.txt  Videos
Documents        file2      index.html.1    parent                Templates

1、使用两种方式在test目录中创建文本文件text1.txt, text2.txt

[root@Gur ~]# cd test
[root@Gur test]# touch test1.txt
[root@Gur test]# touch test2.txt
[root@Gur test]# vim test1.txt
[root@Gur test]# vim test2.txt
[root@Gur test]# ls
test1.txt  test2.txt

 

2、使用Vim在文件text1.txt中写入
       Welcome to my Linux.
       You are the best.
       This is my first file to create on linux

[root@Gur test]# cat test1
cat: test1: No such file or directory
[root@Gur test]# cat test1.txt
 Welcome to my Linux.
       You are the best.
       This is my first file to create on linux

3、设置行号,并将文本中my替换成your,将文件另存为new_test1.txt

  1  Welcome to my Linux.
  2        You are the best.
  3        This is my first file to create on linux
~                                                                                                                                                                                                 
 :set nu

  1  Welcome to your Linux.
  2        You are the best.
  3        This is your first file to create on linux
~                                                                                                  
                                                                                                                                                                                                 
:% s/my/your/g 

  1  Welcome to your Linux.
  2        You are the best.
  3        This is your first file to create on linux
~                                                                                                                                                                                                  
"~/test/new_test1.txt" [New] 3L, 108C written 

4、将test中的文件拷贝到test2目录

[root@Gur ~]# cp -a test test2

5、将test2目录中的test1.txt重命名为test111.txt

[root@Gur test]# mv test1.txt test111.txt
[root@Gur test]# ls
new_test1.txt  test111.txt  test2.txt

6、在test2目录中新建test111.txt的软链接文件 test111_symb.txt

[root@Gur test]# ln -s test111.txt test111_symb.txt
[root@Gur test]# ls
new_test1.txt  test111_symb.txt  test111.txt  test2.txt

7、在test2目录中新建test111.txt的硬链接文件 test111_hard.txt

[root@Gur test]# ln test111.txt test111_hard.txt
[root@Gur test]# ls
new_test1.txt  test111_hard.txt  test111_symb.txt  test111.txt  test2.txt

8、  删除test目录中test1.txt, 删除test目录

[root@Gur ~]# cd /root/test/
[root@Gur test]# rm -rf test1.txt
[root@Gur test]# cd ~
[root@Gur ~]# rm -rf test
[root@Gur ~]# ls
anaconda-ks.cfg  Downloads  file3           initial-setup-ks.cfg  Pictures    test2
date.txt         exit       first_text.txt  link_test             Public      video_1750965
Desktop          file1      index.html      Music                 result.txt  Videos
Documents        file2      index.html.1    parent                Templates

二.将echo "This is my first time to use pipe"内容输出到屏幕上,且保存到pipe_data.txt中

[root@Gur ~]# echo "This is my first time to use pipe" | tee pipe_data.txt
This is my first time to use pipe
[root@Gur ~]# ls
anaconda-ks.cfg  Downloads  file3           initial-setup-ks.cfg  Pictures       Templates
date.txt         exit       first_text.txt  link_test             pipe_data.txt  test2
Desktop          file1      index.html      Music                 Public         video_1750965
Documents        file2      index.html.1    parent                result.txt     Videos


三.文件内容浏览

  a.cat查看/etc/passwd文件内容,且输出时带行号

[root@Gur ~]# 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
     9	mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    10	operator:x:11:0:operator:/root:/sbin/nologin
    11	games:x:12:100:games:/usr/games:/sbin/nologin
    12	ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
    13	nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
    14	dbus:x:81:81:System message bus:/:/sbin/nologin
    15	systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
    16	systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
    17	tss:x:59:59:Account used for TPM access:/dev/null:/sbin/nologin
    18	polkitd:x:998:996:User for polkitd:/:/sbin/nologin
    19	geoclue:x:997:995:User for geoclue:/var/lib/geoclue:/sbin/nologin
    20	rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
    21	pipewire:x:996:992:PipeWire System Daemon:/var/run/pipewire:/sbin/nologin
    22	pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
    23	qemu:x:107:107:qemu user:/:/sbin/nologin
    24	clevis:x:995:989:Clevis Decryption Framework unprivileged user:/var/cache/clevis:/sbin/nologin
    25	usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
    26	unbound:x:994:988:Unbound DNS resolver:/etc/unbound:/sbin/nologin
    27	gluster:x:993:987:GlusterFS daemons:/run/gluster:/sbin/nologin
    28	rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
    29	avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
    30	chrony:x:992:986::/var/lib/chrony:/sbin/nologin
    31	setroubleshoot:x:991:984::/var/lib/setroubleshoot:/sbin/nologin
    32	saslauth:x:990:76:Saslauthd user:/run/saslauthd:/sbin/nologin
    33	libstoragemgmt:x:989:983:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
    34	dnsmasq:x:981:981:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/sbin/nologin
    35	radvd:x:75:75:radvd user:/:/sbin/nologin
    36	sssd:x:980:980:User for sssd:/:/sbin/nologin
    37	cockpit-ws:x:979:979:User for cockpit web service:/nonexisting:/sbin/nologin
    38	cockpit-wsinstance:x:978:978:User for cockpit-ws instances:/nonexisting:/sbin/nologin
    39	flatpak:x:977:977:User for flatpak system helper:/:/sbin/nologin
    40	colord:x:976:976:User for colord:/var/lib/colord:/sbin/nologin
    41	rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
    42	gdm:x:42:42::/var/lib/gdm:/sbin/nologin
    43	gnome-initial-setup:x:975:975::/run/gnome-initial-setup/:/sbin/nologin
    44	tcpdump:x:72:72::/:/sbin/nologin
    45	sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    46	Gur:x:1000:1000:Gur:/home/Gur:/bin/bash

  b.使用more/less查看/etc/passwd内容,且每页显示10行

[root@Gur ~]# more -10 /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
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
--More--(15%)

  c.使用head/tail分别查看文件前5行内容和后5行内容

[root@Gur ~]# 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@Gur ~]# tail -5 /etc/passwd
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:975:975::/run/gnome-initial-setup/:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
Gur:x:1000:1000:Gur:/home/Gur:/bin/bash

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gur.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值