1、建立一個10G的檔案系統,類型為ext4,要求開機可自動挂載至單獨資料/data目錄;
# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。
更改将停留在記憶體中,直到您決定将更改寫入磁盤。
使用寫入指令前請三思。
指令(輸入 m 擷取幫助):p
磁盤 /dev/sda:128.8 GB, 128849018880 位元組,251658240 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤标簽類型:dos
磁盤辨別符:0x0000d19d
裝置 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
指令(輸入 m 擷取幫助):n
Partition type:
p primary (1 primary, 0extended, 3 free)
e extended
Select (default p): p
分區号 (2-4,預設 2):
起始 扇區 (1026048-251658239,預設為 1026048):
将使用預設值 1026048
Last 扇區, +扇區 or +size{K,M,G} (1026048-251658239,預設為 251658239):+10G
分區 2 已設定為 Linux 類型,大小設為 10 GiB
指令(輸入 m 擷取幫助):p
磁盤 /dev/sda:128.8 GB, 128849018880 位元組,251658240 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤标簽類型:dos
磁盤辨別符:0x0000d19d
裝置 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 21997567 10485760 83 Linux
指令(輸入 m 擷取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partitiontable.
WARNING: Re-reading the partition tablefailed with error 16: 裝置或資源忙.
The kernel still uses the old table. Thenew table will be used at
the next reboot or after you runpartprobe(8) or kpartx(8)
正在同步磁盤。
格式化類型為ext4
#mke2fs -t ext4 /dev/sda2
建立/data目錄
#mkdir /data
開機自動挂載,更改/etc/fstab配置檔案:
vim /etc/fstab
/dev/sda2 /data ext4
2、顯示`netstat -tan`指令結果中以‘LISTEN’後跟0個、1個或者多個空白字元結尾的行;
netstat -tan | grep"LISTEN[[:space:]]*$"
[:space:]表示空白字元
*表示前一個字元出現0次或多次
$什麼為結尾
3、添加使用者nginx、zabbix、tomcat、nologin以及hadoop使用者(nologin使用者的shell為/sbin/nologin);而後找出/etc/passwd檔案中使用者名與其shell名相同的行;
#useradd
#useraddnginx
#useraddzabbix
#useradd tomcat
#useradd -s /sbin/nogoginnologin //-s表示指定預設shell目錄位址
#useraddhadoop
#grep "\(^[[:alnum:]]\+\>\).*\1$"/etc/passwd
首先過濾出使用者名,基于使用者名沒有特殊字元[:alnum:],并且使用者名是在/etc/passed檔案下的行首字段,所有用行首錨定^,單詞至少出現一次\+
詞尾錨定\>這樣就能過濾出所有使用者名,shell名相同過濾,首先把前面的分組,中間跟任意内容.*,結尾内容跟前面的内容一緻:\?$,比對一次:\1$
4、找出/etc/rc.d/init.d/functions檔案中某單詞(單詞中間可以存在下劃線)後面跟着一組小括号的行;
#grep -E -o “^[_[:alpha:]]+\(\)”/etc/rc.d/init.d/functions
-o 顯示字元串本身
\轉意
5、使用echo輸出一個路徑,而後egrep找出其路徑基名;進一步的使用egrep取出其目錄名(注意是目錄名,而非目錄路徑);
mkdir –p /data/plt
echo /data/plt | grep -E -o"[^/]+$"首先要指明除了斜線結尾至少出現一次:-E [^/]+$,
-o表示隻顯示比對到的字元串本身
6、查找/usr目錄下不屬于root、bin或hadoop的所有檔案;
#find /usr -not -user root -a -not -userbin -a -not -user -hadoop
#find /usr -not \( -user root -o -user bin-o -user hadoop \)
-a:與
-o:或
-not:非
\(\):将一個或多個字元捆綁在一起,當作一個正題進行處理
7、某天系統被入侵了,黑客在你系統下留下木馬檔案:
現需要查找目前系統上沒有屬主或屬組,且最近一周内曾被通路過的所有檔案;
另外,需要查找/etc目錄下大于20k且類型為普通檔案的所有檔案;
#find / -nouser –a –noguoup –a -atime -10 –ls或
find / \( -nouser -o -nogroup \) -a \(-atime -10 \) -ls
#find /etc -size +20k -type f –ls
8、建立目錄/test/data,讓某組内普通使用者對其有寫權限,且建立的所有檔案的屬組為目錄所屬的組;此外,每個使用者僅能删除自己的檔案。
#mkdir -p /test/data //-p表示循環建立
#chmod o+w /test/data //給普通使用者增加寫權限
#chmod g+s /test/data
#chmod o+t /test/data