Linux常用操作练习题:

0.用cat显示/etc/passwd,并显示行号

[root@rhcsa001 ~]# cat -n /etc/passwd

1. 统计/etc/passwd文件的行数

[root@rhcsa001 ~]# wc -l /etc/passwd

2.将/etc/passwd文件中的前20行重定向保存到/hoem下改名20_pass.txt

[root@rhcsa001 ~]# head -n 20 /etc/passwd >> /home/20_pass.txt

3.在当前目录下创建空文件夹/web/test1

[root@rhcsa001 ~]# mkdir -p ./web/test1
[root@rhcsa001 ~]# tree
.
└── web
    └── test1

2 directories, 0 files

4.查看当前工作目录的命令

[root@rhcsa001 ~]# pwd
[root@rhcsa001 ~]# echo $PWD

5.将/tmp下的文件file1复制到当前目录下,文件名仍为file1

[root@rhcsa001 ~]# cp -r /tmp/file1 ./

6. 将文件file复制成file1

[root@rhcsa001 ~]# cp file ./file1
[root@rhcsa001 ~]# ls
 file  file1

7. 显示环境变量path,将/root加入到$PATH中

[root@rhcsa001 ~]# echo $PATH
/root/.local/bin:/root/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
[root@rhcsa001 ~]# export PATH=$PATH:/root
[root@rhcsa001 ~]# echo $PATH
/root/.local/bin:/root/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/root

7. 拷贝文件/etc/passwd到/tmp目录下

[root@rhcsa001 ~]# cp /etc/passwd /tmp
[root@rhcsa001 ~]# cd /
[root@rhcsa001 /]# cd tmp/
[root@rhcsa001 tmp]# ls
 passwd

8. 查看/tmp/目录的使用空间

[root@rhcsa001 ~]# du -h /tmp

9. 删除空目录dir1

[root@rhcsa001 ~]# rm -rfv dir1/

10. 将/root下的所有文件删除

[root@rhcsa001 ~]# rm -rfv *

10. 删除当前目录下子目录dir中的文件file

[root@rhcsa001 ~]# tree
.
└── dir
    └── file

1 directory, 1 file

[root@rhcsa001 ~]# rm -rfv ./dir/file 

11. 将目录dir1设定成任何人皆有读取及执行的权利,但只有拥有者可作写修改

12. 在/下建立目录test,在test建立文件1.txt和2.txt,分别在文件1.txt和2.txt中输入 :                    “I am chinese”,“are you ok?”

[root@rhcsa001 ~]# cd /
[root@rhcsa001 /]# mkdir test

[root@rhcsa001 /]# cd ./test/
[root@rhcsa001 test]# echo "I am Chinese" >> 1.txt
[root@rhcsa001 test]# echo "Are you OK?" >> 2.txt
[root@rhcsa001 test]# ls
1.txt  2.txt
[root@rhcsa001 test]# cat 1.txt 
I am Chinese
[root@rhcsa001 test]# cat 2.txt 
Are you OK?

 13. 在当前目录下新建一个名称为a.txt的文件,并在文件里面输入如下内容:
Hello Linux!  
Jishou university!  

[root@rhcsa001 ~]# touch a.txt
[root@rhcsa001 ~]# vim a.txt 
进入命令模式
按i键,进入插入模式进行文本编辑
:wq!进入底行模式并进行保存退出

[root@rhcsa001 ~]# cat a.txt 
Hello Linux!
Jishou university!

13. 在/etc/passwd文件中查找所有以“root”开头的文件

[root@rhcsa001 ~]# vim /etc/passwd
进入文件后,进入末行模式输入 :/root

14. 在dir1目录中建立一个空文件file1

[root@rhcsa001 dir1]# touch file1
[root@rhcsa001 ~]# tree
.
└── dir1
    └── file1

1 directory, 1 file

16. 创建用户win1,UID、GID等均按默认

17. 创建用户win2,默认主目录为/think,其余默认

18. 用cat命令将file1、file2、file3合并为文件filenew

[root@rhcsa001 ~]# cat file1 file2 file3
 hello_word
 welcome_come_to_linux
 this_is_a_new_word

[root@rhcsa001 ~]# cat file1 file2 file3 >>filenew
[root@rhcsa001 ~]# cat filenew 
 hello_word
 welcome_come_to_linux
 this_is_a_new_word

21. 将目录dir1改名为dir2

[root@rhcsa001 ~]# mkdir dir1
[root@rhcsa001 ~]# ls
dir1
[root@rhcsa001 ~]# mv dir1 ./dir2
[root@rhcsa001 ~]# ls
dir2

22. 将文件file1改名为file2

[root@rhcsa001 ~]# touch file1
[root@rhcsa001 ~]# ls
 file1
[root@rhcsa001 ~]# mv file1 ./file2
[root@rhcsa001 ~]# ls
 file2

24. 建立source文件的符号链接,命名为source.soft

[root@rhcsa001 ~]# touch source
[root@rhcsa001 ~]# ln -s source source.soft
[root@rhcsa001 ~]# ll
total 0
-rw-r--r--. 1 root root 0 Sep 30 19:00 source
lrwxrwxrwx. 1 root root 6 Sep 30 19:00 source.soft -> source

40. 创建install.login文件的软链接文件install.soft,硬链接文件install.hard

[root@rhcsa001 ~]# touch install.lodin
[root@rhcsa001 ~]# ln -s install.lodin install.soft
[root@rhcsa001 ~]# ln  install.lodin install.hard
[root@rhcsa001 ~]# ll
total 0
-rw-r--r--. 2 root root  0 Sep 30 19:04 install.hard
-rw-r--r--. 2 root root  0 Sep 30 19:04 install.lodin
lrwxrwxrwx. 1 root root 13 Sep 30 19:04 install.soft -> install.lodin

25. 查看/root目录下有哪些文件和目录

[root@rhcsa001 ~]# ls /root

[root@rhcsa001 ~]# ll /root

[root@rhcsa001 ~]# tree /root

29. 查看/etc/passwd文件的前10行

[root@rhcsa001 ~]# head -10 /etc/passwd | cat -n
     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

cat -n 用于显示行号

30.查看/etc/passwd文件的后2行

[root@rhcsa001 ~]# tail -2 /etc/passwd
tcpdump:x:72:72::/:/sbin/nologin
redhat:x:1000:1000:redhat:/home/redhat:/bin/bash

38. 查看当前目录中file的文件内容

[root@rhcsa001 ~]# cat file 
[root@rhcsa001 ~]# head file 
[root@rhcsa001 ~]# tail file 
[root@rhcsa001 ~]# vim file 
[root@rhcsa001 ~]# vi file

39. 在用户目录中创建目录/a/b/c/d ,在/root目录下创建1/2/3/4

41. 把/root目录下所有文件和子目录拷贝到/a/b/c/d目录下

43. 把/root目录下的install.log拷贝成1.txt,2.txt,3.txt,把install.log拷贝成a.txt,a.doc

44. 把/root下的以txt结尾的文件拷贝到/a目录下。把/root下的以a开头的文件拷贝到/a/b目录下


46. 把/a目录下1.txt改名为1.c,把/a/b下的a.txt改名a.c
48. 把/a/b/c目录移动到/root/1/2/3/4目录下
49. 把/root目录下install.log的前10行内容输出到文件/a/b/a.log中
52. 删除/a/b目录下的所有文件和子目录。删除/root/a/b目录下所有文件和子目录
60. 测试本机与IP为183.2.172.42的连通性

[root@rhcsa001 ~]# ping 183.2.172.42 
PING 183.2.172.42 (183.2.172.42) 56(84) bytes of data.
64 bytes from 183.2.172.42: icmp_seq=1 ttl=128 time=52.3 ms
64 bytes from 183.2.172.42: icmp_seq=2 ttl=128 time=55.9 ms

62. 查阅passwd命令的使用手册
66. 将/etc/apt中的所有文件复制到当前目录中
68. 搜索/etc/passwd中包含root的行,并显示出来


75. 修改当前用户的密码


88. 显示当前登录系统的用户
89. 查看/etc目录占用的磁盘空间
92. 显示环境变量USER的值
93. 利用重定向将create.c 的数据输出到 output.c
95. 在你的主目录下建立目录树
        mydir
   shell   program
linux dos  standart

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值