1、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;
//确定是MBR/GPT[root@a ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 20G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot└─sda3 8:3 0 18.9G 0 part ├─centos-root 253:0 0 10G 0 lvm / ├─centos-swap 253:1 0 1G 0 lvm [SWAP] └─centos-home 253:2 0 7.9G 0 lvm /homesr0 11:0 1 1024M 0 rom [root@a ~]# parted /dev/sda printModel: VMware, VMware Virtual S (scsi)Disk /dev/sda: 21.5GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: pmbr_bootNumber Start End Size File system Name Flags 1 1049kB 3146kB 2097kB bios_grub 2 3146kB 1077MB 1074MB xfs 3 1077MB 21.3GB 20.3GB lvm //分割指定容量的磁盘[root@a ~]# gdisk /dev/sdaGPT fdisk (gdisk) version 0.8.6Partition table scan: MBR: protective BSD: not present APM: not present GPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): nPartition number (4-128, default 4): First sector (34-41943006, default = 41662464) or {+-}size{KMGTP}: Last sector (41662464-41943006, default = 41943006) or {+-}size{KMGTP}: +10G Current type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem'Command (? for help): PDisk /dev/sda: 41943040 sectors, 20.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): 974D2867-3522-4343-84A3-A2B26850627EPartition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 41943006Partitions will be aligned on 2048-sector boundariesTotal free space is 180157 sectors (88.0 MiB)Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 2103295 1024.0 MiB 0700 3 2103296 41662463 18.9 GiB 8E00 4 41662464 41764863 10 GiB 8300 Linux filesystem//写入磁盘分割表Command (? for help): WFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): YOK; writing new GUID partition table (GPT) to /dev/sda.Warning: The kernel is still using the old partition table.The new table will be used at the next reboot.The operation has completed successfully.//更新磁盘分割表[root@a ~]# partprobe -s/dev/sda: gpt partitions 1 2 3 4[root@a ~]# lsblk /dev/sdaNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 20G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot├─sda3 8:3 0 18.9G 0 part │ ├─centos-root 253:0 0 10G 0 lvm /│ ├─centos-swap 253:1 0 1G 0 lvm [SWAP]│ └─centos-home 253:2 0 7.9G 0 lvm /home└─sda4 8:4 0 10G 0 part //格式化为ext4[root@a ~]# mkfs.ext4 /dev/sda4mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks12824 inodes, 51200 blocks2560 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=336855047 block groups8192 blocks per group, 8192 fragments per group1832 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done//挂载至/data[hi@a ~]$ vi /etc/fstab ## /etc/fstab# Created by anaconda on Sun Jan 10 22:09:58 2016## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/centos-root / xfs defaults 0 0UUID=4aa9d018-6054-4ae1-bc34-b91d5a06e84c /boot xfs defaults 0 0/dev/mapper/centos-swap swap swap defaults 0 0/dev/sda4 /data etx4 defaults 0 0
2、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;
//0个[root@a ~]# netstat -tan | grep -E "LISTEN[^[:space:]]"//1个或者多个[root@a ~]# netstat -tan | grep -E "LISTEN[[:space:]]+"tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN
3、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;
//添加用户[root@a ~]# useradd nginx[root@a ~]# useradd zabbix[root@a ~]# useradd tomcat[root@a ~]# useradd nologin -s /sbin/nologin[root@a ~]# useradd hadoop//找出/etc/passwd文件中用户名与其shell名相同的行[root@a ~]# grep "^([[:alnum:]]\{1,\}):.*\l$" /etc/passwd
4、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;
[root@a ~]# grep -n "[[:alpha:]]()" /etc/rc.d/init.d/functions
5、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);
[root@a ~]# echo "/home/hi" | grep -E -o "[^/]+/?$" | cut -d"/" -f1[root@a ~]$ echo "/home/hi" | egrep -o "^/[[:alnum:]]+"
6、查找/usr目录下不属于root、bin或hadoop的所有文件;
[root@a hi]# find /usr -not -user root -a -not -user bin -a -not -user hadoop
7、某天系统被***了,***在你系统下留下***文件:
现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;
另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;
[root@a hi]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop[hi@a ~]$ find /etc -size +20k -type f
8、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。
[root@a hi]# mkdir -p /test/data [root@a hi]# chown root.tomcat /test/data[root@a hi]# usermod -g tomcat nginx[root@a hi]# usermod -g tomcat hadoop[root@a hi]# chmod -g+ws,o+t /test/data