一、实战案例(练习)内容
假如你学习完Linux,想找一份儿Linux相关的运维工作,某天你接到一家公司给出的邀请,你来到该公司面试,面试前,运维主管给你出了一些简单的笔试题,题目如下:
1、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;
创建一个10GB的分区
1、首先添加一个10GB的分区
[root@localhost mnt]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until youdecide to write them.
Be careful before using the write command.
Device does not contain a recognized partitiontable
Building a new DOS disklabel with diskidentifier 0xd1d7785c.
Command (m for help): n^Hp
Partition type:
p primary (0 primary, 0extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G}(2048-31457279, default 31457279): +10G
Partition 1 of type Linux and of size 10 GiBis set
Command (m for help): p
Disk /dev/sdb: 16.1 GB, 16106127360 bytes,31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk label type: dos
Disk identifier: 0xd1d7785c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partx -s /dev/sdb1
NR START END SECTORS SIZE NAME UUID
1 2048 20973567 20971520 10G
2、格式化为ext4格式
[root@localhost mnt]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accountinginformation: done
3、创建/data目录,并将磁盘挂载,同时设置开机自动挂载
[root@localhost ~]# mkdir data/
[root@localhost ~]# mount /dev/sdb1 /root/data
编辑/etc/fstab文件,添加:/dev/sdb1 /root/data/ ext4 defaults 00
2、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;
命令如下:netstat -tan |grep "LISTEN[[:space:]]*$"
3、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;
1、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin)
2、修改nologin的shell路径
3、找出/etc/passwd文件中用户名与其shell名相同的行
4、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;
cat /etc/rc.d/init.d/functions | grep -E"\<[[:alpha:]]*_?[[:alpha:]]*[(][)]"
5、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);
路径基名:echo"/etc/rc.d/init.d/" | egrep -o "[^/]+/?$" | cut -d"/" -f1
6、查找/usr目录下不属于root、bin或hadoop的所有文件;
[root@localhost ~]# find /usr -not \( -userroot -o -user bin -o -user hadoop \)
7、某天系统被入侵了,黑客在你系统下留下木马文件:
现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;
1)# find / -nouser -a -nogroup -a -atime -7
另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;
2)#find /etc -size +20k -type f
8、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。
[root@localhost ~]# mkdir -p /test/data
[root@localhost ~]# groupadd test
[root@localhost ~]# chown :test/test/data
[root@localhost ~]# chmod g+w/test/data
[root@localhost ~]# chmod g+s/test/data
[root@localhost ~]# chmod o+t/test/data
[root@localhost~]# ls -ld /test/data/
drwxrwsr-t. 2 root test 6 Dec 30 16:53/test/data/