文件處理命令:
ls -a -l -d -h -i
mkdir?-p ?parents
cd?. ??.. ??/tmp/Japan
pwd
rmdir
cp?-r -p source destination ?可改名recursive preserve
mv?source destination ?剪切文件 改名
ctrl l 清屏 或者 clear命令
rm?-r ?-f
?
touch?新建文件?帶空格需加雙引號,但不建議使用 ?新建文件
?
cat -n ?查看短文件
tac??反向查看
more?查看長文件空格或f翻頁 ?enter ?換行 ?q或Q 退出more /etc/services
less?分頁顯示文件內容 ?pageup向上翻頁 上箭頭 向上一行 ?/查詢n下一個less /etc/services
head?-n 3 file 前3行 ?head file前10行 head -n 20 /etc/services
tail?-n -f?動態顯示文件末尾內容 follow ?tail -n 18 /etc/services ?tail -f /var/log/messages
?
ln -s 軟連接 特點:權限lrwxrwxrwx 大小 箭頭指向源文件
ln ???硬鏈接 相當于 cp -p 不同:與源文件同步更新 ?i結點相同 只能創建在同一分區 不可針對目錄
echo?"內容" file ?想file中寫入內容 可以跨分區 可針對目錄
?
?
-rw-r--r--
-文件類型(-文件d目錄l軟連接)
u所有者 ?g 所屬組 ?o 其他人
r 讀 ?w 寫 ?x 執行
——————————————————————————————————————————————————————————權限管理命令:
root 和 文件所有者 可以更改文件的權限
chmod?ugoa +-= rwx 文件/目錄 很少使用
?????????????421
chmod g+w
chmod 777 文件/目錄
-R 遞歸修改
?
useradd?jinzhao創建jinzhao用戶
passwd?jinzhao為jinzhao修改密碼
?
chown?jinzhao文件/目錄 ?只有root可以
chgrp?lampbrother文件/目錄 ?添加組命令?groupadd?lampbrother ?只有root可以
?
The user file-creation mask
umask?-S ?查看創建目錄的默認權限 對于文件,會把可執行權限x統統去掉
umask 077 將創建默認權限更改為700
——————————————————————————————————————————————————————————文件搜索命令:
文件搜索命令 注意盡量少用搜索,搜索會占用大量資源
find搜索范圍 匹配條件
?
根據文件名查找
find /etc -name init 精準搜索
find /etc -name *init* 模糊搜索
find /etc -name init???
find /etc -iname init??? 忽略大小寫
?
根據文件大小查找?1個數據塊是512B = 0.5KB可以得出1M = 2048
find / -size +204800 大于+小于-等于=
fine /etc -size +163840 -a -size -204800 查找大于80M小于100M的文件
?
根據所有者查找
find /home -user username
根據所屬組查找
find /home -group username
?
根據時間屬性查找
find /etc -amin ??-cmin ???-mmin -5 5分鐘內 +5超過5分鐘
??????????access ??change ??modify
??????????訪問? ? ? ??屬性? ? ? ?內容
-a 同時滿足
-o 滿足一個即可
-type f d l 根據文件類型查找 文件 目錄 軟連接
-inum 根據i節點查找 可以找到i節點的硬連接
?
?
find /etc -name inittab -exec ls -l {} \;
find /etc -name inittab -ok ls -l {} \; ???ok 比 exec多了一個確認環節
-exec/-ok 命令 {} \; ??對搜索結果執行操作
?
ls -i ?找到文件的i節點
find / -inum i節點 -exec rm {} \;通過i節點找到并刪除
?
locate??在資料庫中查找文件 ?資料庫會定期更新 ?
命令 updatedb?手動更新資料庫
資料庫是/var/lib/mlocate/mlocate.db,/tmp不在其記錄范圍之內
locate -i 文件名 不區分大小寫
?
which 命令?搜索命令所在目錄及別名信息
which ls
命令也可用絕對路徑,如 /bin/rm /tmp/liuyifei
?
whereis 命令?搜索命令的位置 和 幫助文檔的位置
?
grep?搜索目標行命令
-i 不區分大小寫 -v排除指定字串的行 文件
在文件中搜尋字串匹配的行并輸出
grep -i multiuser /etc/inittab
grep -v ^# /etc/inittab 排除行首為#的行