10.2-linux文件与目录管理
生活随笔
收集整理的這篇文章主要介紹了
10.2-linux文件与目录管理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.1-目錄的相關操作
1. rmRemove (unlink) the FILE(s).-f, --force #強制刪除ignore nonexistent files, never prompt-i prompt before every removal -I prompt once before removing more than three files, or whenremoving recursively. Less intrusive than -i, while stillgiving protection against most mistakes-r, -R, --recursive 連同目錄和內容一塊刪除remove directories and their contents recursivelyBy default, rm does not remove directories. Use the --recursive (-ror -R) option to remove each listed directory, too, along with allof its contents.#刪除名字帶有 -To remove a file whose name starts with a ‘-’, for example ‘-foo’,use one of these commands:rm -- -foorm ./-fooNote that if you use rm to remove a file, it is usually possible torecover the contents of that file. If you want more assurance thatthe contents are truly unrecoverable, consider using shred. ------------ 2. pwdPrint the full filename of the current working directory.-L, --logical #顯示出當前路徑,包含連接(link)路徑use PWD from environment, even if it contains symlinks-P, --physical #顯示出當前路徑,而非使用連接(link)路徑avoid all symlinks ------------ 3. mkdir SYNOPSISmkdir [OPTION]... DIRECTORY...Create the DIRECTORY(ies), if they do not already exist.-m, --mode=MODE #設置配置文件的權限set file mode (as in chmod), not a=rwx - umask-p, --parentsno error if existing, make parent directories as needed------------ 4. rmdir SYNOPSISrmdir [OPTION]... DIRECTORY...DESCRIPTIONRemove the DIRECTORY(ies), if they are empty.--ignore-fail-on-non-emptyignore each failure that is solely because a directoryis non-empty-p, --parents #連同上層空目錄一起刪除remove DIRECTORY and its ancestors; e.g., ‘rmdir -p a/b/c’ issimilar to ‘rmdir a/b/c a/b a’-v, --verboseoutput a diagnostic for every directory processed--->rm -r test 將目錄下的東西也刪除 View Code?1.2.1查看文件目錄
ls [選項]... [文件]... 列出 FILE 的信息(默認為當前目錄)。-a, --all 不隱藏任何以. 開始的項目-d, --directory 當遇到目錄時列出目錄本身而非目錄內的文件-f 不進行排序,-aU 選項生效,-lst 選項失效-F, --classify 加上文件類型的指示符號(*/=@| 其中一個)--format=關鍵字 交錯-x,逗號分隔-m,水平-x,長-l,單欄-1,詳細-l,垂直-C--full-time 即-l --time-style=full-iso-h, --human-readable 與-l 一起,以易于閱讀的格式輸出文件大小(例如 1K 234M 2G)--si 同上面類似,但是使用1000 為基底而非1024-i, --inode 顯示每個文件的inode 號-l 使用較長格式列出信息-n, --numeric-uid-gid 類似 -l,但列出UID 及GID 號-r, --reverse 排序時保留順序-R, --recursive 遞歸顯示子目錄-S 根據文件大小排序-t 根據修改時間排序 ----------- ll ----> ls -l 一樣 View Code1.2.2復制,刪除,與移動:cp ,rm, mv
1. cp 用法:cp [選項]... [-T] 源文件 目標文件或:cp [選項]... 源文件... 目錄或:cp [選項]... -t 目錄 源文件... 將源文件復制至目標文件,或將多個源文件復制至目標目錄。長選項必須使用的參數對于短選項時也是必需使用的。 * -a, --archive 相當于-pdr 等于-dR --preserve=all--backup[=CONTROL 為每個已存在的目標文件創建備份-d 復制連接文件屬性而非文件本身,等于--no-dereference --preserve=links-f, --force 如果目標文件無法打開則將其移除并重試(當 -n 選項存在時則不需再選此項) *-i, --interactive 覆蓋前詢問(使前面的 -n 選項失效)-l, --link 進行硬連接,文件而不復制 *-p 連同文件的屬性一起復制過去,等于--preserve=模式,所有權,時間戳--preserve[=屬性列表 保持指定的屬性(默認:模式,所有權,時間戳),如果可能保持附加屬性:環境、鏈接、xattr 等-s, --symbolic-link 只創建符號鏈接而不復制文件-u, --update 目標文件比源文件舊才更新目標文件 ------- 使用范例一: [root@wen tmp]# cp ~/.bashrc /tmp/bashrc [root@wen tmp]# cp -i ~/.bashrc /tmp/bashrc cp:是否覆蓋"/tmp/bashrc"? [root@wen tmp]# cd /tmp [root@wen tmp]# cp /var/log/wtmp . [root@wen tmp]# ls -l /var/log/wtmp wtmp -rw-rw-r--. 1 root utmp 208128 10月 2 00:05 /var/log/wtmp -rw-r--r-- 1 root root 207744 10月 3 2017 wtmp [root@wen tmp]# cp -a /var/log/wtmp wtmp_2 [root@wen tmp]# ls -l /var/log/wtmp wtmp_2 -rw-rw-r--. 1 root utmp 208128 10月 2 00:05 /var/log/wtmp -rw-rw-r--. 1 root utmp 207744 10月 3 2017 wtmp_2范例二: [root@wen tmp]# cp /etc/ /tmp cp: 略過目錄"/etc/" [root@wen tmp]# cp -r /etc/ /tmp[root@wen tmp]# ll bashrc -rw-r--r-- 1 root root 176 10月 3 2017 bashrc [root@wen tmp]# cp -s bashrc bashrc_slink [root@wen tmp]# cp -l bashrc bashrc_hlink [root@wen tmp]# ll bashrc* -rw-r--r-- 2 root root 176 10月 3 2017 bashrc -rw-r--r-- 2 root root 176 10月 3 2017 bashrc_hlink #硬連接 lrwxrwxrwx 1 root root 6 10月 2 00:43 bashrc_slink -> bashrc[root@wen tmp]# cp -u ~/.bashrc /tmp/bashrc #常用于備份[root@wen tmp]# cp bashrc_slink bashrc_slink_1 [root@wen tmp]# cp -d bashrc_slink bashrc_slink_2 #復制連接文件屬性而非本身 [root@wen tmp]# ll bashrc bashrc_slink* -rw-r--r-- 2 root root 176 10月 3 2017 bashrc lrwxrwxrwx 1 root root 6 10月 2 00:43 bashrc_slink -> bashrc -rw-r--r-- 1 root root 176 10月 2 00:50 bashrc_slink_1 lrwxrwxrwx 1 root root 6 10月 2 00:50 bashrc_slink_2 -> bashrc cp rm [root@wen ~]# cd /tmp [root@wen tmp]# ls bashrc bashrc_slink bashrc_slink_2 oldboy wtmp_2 bashrc_hlink bashrc_slink_1 etc wtmp* rm:是否刪除普通文件 "bashrc"?y 已刪除"bashrc" rm:是否刪除普通文件 "bashrc_hlink"?y 已刪除"bashrc_hlink" rm:是否刪除符號鏈接 "bashrc_slink"?y 已刪除"bashrc_slink" rm:是否刪除普通文件 "bashrc_slink_1"?y 已刪除"bashrc_slink_1" rm:是否刪除符號鏈接 "bashrc_slink_2"?y 已刪除"bashrc_slink_2" [root@wen tmp]# ls etc oldboy wtmp wtmp_2 [root@wen tmp]# rm -fr /tmp/etc [root@wen tmp]# ls oldboy wtmp wtmp_2 [root@wen tmp]# \rm -r /tmp/wtmp* #沒有詢問刪除 [root@wen tmp]# ls oldboy [root@wen tmp]# touch ./-aaa- [root@wen tmp]# ls -aaa- oldboy [root@wen tmp]# rm ./-aaa- #或者 rm -- -aaa- rm:是否刪除普通空文件 "./-aaa-"?y [root@wen tmp]# ls oldboy rm 用法:mv [選項]... [-T] 源文件 目標文件或:mv [選項]... 源文件... 目錄或:mv [選項]... -t 目錄 源文件... 將源文件重命名為目標文件,或將源文件移動至指定目錄。-f, --force 覆蓋前不詢問-i, --interactive 覆蓋前詢問-u, --update 只在源文件文件比目標文件新,或目標文件不存在時才進行移動 [root@wen tmp]# cp ~/.bashrc bashrc [root@wen tmp]# mkdir mvtest [root@wen tmp]# mv bashrc mvtest [root@wen tmp]# mv mvtest mvtest2 #重命名 [root@wen tmp]# ls mvtest2 oldboy mv1.3 文件內容查閱
總結
以上是生活随笔為你收集整理的10.2-linux文件与目录管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 9.30
- 下一篇: linux 其他常用命令