Linux基本命令练习

Linux基本命令练习

  1. 在你的家目录中,创建若干空文件。创建 6 个空文件 song1.mp3~song6.mp3;创建 6 个空文件
    snap1.jpg~snap6.jpg;创建 6 个空文件 film1.avi~film6.avi
[root@localhost ~]# mkdir song{1..6}.mp3
[root@localhost ~]# mkdir snap{1..6}.jpg film{1..6}.avi
  1. 将 mp3 文件移动到"音乐"目录,将 jpg 文件移动到"图片"目录,将 avi 文件移动到"视 频"目录

    [root@localhost ~]# mkdir 音乐 图片 视频
    [root@localhost ~]# mv *.avi 视频
    [root@localhost ~]# mv *.jpg 图片
    [root@localhost ~]# mv *.mp3 音乐
    
  2. 在你的家目录中创建三个空目录,分别为 friends,family 和 work。

    [root@localhost ~]# mkdir {friends,family,work}
    
  3. 将刚才创建的 mp3,jpg 和 avi 文件,1、2 号复制到 friends 目录中,3、4 号复制到 family 目录
    中,5、6 号复制到 work 目录中。

[root@localhost ~]# cp 图片/snap{1..2}.jpg  视频/film{1..2}.avi  音乐/song{1..2}.mp3 friends/
[root@localhost ~]# cp 图片/snap{3,4}.jpg  视频/film{3,4}.avi  音乐/song{3,4}.mp3 family/
[root@localhost ~]# cp 图片/snap{5,6}.jpg  视频/film{5,6}.avi  音乐/song{5,6}.mp3 work/
  1. 回到你的家目录,尝试使用 rmdir 命令同时删除 family 和 friends 目录。

    rmdir 不能删除,只能删除空目录
    
  2. 尝试使用 rm 命令同时删除 family 和 friends 目录。

    [root@localhost ~]# rm -rf family/ friends/
    
  3. 删除 work 目录下的内容,但不要删除 work 目录本身。

    [root@localhost ~]# cd work/
    [root@localhost work]# rm -f *
    
  4. 使用 rmdir 命令删除空目录 work

    [root@localhost ~]# rmdir work/
    
  5. 创建 12 个空文件,命名规则为 tv_seasonX_episodeY.ogg,X 的取值范围为 1~2,Y 的 取值范围
    为 1~6。

    [root@localhost ~]# touch tv_season{1..2}_episode{1..6}.ogg
    
  6. 创建 8 个空文件,命名规则为 mystery_chapterX.odf,X 的取值范围为 1~8。

    [root@localhost ~]# touch mystery_chapter{1..8}.odf
    
  7. 在家目录的“视频”目录中创建两个子目录 season1 和 season2

    [root@localhost ~]# mkdir 视频/season1 视频/season2
    
  8. 移动刚才创建的 tv_season1 开头的文件到“视频/season1”目录中。tv_season2 开 头的文件到“视
    频/season2”目录中。

    [root@localhost ~]# mv tv_season1* 视频/season1 tv_season2* 视频/season2
    
  9. 使用一条命令在家目录的“文档”目录中创建 my_bastseller 目录,并在 my_bastseller 目录中创建
    chapters 目录

    [root@localhost ~]# mkdir my_bastseller/chapters -p
    
  10. 使用一条命令在刚才创建的 my_bastseller 目录中创建 editor,plot_change,vacation 三个子目录。

    [root@localhost my_bastseller]# mkdir {editor,plot_change,vacation}
    
  11. 切换到 chapters 目录中,并将家目录中所有 mystery_chapter 开头的文件复制到其 中。

    [root@localhost my_bastseller]# cp /root/my_bastseller/mystery_chapter* chapters/
    
  12. 接上一题,将刚复制过来的 mystery_chapter 文件中的前两个文件移动到 editor 目录 中,使用相
    对路径。

    [root@localhost chapters]# mv mystery_chapter{1,2}.odf ../editor/
    
  13. 将复制到 chapters 目录中的 mystery_chapter 文件中的 7、8 号文件移动到 vacation 目录中,用
    一条命令完成。

    [root@localhost my_bastseller]# mv chapters/mystery_chapter{7,8}.odf vacation/
    
  14. 统计/boot目录大小,以M为单位显示

    [root@localhost /]# du -h /boot
    
  15. 查看系统中 cpu 的信息。

    [root@localhost /]# cat /proc/cpuinfo 
    
  16. 使用分页查看/var/log/messages 文件

    [root@localhost /]# more /var/log/messages 
    
  17. 查看/var/log/messages 文件最后 10 条记录

    [root@localhost ~]# tail /root/abc.cfg 
    
二、vim编辑器练习
  1. 复制/etc/ssh/sshd_config文件到你的家目录里面,并改名为test_config

    [root@localhost ~]# cp /etc/ssh/sshd_config test_config
    
  2. 使用vim打开test_config文件

    [root@localhost ~]# vim test_config 
    
  3. 在第二行中输入:#this is a vim test

    vim test_config
    o键
    2 #       this is a vim test
    
  4. 将1-6行中的sshd替换成SSHD

    :1,6 s/sshd/SSHD/g
    
  5. 将所有的ssh替换成SSH

    :% s/ssh/SSH/g
    
  6. 将文件另存为test2_config

    :w test2_config
    
  7. 不保存退出文件

    :q!
    
  8. 将/boot/grub2/grub.cfg复制到/root目录下,并改名为abc.cfg

    [root@localhost ~]# cp /boot/grub2/grub.cfg /root/abc.cfg
    
  9. 使用vim编辑abc.cfg

    [root@localhost ~]# vim /root/abc.cfg
    
  10. 设置显示行号

    :set nu
    
  11. 将光标定位到第20行

    20G
    
  12. 复制5行内容,并将其粘贴到文本末尾

    复制5行:5yy
    到文本末尾:G
    粘贴:p
    
  13. 光标快速跳转到第30行,删除当前行

    30G
    dd  #删除光标所在的当前行
    
  14. 删除当前光标出下3行内容

    3dd  #删除3行内容
    
  15. 复制当前光标处一下5行内容,将其粘贴到文本最开始位置

    5yy  #复制5行内容
    gg   #将光标移动到文件首行
    p    #粘贴内容
    
  16. 查找文本中的kernel关键字

    /kernel
    
  17. 移动光标到文本末尾,自下而上查找grub.d关键字

    ?kernrl
    
  18. 取消行号

    :set nonu
    
  19. 保存退出

    :wq    :x
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值