Error[8]: Undefined offset: 115, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述目录 输入输出部分 find部分 基础阶段-拓展练习2 输入输出部分 1.输入时间命令"date"将当前系统时间输出到/data/1.txt [[email protected] ~]# date >/data/1.txt[[email protected] ~]# cat /data/1.txtWed Jul 3 15:48:24 CST 2019 2.输入时间命令"date"将当前系统时

目录

输入输出部分 find部分 基础阶段-拓展练习2 输入输出部分 1.输入时间命令"date"将当前系统时间输出到/data/1.txt
[[email protected] ~]# date >/data/1.txt[[email protected] ~]# cat /data/1.txtWed Jul  3 15:48:24 CST 2019
2.输入时间命令"date"将当前系统时间追加到/data/1.txt
[[email protected] ~]# date >> /data/1.txt[[email protected] ~]# cat /data/1.txtWed Jul  3 15:48:24 CST 2019Wed Jul  3 15:49:28 CST 2019
3.在当前系统能Ping通百度的情况下,使用" Ping -c3 baIDu.com "将返回的信息输出到/data/1.txt
[[email protected] ~]# Ping -c3 baIDu.com >> /data/1.txt
4.使用“ls /ta”将错误的信息输出到/data/1.txt
[[email protected] ~]# ls /ta 2>> /data/1.txt
5.将/data/1.txt的文件内容,标准输出到/data/2.txt
[[email protected] ~]# cat /data/1.txt >/data/2.txt
6.使用"seq 10 50"将以0结尾的行标准输出到3.txt
[[email protected] ~]# seq 10 50|grep '0$'>3.txt
7.把/etc/fstab文件内容重定向到/tmp目录下文件名为fstab.out
[[email protected] ~]# cat /etc/fstab>/tmp/fstab.out
8.把字符"hello world"追加到/tmp/fstab.out文件尾部
[[email protected] ~]# echo hello world >> /tmp/fstab.out
9.输入df -h,取出当前系统根分区已用磁盘空间的百分比,并将取出来的数值输出到/data/1.txt
[[email protected] ~]# df -h|awk '/sda3/'|awk  -F '[ %]+' '{print}'>/data/1.txt[[email protected] ~]# cat /data/1.txt7
10.使用命令Ping测试10.0.0.100是否通畅,把输出的结果不管是正确的还是错误的都追加到/data/1.txt
[[email protected] ~]# Ping 10.0.0.100 &>>/data/1.txt
11.使用重定向从文件/etc/passwd中读取数据。
cat < /etc/passwd
12.用 << 举个命令的使用例子。
[[email protected] ~]# cat >>a.txt <<eof> 123> 123> 456> eof
13.复制/etc/passwd文件到当前目录下,把文件中的:替换成#,不能使用sed和vim命令。
[[email protected] ~]# cp /etc/passwd ./ [[email protected] ~]# tr ':' '#' < ./passwd
14.执行测试虚拟机是否能上网的命令,把错误的结果保存到/data/1.txt
[[email protected] ~]# Ping baIDu.com 2>/data/1.txt
15.清空/data/1.txt文件中的内容,不能使用vim命令。
[[email protected] ~]# echo  > /data/1.txt
16.在当前系统能Ping通百度的情况下,使用命令curl cip.cc 查看当前网络出口地址,取出关键字"数据二"所在的行,以空格为分隔符,取出第三列的内容
[[email protected] ~]# curl -s cip.cc|awk '/数据二/'|awk -F ' ' '{print}'上海市
17.改变文件所有者的命令是?
chown
18.新建一个1.txt文件,文件内容如下

1123
1122
112233
321
3306
8080
80
23
21
8081
8082
8085

[[email protected] ~]# cat >>1.txt <<eof> 1123> 1122> 112233> 321> 3306> 8080> 80> 23> 21> 8081> 8082> 8085> eof
19.接18题,显示1.txt第3行到第10行的内容(三种方法)
[[email protected] ~]# head 1.txt|tail -7[[email protected] ~]# awk 'NR==3,NR==10' 1.txt[[email protected] ~]# sed -n '3,10p' 1.txt
20.接18题,显示1.txt第3行和第10行的内容(两种方法)
[[email protected] ~]# awk 'NR==3;NR==10' 1.txt[[email protected] ~]# sed -n '3p;10p' 1.txt
21.新建用户oldboy,oldgirl,属同一用户组edu
[[email protected] ~]# groupadd edu[[email protected] ~]# useradd -g edu oldboy[[email protected] ~]# useradd -g edu oldgirl
22.修改文件1.txt的所有者为oldboy,属组为edu
[[email protected] ~]# chown oldboy.edu 1.txt[[email protected] ~]# ll -d 1.txt-rw-r--r--. 1 oldboy edu 55 Jul  4 01:23 1.txt
23.除所有者以外,属组和其他用户均没有任何权限(要求普通用户进行验证)
chmod g=- o=-
24.复制/etc/fstab文件到/var/tmp下,设置文件所有者为wangcai读写权限,所属组为sysadmins组有读写权限,其他人无权限
[[email protected] ~]# cp /etc/fstab /var/tmp[[email protected] ~]# chmod  660 /var/tmp/fstab[[email protected] ~]# groupadd sysadmins[[email protected] ~]# useradd wangcai[[email protected] ~]# chown wangcai.sysadmins /var/tmp/fstab[[email protected] ~]# ll -d /var/tmp/fstab-rw-rw----. 1 wangcai sysadmins 501 Jul  4 02:06 /var/tmp/fstab
25.创建下面的用户、组和组成员关系,用户natasha,使用admins作为附属组,用户harry,也使用admins作为附属组,用户sh,不可交互登录系统,natasha,harry,sh密码都是centos
[[email protected] ~]# groupadd admins[[email protected] ~]# useradd natasha -G admins[[email protected] ~]# useradd harry -G admins[[email protected] ~]# useradd sh -s /sbin/nologin[[email protected] ~]# echo 'centos'|passwd --stdin natashaChanging password for user natasha.passwd: all authentication tokens updated successfully.[[email protected] ~]# echo 'centos'|passwd --stdin harryChanging password for user harry.passwd: all authentication tokens updated successfully.[[email protected] ~]# echo 'centos'|passwd --stdin shChanging password for user sh.passwd: all authentication tokens updated successfully.
26.新建一个用户rose,uID为555,gID为500,注释信息为:linux,家目录在/rose
[[email protected] ~]# useradd rose -u 555  -c "linux" -d /home/rose[[email protected] ~]# groupmod rose -g 500[[email protected] ~]# ID roseuID=555(rose) gID=500(rose) groups=500(rose)
27.执行命令echo "I am qls,myqq is 1176494252">/oldboy/oldboy.txt,

现在需要从文件中过滤出“qls”和“1176494252”字符串,请给出命令?(最少三种方法)

[[email protected] ~]# sed -rn '/qls|1176494252/p' /oldboy/oldboy.txt[[email protected] ~]# awk '/qls|1176494252/' /oldboy/oldboy.txt[[email protected] ~]# egrep 'qls|1176494252' /oldboy/oldboy.txt
28.接上题,如果需要从文件中过滤出“qls,1176494252”字符串,请再给出命令?
[[email protected] ~]# sed -rn '/qls|,|1176494252/p' /oldboy/oldboy.txt[[email protected] ~]# awk '/qls|,|1176494252/' /oldboy/oldboy.txt[[email protected] ~]# egrep 'qls|,|1176494252' /oldboy/oldboy.txt
29.如何查看/etc/services文件的有多少行?(三种方法)
[[email protected] ~]# cat -n /etc/services|tail -1[[email protected] ~]# wc -l /etc/servicesless +N[[email protected] ~]# grep -n . /etc/services|tail -1
30.我想在/data/oldboyedu目录下面创建 一个oldboy.txt文件,出现了如下报错。

[[email protected] ~]# touch /data/oldboyedu/oldboy.txt
touch: cannot touch ‘/data/oldboyedu/oldboy.txt’: No such file or directory
问:为何出现这样的错误?该怎么解决?

没有目录[[email protected] ~]# mkdir /data/oldboyedu[[email protected] ~]# touch /data/oldboyedu/oldboy.txt
31.请输入你知道的20个命令及作用
useradd 创建用户whoami 查看用户名history 历史命令alias  别名ls 列出目录的内容及其内容属性信息cd 切换目录mkdir 创建目录touch 创建文件tree 树状显示目录结构cp 复制命令mv 移动sort 排序cut 截取uniq 去重head 查看前n 行tail 查看尾部n 行rm 删除cat 查看tr 替换grep   过滤关键字sed文本处理工具awk文本处理工具
32.翻译题
01).command not found      命令没有找到              02).No such file or directory     没有这个文件或目录    03).Permission denIEd       权限不足               04).overwrite               覆盖05).file exists             文件已经存在              06).Is a directory          这是1个目录              07).Not a directory           不是1个目录            08).Warning: Changing a Readonly file      警告:改变一个只读文件09).Found a swap file by the name ".1.swp" 发现了一个swap文件名字为1.swp   是vim编辑器碰到的意外关闭文件有缓存 10).unrecognized option '--oldboy'  不识别的选项,去查看帮助11).Operation not permitted      *** 作不许可12).invalID option      无效的选项
find部分 1.找出/tmp目录下,属主不是root,且文件名不以f开头的文件
find /tmp -type f ! -user root ! -name 'f*'
2.查找/etc/目录下,所有.conf后缀的文件
find /etc/ -type f -name '*.conf'
3.查找/var目录下属主为root,且属组为mail的所有文件
find /var -type f -user root -group mail
4.查找/var目录下7天以前,同时属主不为root,也不是postfix的文件
find /var -type f ! -user root ! -user postfix
5.查找/etc目录下大于1M且类型为普通文件的所有文件
find /etc -type f -size +1M
6.查找/etc目录下所有用户都没有写权限的文件
find /etc  -type f  -perm -000
7.查找/目录下最后创建时间是3天前,后缀是*.log的文件
find / -type f -mtime +3 -name '*.log'
8.查找/目录下文件名包含txt的文件
find / -type -name '*txt*'
9.查找/目录下属主是oldboy并且属组是oldboy的文件
find / -type f  -user oldboy -group oldboy
10.查找/目录下属主是oldboy但是属组不是oldboy的文件
find / -type f -user oldboy ! -group oldboy
11.查找/目录下属主是oldboy或者属主是oldgirl的文件
find / -user oldboy -o -user oldgirl
12.查找/tmp目录下属主既不是oldboy,也不是oldgirl的文件
find /tmp ! -user oldboy ! -user oldgirl
13.查找/var/log目录下7天以前的文件
find /var/log -type f  -mtime +7
14.查找/tmp目录下15天以前的文件删除
find /tmp -type f -mtime +15 -delete
15.查找/home目录下,类型是目录的,并且属主是oldboy的目录
find /home -type d -user oldboy
16.查找/var/log下大于100kb且以log结尾的所有文件
find /var/log -type f -size +100k -name '*log'
17.查找tmp目录下所属组group1,所属主user1的目录
find /tmp -type d -user user1 -group group1
18.同时查找根目录下名为1.txt,2.txt的文件和名字带a的目录
find / -type f -name 1.txt -name 2.txt  -type d -name '*a*'
19.查找/tmp目录下所有文件并删除
find /tmp -type f -delete
20.查找/etc目录下至少有一类用户没有写权限的文件
[[email protected] ~]# find /tmp -type f  -perm -644[[email protected] ~]# find /tmp -type f ! -perm -222
21.查找/tmp目录下,属主不是root,且文件名不以f开头的文件
find /tmp ! -user root ! -name 'f*'
22.查找/var目录下属主为root,且属组为mail的所有文件
find /var -type f -user root -group mail
23.查找/var目录下不属于root、lp、gdm的所有文件
find /var -type f ! -user root ! -user Ip ! -user gdm
24.查找/var目录下最近一周内其内容修改过,同时属主不为root,也不是postfix的文件
find /var -type f -mtime -7 ! -user root !-user postfix
25.查找/etc目录下大于1M且类型为普通文件的所有文件
find /etc -type f -size +1M
26.将/etc/中的所有目录(仅目录)复制到/tmp下,目录结构不变
find /etc/ -maxdepth 1 -type d |xargs cp -t /tmp/
27.将/etc目录复制到/var/tmp/,/var/tmp/etc的所有目录权限777/var/tmp/etc目录中所有文件权限666
cp /etc  /var/tmp/find /var/tmp/ -type d |xargs chmod -t 777find /var/tmp/ -type f |xargs chmod -t 666
28.保留/var/log/下最近7天的日志文件,其他全部删除
find /var/log/ -mtime +7 -delete
29.创建touch file{1..10}10个文件,保留file9,其他一次全部删除
find $(touch file{1..10})  -type  f ! -name ‘file9’ -delete
30.解释如下每条命令含义
mkdir /root/dir1在root目录下创建目录dir1touch /root/dir1/file{1..10}在dir1目录下创建10个file文件find /root/dir1 -type f -name "file5"查找/root/dir1目录下的file5文件find /root/dir1 ! -name "file5"查找dir1目录下除了file5的文件find /root/dir1 -name "file5" -o -name "file9"查找dirl目录下file5或file9文件find /root/dir1 -name "file5" -o -name "file9" -ls查看dirl目录下file5或file9文件的详细信息find /root/dir1 \( -name "file5" -o -name "file9" \) -ls查找/root/dir1下文件名为file5或者file9 并且显示信息find /root/dir1 \( -name "file5" -o -name "file9" \) -exec rm -rvf {} \;查找/root/dir1下的文件名为file5或者file9并且删除find /root/dir1 ! \( -name "file4" -o -name "file8" \) -exec rm -vf {} \;查找/root/dir1下的文件名不为file4或file8的所有文件并删除
基础阶段-拓展练习2 1.linux关机重启的命令有哪些 ?(至少4个)
关机:inint0   shutdown -h Now  powroff重启:reboot  init6  shutdown -r
2.你知道哪些bash的快捷键呢?请把他写出来,并写出他的作用?(至少6个)
Ctrl + a    :将光标跳转到行首Ctrl + e   :将光标跳转至行末Ctrl + w   :以空格为单位,将当前光标位置之前的内容删除Ctrl + u   :将当前光标位置之前的内容全部删除Ctrl + l   :清屏Ctrl + c   :终止当前命令Ctrl + d   :退出,断开当前连接(exit,logoutCtrl + z   :挂起,放后台执行Ctrl + r   :搜索历史命令Ctrl + s   :锁屏Ctrl + q   :解锁Ctrl + 左右:按照单词跳转光标
@H_531_301@3.linux的发行版本都有哪些?(至少6个)
RedhatCentosubuntuDebianSuseFreebsd Fedora红旗
4.如果我在当前在/目录下,之后执行了以下 *** 作,请告诉我,最后我所在的目录位置?

cd /etc/sysconfig/

cd ..

cd ..

cd -

cd ~

当前用户的家目录
5.显示/etc/services文件的第11行到第20行的内容?
sed -n ‘11,20p’/etc/serviceshead -20 /etc/services|tailawk ‘NR==11,NR==20’/etc/services
6.已知文件123.txt内容如下,请过滤出不包含online字符串的命令

test

olDBOY

online

oldboy

oldboyoldboy

grep -v ‘online’123.txtsed ‘/online/d' 123.txt
7.已知执行ip a s eth0结果如下:要求取出IP地址(两种方法)

[[email protected] ~]# ip a s eth0

2: eth0: <broADCAST,MulTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group

? link/ether 00:0c:29:77:fe:83 brd ff:ff:ff:ff:ff:ff

? inet 10.0.0.90/24 brd 10.0.0.255 scope global eth0 #最前面为4个空格。

? valID_lft forever preferred_lft forever

inet6 fe80::20c:29ff:fe77:fe83/64 scope link

ip a s eth0|awk -F’[ /]+’ ’NR==3{print }’ip a s eth0|sed -nr ‘3s#.*t (.*)/.*##gp’
8.已知/data/test.txt文件内容如下:要求取出不包含bejing的行,(两种方法)

shanghai

bejing

nanjing

sed -n ‘1p;3p’/data/test.txtawk ‘NR==1;NR==3’/data/test.txt
9.调试系统服务时,希望能实时查看系统日志/var/log/messages的更新,如何做?
tail -f /var/log/messages
10.统计/etc/passwd文件一共有多少行?(两种方法)
wc -l /etc/passwdcat -n /etc/passwd|tail -1grep -c ‘.’/etc/passwdawk ‘{print 
which ifconfigtype -a ifconfigfind /-type f -name “ifconfig”whereis ifconfig
,NR}’/etc/passwd|tail -1
11.查找ifconfig命令的绝对路径在哪里?(两种方法)
wc -c /etc/servicesll /etc/services
@H_22_419@12.统计文件/etc/services的大小?(两种方法)
tr ‘,’ ’’<file.txt |cut -d ‘ ’ -f2,5awk -F ‘[,]+’’{print ,}’ file.txtsed -rn ‘s#Im (.*),.*Q (.*)# #g’file.txt
13.执行下面的命令echo "Im qiuZengjia,is QQ 1176494252" >file.txt,要求取出该文件中的姓名和QQ号。(注意逗号前面没有空格)。(两种方法)
tree -a /var/log/|tail -1
14.统计/var/log下的所有文件(包含目录)个数(包括隐藏文件)。
awk -F ‘NR==1 {print $NF}’/etc/passwdcut -d ‘:’ -f7 /etc/passswdsed -nr ‘1s#.*:(.*)##gp’/etc/passwd
15.以“:”为分隔符,取出/etc/passwd第一行的第七列也就是最后一列的内容?(两种方法)
mkdir -p /oldboy/test
16.请用一条命令完成创建目录/oldboy/test,即创建/oldboy目录及/oldboy/test。
find /oldboy -type f -name “*.txt”|xargs sed -t ‘s#oldboy#oldgirl#g’sed ‘s#oldboy#oldgirl#g’ `find /oldboy -type f -name “*.txt” `
17.把/oldboy目录及其子目录下所有以扩展名 .txt结尾的文件中,文件包含oldboy的字符串全部替换为oldgirl(两种方法)
sed -n ‘5,15p’ /etc/passwd >/oldboy/test.txt
18.把/etc/passwd文件中的第5到第15行的内容保存到/oldboy/test.txt中 > >> &> # .. . $ 19.说出下面几个特殊符号的含义
*  所有> 标准输出>>  追加重定向&> 正确的和错误的都输出# 注释.. 返回上级目录. 当前目录$以...结尾
sed -i ‘s#beijing#shanghai#g’/data/test.txt
20.把/data/test.txt文件中的beijing替换为shanghai,给出命令(请使用sed命令).
find /var/log -type f -name “*.log” -ls
21.找出/var/log目录中以.log结尾的文件,并显示这些文件的属性信息。
grep -En ‘3306|1521’/etc/seriviceawk ‘/3306|1521/’ /etc/services
22.过滤出/etc/services 文件包含3306或1521两数字所在的行的内容。(两种方法)
cp $(find /data -mtime +7 -size +100k) /tmpcp `find /data -mtime +7 -size +100k` /tmp
23.将/data目录下的修改时间是7天以前,并且大于100k的文件复制到/tmp目录下。(两种方法)
find /data -type f -size +50k -100k  |xargs sed  -t 's#oldboy#oldgirl#g'sed 's#oldboy#oldgirl#g' $(find /data -type f  -size +50k -100k )
24.将/data目录中大于50k且小于100k 的文件,把文件中的oldboy替换为oldgirl。(两种方法)
/etc/sysconfig/network-scripts/ifcfg-ens33etc/resolv.cof书写方式不一样生效方式不一样网卡配置文件需要重启网络服务才能生效
25.写出redhat中,配置网卡及dns的配置文件是什么?有什么区别?
:%s#oldboy#oldoldgirl#g
26.vim中把所有oldboy替换为oldgirl,给出命令
find /app/log -mtime +7  -type f -delete
27.查找/app/logs/下7天以前的文件并删除
find /data/ -maxdepth 1 -type f  -name "*beijing*"-o -name "*hello-nanjing*"|xargs cat -t -n
28./data目录下(一级目录)查找包含“hello-beijing”或“hello-nanjing”的所有文件及行号
echo:所见即所得history:查看历史命令alias:设置别名help:帮助命令shutdown:关机重启命令ls:列出目录的属性信息cd:切换目录mkdir:创建目录touch:创建文件tree:已树状形式显示目录cp:复制mv:移动rm:删除cat:查看文件内容head:查看文件的前n行,默认10行tail:实时查看文件内容的更新grep:过滤sed:替换,取行awk:取列,正则后向引用which:查找命令的绝对路径type:显示命令的绝对路径sort:排序uniq:去重cut:截取vim:文本编辑器useradd:创建用户passwd:设置密码groupadd:创建组chown:属主属组修改命令chmod:修改权限find文件查找
29.请输入你知道的20个命令及作用(不做直接扣十分)
find -name “mytest.log” -type f
30.寻找名称为mytest.log的文件
sed -rn ‘s#name#address#gp’ config.txt
31.用命令行更改config.txt文件,把里面的“name”更改为“address”
mv $(find /var/log -size +1M) /tmp/logmv `find /var/log -size +1M` /tmp/log
32.查找目录/var/log下大于1M的文件移动到/tmp/log下。(两种方法)
01).command not found   文件找不到   02).No such file or directory   没有这个文件或者目录03).Permission denIEd   权限不够04).file exists  文件已存在
33.如下常见报错,说明一下如下报错信息?
cat /etc/fstab >/tmp/fstab.out
34.把/etc/fstab文件内容重定向到/tmp目录下文件名为fstab.out
tr ‘:’ ‘#’< /etc/passwd
35.把/etc/passwd文件中的:替换成#,不能使用sed和vim命令及管道符号。
sed  -n ‘3p;10p test.txt’awk  ‘NR==3;NR==10’ test.txt
36.显示test.txt第3行和第10行的内容(两种方法)
rw-r--r--     644rw-rw-r--     664622           rw--w--w-746           rwxr--rw-
37.将以下权限翻译成数字,将数字权限用字母表示
groupadd Agroupadd Buseradd davID -g groupadd Auseradd peter -g groupadd Auseradd life -g groupadd Buseradd laowang -g groupadd B
38.假设公司研发部的用户davID和peter属于组A,财务部的用户life和laowang属于组B,根据要求创建用户及组。
mkdir /testchmod 1777 /test
39.创建目录/test,要求所有用户对这个目录有所有权限,现在只想让每个用户在这个目录只能对属于自己的文件进行 *** 作,怎么实现?
属主,属组,其他用户
40.用户基础权限为9位,每三位为一组,每组代表着谁的权限?
touch test.txtchmod 600 test.txt
41.创建一个文件test.txt,并其将权限改为600.
groupadd shanghai02 -g 1099
42.创建一个用户基本组,shanghai02,指定GID为1099.
groupadd linuxgroupadd shanghai02useradd linux01 -g linux -G shanghai02
43.创建一个用户linux01,指定该用户的基本组为linux,附加组为shanghai02。
systemctl  stop firewalldsystemctl disable firewalld
44.怎样临时关闭和永久关闭firewalld这个服务?
useradd test01echo 123456|passwd --stdin test01
45.创建test01用户,给test01用户使用非交互式设置密码为123456
echo $RANDOM|md5sum|cut -c 1-18 |tee test.txt|passwd --stdin test01mkgasswd -l 18 |tee test.txt|passwd --stdin test01
46.使用root用户给test01用户设置一个18位的随机密码,并进行登录。
删除当前所在行,并进入编辑模式
47.普通模式下的S是什么作用?
userdel -r user2
48.删除用户user2,不保留其家目录。
chmod -R +x  /test
49.给/test目录及目录下的所有文件或目录加上x权限(属主、属组、其他用户都执行权限)。
mkdir /testuseradd qiudaogrepadd linuxchown qiudao.linux /test
50.将/test/目录的属主修改为qiudao,属组改为linux,需创建用户和用户组。 [+++] 总结

以上是内存溢出为你收集整理的Linux拓展练习部分--输入输出 / find部分 /基础拓展2全部内容,希望文章能够帮你解决Linux拓展练习部分--输入输出 / find部分 /基础拓展2所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Linux拓展练习部分--输入输出find部分 基础拓展2_系统运维_内存溢出

Linux拓展练习部分--输入输出find部分 基础拓展2

Linux拓展练习部分--输入输出find部分 基础拓展2,第1张

概述目录 输入输出部分 find部分 基础阶段-拓展练习2 输入输出部分 1.输入时间命令"date"将当前系统时间输出到/data/1.txt [[email protected] ~]# date >/data/1.txt[[email protected] ~]# cat /data/1.txtWed Jul 3 15:48:24 CST 2019 2.输入时间命令"date"将当前系统时

目录

输入输出部分 find部分 基础阶段-拓展练习2 输入输出部分 1.输入时间命令"date"将当前系统时间输出到/data/1.txt
[[email protected] ~]# date >/data/1.txt[[email protected] ~]# cat /data/1.txtWed Jul  3 15:48:24 CST 2019
2.输入时间命令"date"将当前系统时间追加到/data/1.txt
[[email protected] ~]# date >> /data/1.txt[[email protected] ~]# cat /data/1.txtWed Jul  3 15:48:24 CST 2019Wed Jul  3 15:49:28 CST 2019
3.在当前系统能Ping通百度的情况下,使用" Ping -c3 baIDu.com "将返回的信息输出到/data/1.txt
[[email protected] ~]# Ping -c3 baIDu.com >> /data/1.txt
4.使用“ls /ta”将错误的信息输出到/data/1.txt
[[email protected] ~]# ls /ta 2>> /data/1.txt
5.将/data/1.txt的文件内容,标准输出到/data/2.txt
[[email protected] ~]# cat /data/1.txt >/data/2.txt
6.使用"seq 10 50"将以0结尾的行标准输出到3.txt
[[email protected] ~]# seq 10 50|grep '0$'>3.txt
7.把/etc/fstab文件内容重定向到/tmp目录下文件名为fstab.out
[[email protected] ~]# cat /etc/fstab>/tmp/fstab.out
8.把字符"hello world"追加到/tmp/fstab.out文件尾部
[[email protected] ~]# echo hello world >> /tmp/fstab.out
9.输入df -h,取出当前系统根分区已用磁盘空间的百分比,并将取出来的数值输出到/data/1.txt
[[email protected] ~]# df -h|awk '/sda3/'|awk  -F '[ %]+' '{print}'>/data/1.txt[[email protected] ~]# cat /data/1.txt7
10.使用命令Ping测试10.0.0.100是否通畅,把输出的结果不管是正确的还是错误的都追加到/data/1.txt
[[email protected] ~]# Ping 10.0.0.100 &>>/data/1.txt
11.使用重定向从文件/etc/passwd中读取数据。
cat < /etc/passwd
12.用 << 举个命令的使用例子。
[[email protected] ~]# cat >>a.txt <<eof> 123> 123> 456> eof
13.复制/etc/passwd文件到当前目录下,把文件中的:替换成#,不能使用sed和vim命令。
[[email protected] ~]# cp /etc/passwd ./ [[email protected] ~]# tr ':' '#' < ./passwd
14.执行测试虚拟机是否能上网的命令,把错误的结果保存到/data/1.txt
[[email protected] ~]# Ping baIDu.com 2>/data/1.txt
15.清空/data/1.txt文件中的内容,不能使用vim命令。
[[email protected] ~]# echo  > /data/1.txt
16.在当前系统能Ping通百度的情况下,使用命令curl cip.cc 查看当前网络出口地址,取出关键字"数据二"所在的行,以空格为分隔符,取出第三列的内容
[[email protected] ~]# curl -s cip.cc|awk '/数据二/'|awk -F ' ' '{print}'上海市
17.改变文件所有者的命令是?
chown
18.新建一个1.txt文件,文件内容如下

1123
1122
112233
321
3306
8080
80
23
21
8081
8082
8085

[[email protected] ~]# cat >>1.txt <<eof> 1123> 1122> 112233> 321> 3306> 8080> 80> 23> 21> 8081> 8082> 8085> eof
19.接18题,显示1.txt第3行到第10行的内容(三种方法)
[[email protected] ~]# head 1.txt|tail -7[[email protected] ~]# awk 'NR==3,NR==10' 1.txt[[email protected] ~]# sed -n '3,10p' 1.txt
20.接18题,显示1.txt第3行和第10行的内容(两种方法)
[[email protected] ~]# awk 'NR==3;NR==10' 1.txt[[email protected] ~]# sed -n '3p;10p' 1.txt
21.新建用户oldboy,oldgirl,属同一用户组edu
[[email protected] ~]# groupadd edu[[email protected] ~]# useradd -g edu oldboy[[email protected] ~]# useradd -g edu oldgirl
22.修改文件1.txt的所有者为oldboy,属组为edu
[[email protected] ~]# chown oldboy.edu 1.txt[[email protected] ~]# ll -d 1.txt-rw-r--r--. 1 oldboy edu 55 Jul  4 01:23 1.txt
23.除所有者以外,属组和其他用户均没有任何权限(要求普通用户进行验证)
chmod g=- o=-
24.复制/etc/fstab文件到/var/tmp下,设置文件所有者为wangcai读写权限,所属组为sysadmins组有读写权限,其他人无权限
[[email protected] ~]# cp /etc/fstab /var/tmp[[email protected] ~]# chmod  660 /var/tmp/fstab[[email protected] ~]# groupadd sysadmins[[email protected] ~]# useradd wangcai[[email protected] ~]# chown wangcai.sysadmins /var/tmp/fstab[[email protected] ~]# ll -d /var/tmp/fstab-rw-rw----. 1 wangcai sysadmins 501 Jul  4 02:06 /var/tmp/fstab
25.创建下面的用户、组和组成员关系,用户natasha,使用admins作为附属组,用户harry,也使用admins作为附属组,用户sh,不可交互登录系统,natasha,harry,sh密码都是centos
[[email protected] ~]# groupadd admins[[email protected] ~]# useradd natasha -G admins[[email protected] ~]# useradd harry -G admins[[email protected] ~]# useradd sh -s /sbin/nologin[[email protected] ~]# echo 'centos'|passwd --stdin natashaChanging password for user natasha.passwd: all authentication tokens updated successfully.[[email protected] ~]# echo 'centos'|passwd --stdin harryChanging password for user harry.passwd: all authentication tokens updated successfully.[[email protected] ~]# echo 'centos'|passwd --stdin shChanging password for user sh.passwd: all authentication tokens updated successfully.
26.新建一个用户rose,uID为555,gID为500,注释信息为:linux,家目录在/rose
[[email protected] ~]# useradd rose -u 555  -c "linux" -d /home/rose[[email protected] ~]# groupmod rose -g 500[[email protected] ~]# ID roseuID=555(rose) gID=500(rose) groups=500(rose)
27.执行命令echo "I am qls,myqq is 1176494252">/oldboy/oldboy.txt,

现在需要从文件中过滤出“qls”和“1176494252”字符串,请给出命令?(最少三种方法)

[[email protected] ~]# sed -rn '/qls|1176494252/p' /oldboy/oldboy.txt[[email protected] ~]# awk '/qls|1176494252/' /oldboy/oldboy.txt[[email protected] ~]# egrep 'qls|1176494252' /oldboy/oldboy.txt
28.接上题,如果需要从文件中过滤出“qls,1176494252”字符串,请再给出命令?
[[email protected] ~]# sed -rn '/qls|,|1176494252/p' /oldboy/oldboy.txt[[email protected] ~]# awk '/qls|,|1176494252/' /oldboy/oldboy.txt[[email protected] ~]# egrep 'qls|,|1176494252' /oldboy/oldboy.txt
29.如何查看/etc/services文件的有多少行?(三种方法)
[[email protected] ~]# cat -n /etc/services|tail -1[[email protected] ~]# wc -l /etc/servicesless +N[[email protected] ~]# grep -n . /etc/services|tail -1
30.我想在/data/oldboyedu目录下面创建 一个oldboy.txt文件,出现了如下报错。

[[email protected] ~]# touch /data/oldboyedu/oldboy.txt
touch: cannot touch ‘/data/oldboyedu/oldboy.txt’: No such file or directory
问:为何出现这样的错误?该怎么解决?

没有目录[[email protected] ~]# mkdir /data/oldboyedu[[email protected] ~]# touch /data/oldboyedu/oldboy.txt
31.请输入你知道的20个命令及作用
useradd 创建用户whoami 查看用户名history 历史命令alias  别名ls 列出目录的内容及其内容属性信息cd 切换目录mkdir 创建目录touch 创建文件tree 树状显示目录结构cp 复制命令mv 移动sort 排序cut 截取uniq 去重head 查看前n 行tail 查看尾部n 行rm 删除cat 查看tr 替换grep   过滤关键字sed文本处理工具awk文本处理工具
32.翻译题
01).command not found      命令没有找到              02).No such file or directory     没有这个文件或目录    03).Permission denIEd       权限不足               04).overwrite               覆盖05).file exists             文件已经存在              06).Is a directory          这是1个目录              07).Not a directory           不是1个目录            08).Warning: Changing a Readonly file      警告:改变一个只读文件09).Found a swap file by the name ".1.swp" 发现了一个swap文件名字为1.swp   是vim编辑器碰到的意外关闭文件有缓存 10).unrecognized option '--oldboy'  不识别的选项,去查看帮助11).Operation not permitted      *** 作不许可12).invalID option      无效的选项
find部分 1.找出/tmp目录下,属主不是root,且文件名不以f开头的文件
find /tmp -type f ! -user root ! -name 'f*'
2.查找/etc/目录下,所有.conf后缀的文件
find /etc/ -type f -name '*.conf'
3.查找/var目录下属主为root,且属组为mail的所有文件
find /var -type f -user root -group mail
4.查找/var目录下7天以前,同时属主不为root,也不是postfix的文件
find /var -type f ! -user root ! -user postfix
5.查找/etc目录下大于1M且类型为普通文件的所有文件
find /etc -type f -size +1M
6.查找/etc目录下所有用户都没有写权限的文件
find /etc  -type f  -perm -000
7.查找/目录下最后创建时间是3天前,后缀是*.log的文件
find / -type f -mtime +3 -name '*.log'
8.查找/目录下文件名包含txt的文件
find / -type -name '*txt*'
9.查找/目录下属主是oldboy并且属组是oldboy的文件
find / -type f  -user oldboy -group oldboy
10.查找/目录下属主是oldboy但是属组不是oldboy的文件
find / -type f -user oldboy ! -group oldboy
11.查找/目录下属主是oldboy或者属主是oldgirl的文件
find / -user oldboy -o -user oldgirl
12.查找/tmp目录下属主既不是oldboy,也不是oldgirl的文件
find /tmp ! -user oldboy ! -user oldgirl
13.查找/var/log目录下7天以前的文件
find /var/log -type f  -mtime +7
14.查找/tmp目录下15天以前的文件删除
find /tmp -type f -mtime +15 -delete
15.查找/home目录下,类型是目录的,并且属主是oldboy的目录
find /home -type d -user oldboy
16.查找/var/log下大于100kb且以log结尾的所有文件
find /var/log -type f -size +100k -name '*log'
17.查找tmp目录下所属组group1,所属主user1的目录
find /tmp -type d -user user1 -group group1
18.同时查找根目录下名为1.txt,2.txt的文件和名字带a的目录
find / -type f -name 1.txt -name 2.txt  -type d -name '*a*'
19.查找/tmp目录下所有文件并删除
find /tmp -type f -delete
20.查找/etc目录下至少有一类用户没有写权限的文件
[[email protected] ~]# find /tmp -type f  -perm -644[[email protected] ~]# find /tmp -type f ! -perm -222
21.查找/tmp目录下,属主不是root,且文件名不以f开头的文件
find /tmp ! -user root ! -name 'f*'
22.查找/var目录下属主为root,且属组为mail的所有文件
find /var -type f -user root -group mail
23.查找/var目录下不属于root、lp、gdm的所有文件
find /var -type f ! -user root ! -user Ip ! -user gdm
24.查找/var目录下最近一周内其内容修改过,同时属主不为root,也不是postfix的文件
find /var -type f -mtime -7 ! -user root !-user postfix
25.查找/etc目录下大于1M且类型为普通文件的所有文件
find /etc -type f -size +1M
26.将/etc/中的所有目录(仅目录)复制到/tmp下,目录结构不变
find /etc/ -maxdepth 1 -type d |xargs cp -t /tmp/
27.将/etc目录复制到/var/tmp/,/var/tmp/etc的所有目录权限777/var/tmp/etc目录中所有文件权限666
cp /etc  /var/tmp/find /var/tmp/ -type d |xargs chmod -t 777find /var/tmp/ -type f |xargs chmod -t 666
28.保留/var/log/下最近7天的日志文件,其他全部删除
find /var/log/ -mtime +7 -delete
29.创建touch file{1..10}10个文件,保留file9,其他一次全部删除
find $(touch file{1..10})  -type  f ! -name ‘file9’ -delete
30.解释如下每条命令含义
mkdir /root/dir1在root目录下创建目录dir1touch /root/dir1/file{1..10}在dir1目录下创建10个file文件find /root/dir1 -type f -name "file5"查找/root/dir1目录下的file5文件find /root/dir1 ! -name "file5"查找dir1目录下除了file5的文件find /root/dir1 -name "file5" -o -name "file9"查找dirl目录下file5或file9文件find /root/dir1 -name "file5" -o -name "file9" -ls查看dirl目录下file5或file9文件的详细信息find /root/dir1 \( -name "file5" -o -name "file9" \) -ls查找/root/dir1下文件名为file5或者file9 并且显示信息find /root/dir1 \( -name "file5" -o -name "file9" \) -exec rm -rvf {} \;查找/root/dir1下的文件名为file5或者file9并且删除find /root/dir1 ! \( -name "file4" -o -name "file8" \) -exec rm -vf {} \;查找/root/dir1下的文件名不为file4或file8的所有文件并删除
基础阶段-拓展练习2 1.linux关机重启的命令有哪些 ?(至少4个)
关机:inint0   shutdown -h Now  powroff重启:reboot  init6  shutdown -r
2.你知道哪些bash的快捷键呢?请把他写出来,并写出他的作用?(至少6个)
Ctrl + a    :将光标跳转到行首Ctrl + e   :将光标跳转至行末Ctrl + w   :以空格为单位,将当前光标位置之前的内容删除Ctrl + u   :将当前光标位置之前的内容全部删除Ctrl + l   :清屏Ctrl + c   :终止当前命令Ctrl + d   :退出,断开当前连接(exit,logoutCtrl + z   :挂起,放后台执行Ctrl + r   :搜索历史命令Ctrl + s   :锁屏Ctrl + q   :解锁Ctrl + 左右:按照单词跳转光标
@H_531_301@3.linux的发行版本都有哪些?(至少6个)
RedhatCentosubuntuDebianSuseFreebsd Fedora红旗
4.如果我在当前在/目录下,之后执行了以下 *** 作,请告诉我,最后我所在的目录位置?

cd /etc/sysconfig/

cd ..

cd ..

cd -

cd ~

当前用户的家目录
5.显示/etc/services文件的第11行到第20行的内容?
sed -n ‘11,20p’/etc/serviceshead -20 /etc/services|tailawk ‘NR==11,NR==20’/etc/services
6.已知文件123.txt内容如下,请过滤出不包含online字符串的命令

test

olDBOY

online

oldboy

oldboyoldboy

grep -v ‘online’123.txtsed ‘/online/d' 123.txt
7.已知执行ip a s eth0结果如下:要求取出IP地址(两种方法)

[[email protected] ~]# ip a s eth0

2: eth0: <broADCAST,MulTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group

? link/ether 00:0c:29:77:fe:83 brd ff:ff:ff:ff:ff:ff

? inet 10.0.0.90/24 brd 10.0.0.255 scope global eth0 #最前面为4个空格。

? valID_lft forever preferred_lft forever

inet6 fe80::20c:29ff:fe77:fe83/64 scope link

ip a s eth0|awk -F’[ /]+’ ’NR==3{print }’ip a s eth0|sed -nr ‘3s#.*t (.*)/.*##gp’
8.已知/data/test.txt文件内容如下:要求取出不包含bejing的行,(两种方法)

shanghai

bejing

nanjing

sed -n ‘1p;3p’/data/test.txtawk ‘NR==1;NR==3’/data/test.txt
9.调试系统服务时,希望能实时查看系统日志/var/log/messages的更新,如何做?
tail -f /var/log/messages
10.统计/etc/passwd文件一共有多少行?(两种方法)
wc -l /etc/passwdcat -n /etc/passwd|tail -1grep -c ‘.’/etc/passwdawk ‘{print 
which ifconfigtype -a ifconfigfind /-type f -name “ifconfig”whereis ifconfig
,NR}’/etc/passwd|tail -1
11.查找ifconfig命令的绝对路径在哪里?(两种方法)
wc -c /etc/servicesll /etc/services
@H_22_419@12.统计文件/etc/services的大小?(两种方法)
tr ‘,’ ’’<file.txt |cut -d ‘ ’ -f2,5awk -F ‘[,]+’’{print ,}’ file.txtsed -rn ‘s#Im (.*),.*Q (.*)# #g’file.txt
13.执行下面的命令echo "Im qiuZengjia,is QQ 1176494252" >file.txt,要求取出该文件中的姓名和QQ号。(注意逗号前面没有空格)。(两种方法)
tree -a /var/log/|tail -1
14.统计/var/log下的所有文件(包含目录)个数(包括隐藏文件)。
awk -F ‘NR==1 {print $NF}’/etc/passwdcut -d ‘:’ -f7 /etc/passswdsed -nr ‘1s#.*:(.*)##gp’/etc/passwd
15.以“:”为分隔符,取出/etc/passwd第一行的第七列也就是最后一列的内容?(两种方法)
mkdir -p /oldboy/test
16.请用一条命令完成创建目录/oldboy/test,即创建/oldboy目录及/oldboy/test。
find /oldboy -type f -name “*.txt”|xargs sed -t ‘s#oldboy#oldgirl#g’sed ‘s#oldboy#oldgirl#g’ `find /oldboy -type f -name “*.txt” `
17.把/oldboy目录及其子目录下所有以扩展名 .txt结尾的文件中,文件包含oldboy的字符串全部替换为oldgirl(两种方法)
sed -n ‘5,15p’ /etc/passwd >/oldboy/test.txt
18.把/etc/passwd文件中的第5到第15行的内容保存到/oldboy/test.txt中 > >> &> # .. . $ 19.说出下面几个特殊符号的含义
*  所有> 标准输出>>  追加重定向&> 正确的和错误的都输出# 注释.. 返回上级目录. 当前目录$以...结尾
sed -i ‘s#beijing#shanghai#g’/data/test.txt
20.把/data/test.txt文件中的beijing替换为shanghai,给出命令(请使用sed命令).
find /var/log -type f -name “*.log” -ls
21.找出/var/log目录中以.log结尾的文件,并显示这些文件的属性信息。
grep -En ‘3306|1521’/etc/seriviceawk ‘/3306|1521/’ /etc/services
22.过滤出/etc/services 文件包含3306或1521两数字所在的行的内容。(两种方法)
cp $(find /data -mtime +7 -size +100k) /tmpcp `find /data -mtime +7 -size +100k` /tmp
23.将/data目录下的修改时间是7天以前,并且大于100k的文件复制到/tmp目录下。(两种方法)
find /data -type f -size +50k -100k  |xargs sed  -t 's#oldboy#oldgirl#g'sed 's#oldboy#oldgirl#g' $(find /data -type f  -size +50k -100k )
24.将/data目录中大于50k且小于100k 的文件,把文件中的oldboy替换为oldgirl。(两种方法)
/etc/sysconfig/network-scripts/ifcfg-ens33etc/resolv.cof书写方式不一样生效方式不一样网卡配置文件需要重启网络服务才能生效
25.写出redhat中,配置网卡及dns的配置文件是什么?有什么区别?
:%s#oldboy#oldoldgirl#g
26.vim中把所有oldboy替换为oldgirl,给出命令
find /app/log -mtime +7  -type f -delete
27.查找/app/logs/下7天以前的文件并删除
find /data/ -maxdepth 1 -type f  -name "*beijing*"-o -name "*hello-nanjing*"|xargs cat -t -n
28./data目录下(一级目录)查找包含“hello-beijing”或“hello-nanjing”的所有文件及行号
echo:所见即所得history:查看历史命令alias:设置别名help:帮助命令shutdown:关机重启命令ls:列出目录的属性信息cd:切换目录mkdir:创建目录touch:创建文件tree:已树状形式显示目录cp:复制mv:移动rm:删除cat:查看文件内容head:查看文件的前n行,默认10行tail:实时查看文件内容的更新grep:过滤sed:替换,取行awk:取列,正则后向引用which:查找命令的绝对路径type:显示命令的绝对路径sort:排序uniq:去重cut:截取vim:文本编辑器useradd:创建用户passwd:设置密码groupadd:创建组chown:属主属组修改命令chmod:修改权限find文件查找
29.请输入你知道的20个命令及作用(不做直接扣十分)
find -name “mytest.log” -type f
30.寻找名称为mytest.log的文件
sed -rn ‘s#name#address#gp’ config.txt
31.用命令行更改config.txt文件,把里面的“name”更改为“address”
mv $(find /var/log -size +1M) /tmp/logmv `find /var/log -size +1M` /tmp/log
32.查找目录/var/log下大于1M的文件移动到/tmp/log下。(两种方法)
01).command not found   文件找不到   02).No such file or directory   没有这个文件或者目录03).Permission denIEd   权限不够04).file exists  文件已存在
33.如下常见报错,说明一下如下报错信息?
cat /etc/fstab >/tmp/fstab.out
34.把/etc/fstab文件内容重定向到/tmp目录下文件名为fstab.out
tr ‘:’ ‘#’< /etc/passwd
35.把/etc/passwd文件中的:替换成#,不能使用sed和vim命令及管道符号。
sed  -n ‘3p;10p test.txt’awk  ‘NR==3;NR==10’ test.txt
36.显示test.txt第3行和第10行的内容(两种方法)
rw-r--r--     644rw-rw-r--     664622           rw--w--w-746           rwxr--rw-
37.将以下权限翻译成数字,将数字权限用字母表示
groupadd Agroupadd Buseradd davID -g groupadd Auseradd peter -g groupadd Auseradd life -g groupadd Buseradd laowang -g groupadd B
38.假设公司研发部的用户davID和peter属于组A,财务部的用户life和laowang属于组B,根据要求创建用户及组。
mkdir /testchmod 1777 /test
39.创建目录/test,要求所有用户对这个目录有所有权限,现在只想让每个用户在这个目录只能对属于自己的文件进行 *** 作,怎么实现?
属主,属组,其他用户
40.用户基础权限为9位,每三位为一组,每组代表着谁的权限?
touch test.txtchmod 600 test.txt
41.创建一个文件test.txt,并其将权限改为600.
groupadd shanghai02 -g 1099
42.创建一个用户基本组,shanghai02,指定GID为1099.
groupadd linuxgroupadd shanghai02useradd linux01 -g linux -G shanghai02
43.创建一个用户linux01,指定该用户的基本组为linux,附加组为shanghai02。
systemctl  stop firewalldsystemctl disable firewalld
44.怎样临时关闭和永久关闭firewalld这个服务?
useradd test01echo 123456|passwd --stdin test01
45.创建test01用户,给test01用户使用非交互式设置密码为123456
echo $RANDOM|md5sum|cut -c 1-18 |tee test.txt|passwd --stdin test01mkgasswd -l 18 |tee test.txt|passwd --stdin test01
46.使用root用户给test01用户设置一个18位的随机密码,并进行登录。
删除当前所在行,并进入编辑模式
47.普通模式下的S是什么作用?
userdel -r user2
48.删除用户user2,不保留其家目录。
chmod -R +x  /test
49.给/test目录及目录下的所有文件或目录加上x权限(属主、属组、其他用户都执行权限)。
mkdir /testuseradd qiudaogrepadd linuxchown qiudao.linux /test
50.将/test/目录的属主修改为qiudao,属组改为linux,需创建用户和用户组。 总结

以上是内存溢出为你收集整理的Linux拓展练习部分--输入输出 / find部分 /基础拓展2全部内容,希望文章能够帮你解决Linux拓展练习部分--输入输出 / find部分 /基础拓展2所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1017207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存