Linux作业(3)

1、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();

[[email protected]~]# ls /etc/rc.d/init.d/
functions  netconsole  network README
[[email protected] ~]# grep -o "\<.*\>()"/etc/rc.d/init.d/functions
checkpid()
__pids_var_run()
__pids_pidof()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
echo_success()
echo_failure()
echo_passed()
echo_warning()
update_boot_stage()
success()
failure()
passed()
warning()
action()
strstr()

2、使用echo命令输出一个绝对路径,使用grep取出其基名;

[[email protected]~]#  echo "/etc/rc.d/init.d/functions"| grep -E -o "[^/]+$"
functions

扩展:取出其路径名

[[email protected]~]# echo "/etc/rc.d/init.d/functions" | grep -E -o "^/.*/"
/etc/rc.d/init.d/

3、找出ifconfig命令结果中的1-255之间数字;

[[email protected] ~]# ifconfig

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.2.108  netmask255.255.255.0  broadcast 192.168.2.255

inet6 fe80::20c:29ff:fe0d:4a8b prefixlen 64  scopeid0x20<link>

ether 00:0c:29:0d:4a:8b txqueuelen 1000  (Ethernet)

RX packets 419  bytes 41325 (40.3KiB)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 337  bytes 46637 (45.5KiB)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

lo:flags=73<UP,LOOPBACK,RUNNING>  mtu65536

inet 127.0.0.1  netmask 255.0.0.0

inet6 ::1  prefixlen 128  scopeid 0x10<host>

loop  txqueuelen 0  (Local Loopback)

RX packets 4  bytes 340 (340.0 B)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 4  bytes 340 (340.0 B)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

virbr0:flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

inet 192.168.122.1  netmask255.255.255.0  broadcast 192.168.122.255

ether 52:54:00:47:81:6c txqueuelen 0  (Ethernet)

RX packets 0  bytes 0 (0.0 B)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 0  bytes 0 (0.0 B)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

[[email protected] ~]#ifconfig | grep -E -o "\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"
192
168
2
108
255
255
255
0
192
168
2
255
64
29
38
5
0
0
0
0
40
8
0
0
0
0
0
73
127
0
0
1
255
0
0
0
1
128
0
4
0
0
0
0
0
4
0
0
0
0
0
0
192
168
122
1
255
255
255
0
192
168
122
255
52
54
47
81
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

4、查找当前系统上没有属主或属组的文件;

[[email protected]~]# find / -nouser -o -nogroup
/home/mandriva
/home/mandriva/.bash_logout
/home/mandriva/.bash_profile
/home/mandriva/.bashrc
/home/mandriva/.mozilla
/home/mandriva/.mozilla/extensions
/home/mandriva/.mozilla/plugins
find: ‘/proc/3244/task/3244/fd/6’: 没有那个文件或目录
find:‘/proc/3244/task/3244/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/3244/fd/6’: 没有那个文件或目录
find:‘/proc/3244/fdinfo/6’: 没有那个文件或目录
/var/spool/mail/mandriva
[[email protected] ~]#

进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

[[email protected] ~]# find / \( -nouser -o-nogroup \) -a -atime -3

/home/mandriva

/home/mandriva/.mozilla

/home/mandriva/.mozilla/extensions

/home/mandriva/.mozilla/plugins

find: ‘/proc/3254/task/3254/fd/6’: 没有那个文件或目录

find: ‘/proc/3254/task/3254/fdinfo/6’: 没有那个文件或目录

find: ‘/proc/3254/fd/6’: 没有那个文件或目录

find: ‘/proc/3254/fdinfo/6’: 没有那个文件或目录

5、查找/etc目录下大于1M,且类型为普通文件的所有文件;

[[email protected] ~]# find /etc -size +1M -a-type f -ls

4239312 6852 -r--r--r--   1 root    root      7014922 12月 11 00:24/etc/udev/hwdb.bin

202385046 3772 -rw-r--r--   1 root    root      3858924 11月 21  2015 /etc/selinux/targeted/policy/policy.29

4083229 1336 -rw-r--r--   1 root    root      1367395 3月  6  2015/etc/brltty/zh-tw.ctb

[[email protected] ~]#

6、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

[[email protected] ~]# find /etc/init.d/ -perm/113 -ls

201494444   0 drwxr-xr-x   2 root     root           66 12月 10 00:22/etc/init.d/

201868855   4 -rwxr-xr-x   1 root     root         2989 9月 16  2015 /etc/init.d/netconsole

201868856   8 -rwxr-xr-x   1 root     root         6630 9月 16  2015 /etc/init.d/network

7、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

[[email protected]~]# find /etc/ -not \( -user root -o -user hadoop \) -atime -7 -ls
find: 用户名‘hadoop’ 未知
[[email protected] ~]# find/etc/ -not \( -user root -o -user bin \) -atime -7 -ls
134780546    0 drwx------   2 polkitd root           63 12月 10 00:21 /etc/polkit-1/rules.d
136093649    0 drwx--x--x   2 sssd    sssd            6 8月 3 00:58 /etc/sssd
[[email protected] ~]#

8、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;

[[email protected]~]# ls /etc/rc.d/
init.d  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d  rc.local
[[email protected] ~]#

[[email protected]~]# cp /etc/rc.d/rc.local /tmp/
[[email protected] ~]# ls /tmp/
mytest2   systemd-private-62113d01174b48f3b9b96b264b53cd52-cups.service-x1z7b8
rc.local  systemd-private-62113d01174b48f3b9b96b264b53cd52-vmtoolsd.service-pkrcv0
[[email protected] ~]# sed -i ‘s/\(^[[:space:]]\)/#\1/g‘ /tmp/rc.local

9、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符

[[email protected]~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run ‘chmod +x /etc/rc.d/rc.local‘ to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
[[email protected] ~]# cp /etc/rc.d/rc.local /tmp/
[[email protected] ~]# ls /tmp/
mytest2   systemd-private-62113d01174b48f3b9b96b264b53cd52-cups.service-x1z7b8
rc.local  systemd-private-62113d01174b48f3b9b96b264b53cd52-vmtoolsd.service-pkrcv0

[[email protected]~]# sed -i ‘s/^#[[:space:]]\+//g‘ /tmp/rc.local
[[email protected] ~]# cat /tmp/rc.local
#!/bin/bash
THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
It is highly advisable to create own systemd services or udev rules
to run scripts during boot instead of using this file.
#
In contrast to previous versions due to parallel execution during boot
this script will NOT be run after all other services.
#
Please note that you must run ‘chmod +x /etc/rc.d/rc.local‘ to ensure
that this script will be executed during boot.

touch /var/lock/subsys/local
[[email protected] ~]#

10、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;

[[email protected]~]# sed ‘s/enabled=0/enabled=1/g;s/gpgcheck=1/gpgcheck=2/g;‘/etc/yum.repos.d/CentOS-Media.rep

11、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20161202

[[email protected]~]# crontab -e

00 00 * *2,4,6 cp -r /var/log/messages /backup/messages_logs/messages-$(date +/%Y/%m/%d)

12、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中

[[email protected]~]# crontab -e

00 */2 * * *cat /proc/meminfo |grep "^S" >> /stats/memory.txt

13、写一个脚本创建10用户user10-user19;密码同用户名;

[[email protected]~]# vi test02

#!/bin/sh

for i in {10..19};do

id user$i &>/dev/dull

if [ $? -eq 0 ];then

echo "user$i exits"

else

useradd user$i

echo "user$i"| passwd --stdin user$i

echo "user$i added"

fi

done

时间: 2024-08-04 19:54:51

Linux作业(3)的相关文章

马哥linux作业第五周&#39;

1.显示当前系统上root.fedora或user1用户的默认shell: egrep "^(root|fedora|user1)\>" /etc/passwd |cut -d: -f1,7 root|fedora|user1表示三者符合其一的选择条件 ()使其归组 ^表示以后面归组的条件开头 \>表示以空字符截断此前的条件字符,即后跟其它字符的单词将不匹配 2.找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello():

马哥linux作业第四周&#39;

1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. cp -r /etc/skel/ /home/tuser1 chmod -R go-rwx /home/tuser1 2.编辑/etc/group文件,添加组hadoop. vim /etc/group 先查看有无hadoop组:输入"/hadoop" 如没有则在最后一行加入:输入":"进入编辑模式,移至最后一行,回车后输入 &qu

马哥linux作业第三周&#39;

1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可. who | cut -d' ' -f1 | sort -u 2.取出最后登录到当前系统的用户的相关信息. last | head -1 3.取出当前系统上被用户当作其默认shell的最多的那个shell. cat /etc/passwd | cut -d ':' -f7 |sort | uniq -c | sort |head -1 4.将/etc/passw d 中的第三个字段数值最大的后10个用户的信

代做Shell作业、代写代做Unix、Linux作业、代写国外shell作业

代做Shell作业.代写代做Unix.Linux作业.代写国外shell作业这个项目是为了创建一个文件同步器.1.1介绍许多计算机用户希望从不同的机器上访问他们的文件,最方便的方法是使用单一的文件系统,这个文件系统通过网络上的多台机器安装.机器在不同的网络时,系统共享的文件不能轻易被使用.举个例子,一个用户在两台机器(携带式和台式)上拥有相同的文件,当一个携带式机器上的文件被更改时,而它此时并没有接到网络中,那么它必须手动将新版本复制到系统中(这个系统只含有旧版本的文件),当文件分别在这两个系统

Linux作业(三)-shell统计某文章中出现频率最高的N个单词并排序输出出现次数

Linux课上的作业周三交,若有考虑不周到的地方,还请多多不吝赐教. shell处理文本相关的经常使用命令见此博客 # #假设输入两个參数 则第一个为统计单词的个数.第二个为要统计的文章 #假设输入一个參数 则默认统计单词的个数为10 # 详细思路: 将各种符号用换行替换(tr命令) 大写改小写(tr命令) 排序.统计单词个数并除去反复 (sort和uniq) 按出现次数的高低排序(sort) 打印N个须要统计的单词 #!/bin/bash if [ $# -ne 2 -a $# -ne 1 ]

linux作业1

1,描述计算机的组成及其功能. 运算器,对数据进行加减乘除等操作 控制器,控制程序的指令 存储器,储存程序数据信息 输入设备,下指令,提高数据 输出设备,输出结果 2,按系列罗列LINUX的发行版,并描述不同发行版之间的联系与区别. Debian:  (ubuntu),dpkg包管理系统 Slackware:  (suse),rpm包管理系统 Redhat:  (centos), rpm包管理系统 Gentoo, Arclinux, 3,描述LINUX的哲学思想,并按照自己的理解对其进行解释性描

LINUX作业( 二)

1.Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示. LINUX文件管理类命令一般有 cat.tac.more.less.tail.head 3.请使用命令行展开功能来完成以下练习: (1).创建/tmp目录下的:a_c, a_d, b_c, b_d touch /tmp/{a,b}_{c,d} (2).创建/tmp/mylinux目录下的: mylinux/ ├── bin ├── boot │   └── grub ├── dev ├── etc │   ├── rc

Linux作业(4)-03

10.创建一个由至少两个物理卷组成的大小为20G的卷组:要求,PE大小为8M:而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl: [[email protected] ~]# fdisk -l 磁盘 /dev/sda:128.8 GB, 128849018880 字节,251658240 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最

Linux作业(4)-01

1.创建一个10G分区,并格式为ext4文件系统: (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl: [[email protected] ~]# fdisk -l 磁盘 /dev/sdb:21.5 GB, 21474836480字节,41943040 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节

Linux作业(4)-02

4.总结RAID的各个级别及其组合方式和性能的不同: RAID:RedundantArrays of Independent Disks(磁盘阵列),有"独立磁盘构成的具有冗余能力的阵列"之意. 级别:RAID 0,RAID 1,RAID 10,RAID 01,RAID 5等 RAID 0:连续以位或字节为单位分割数据,同时读/写于多个磁盘上,因此具有很高的数据传输率,但它没有数据冗余,因此并不能算是真正的RAID结构. RAID 0只是单纯地提高性能,并没有为数据的可靠性提供保证,它