Mac OS中顯示及隱藏文件和文件夾的方法


 Mac有一個設計原則,就是用戶不需要看到的或者用戶不希望看到的,都不會顯示出來。但如果你想要修改其中某些文件,也是可以的,先需要顯示所有的文件,可以在終端中輸入命令行來實現。

顯示系統隱藏的文件

    defaults write com.apple.finder AppleShowAllFiles -bool true
    KillAll Finder
    或者
    defaults write com.apple.finder AppleShowAllFiles YES
    KillAll Finder

    同樣可以把這些隱藏文件再隱藏起來
    defaults write com.apple.finder AppleShowAllFiles -bool false
    KillAll Finder
     
    或者
    defaults write com.apple.finder AppleShowAllFiles NO
    KillAll Finder


在顯示了所有文件之后,那如何把一個不是隱藏的文件修改為隱藏呢,下面介紹兩種簡單的方法。


方法一:直接在文件或文件夾名前面的加一個‘.’點號,然后系統會彈出修改確認對話框,點好就行了。
方法二:利用命令“chflags hidden” 可以隱藏文件或文件夾。


先打開Terminal(Applications/Utilities/Terminal),然后執行命令
chflags hidden 文件路徑 或
chflags hidden 文件夾路徑
既可。也可以先輸入chflags hidden,然后直接把要隱藏的文件用鼠標選中拖到輸入框中,它自動會轉換為文件的路徑。
要解除文件的隱藏狀態,可以使用命令:
chflags nohidden
與前面相對應即可。


上面兩種方式,到底有啥區別呢,個人覺得方法一並沒有修改文件本身的屬性,在linux及unix中,約定好點開頭的文件就是隱藏文件。
方法二中修改的是文件本身的隱藏標志,但貌似在windows上不起作用,只能在linux及unix中有用。而方法一,windows也是可以顯示
隱藏的,應該是windows也識別linux及unix中的點號約定。


在網上還發現有一個可以隱藏文件及文件夾的開源工程,提供了一個帶界面的程序,可以方便不會使用命令行的用戶,地址是https://code.google.com/p/hideme4mac/

最后,附加上chflags命令的詳細信息。
chflags 命令修改文件的標志(change file flags),包括隱藏標志,其詳細使用方法如下:

    SYNOPSIS
    chflags [-fhv] [-R [-H | -L | -P]] flags file ...
     
    DESCRIPTION
    The chflags utility modifies the file flags of the listed files as specified by the flags operand.
     
    The options are as follows:
     
    -f Do not display a diagnostic message if chflags could not modify the flags for file, nor modify
    the exit status to reflect such failures.
     
    -H If the -R option is specified, symbolic links on the command line are followed. (Symbolic
    links encountered in the tree traversal are not followed.)
     
    -h If the file is a symbolic link, change the file flags of the link itself rather than the file
    to which it points.
     
    -L If the -R option is specified, all symbolic links are followed.
     
    -P If the -R option is specified, no symbolic links are followed. This is the default.
     
    -R Change the file flags for the file hierarchies rooted in the files instead of just the files
    themselves.
     
    -v Cause chflags to be verbose, showing filenames as the flags are modified. If the -v option is
    specified more than once, the old and new flags of the file will also be printed, in octal
    notation.
     
    The flags are specified as an octal number or a comma separated list of keywords. The following key-
    words are currently defined:
     
    arch, archived
    set the archived flag (super-user only)
     
    opaque set the opaque flag (owner or super-user only). [Directory is opaque when viewed through
    a union mount]
     
    nodump set the nodump flag (owner or super-user only)
     
    sappnd, sappend
    set the system append-only flag (super-user only)
     
    schg, schange, simmutable
    set the system immutable flag (super-user only)
     
    uappnd, uappend
    set the user append-only flag (owner or super-user only)
     
    uchg, uchange, uimmutable
    set the user immutable flag (owner or super-user only)
     
    hidden set the hidden flag [Hide item from GUI]
     
    As discussed in chflags(2), the sappnd and schg flags may only be unset when the system is in single-
    user mode.
     
    Putting the letters ``no'' before or removing the letters ``no'' from a keyword causes the flag to be
    cleared. For example:
     
    nouchg clear the user immutable flag (owner or super-user only)
    dump clear the nodump flag (owner or super-user only)
     
    Unless the -H or -L options are given, chflags on a symbolic link always succeeds and has no effect.
    The -H, -L and -P options are ignored unless the -R option is specified. In addition, these options
    override each other and the command's actions are determined by the last one specified.
     
    You can use "ls -lO" to see the flags of existing files.



下面提供一個中文版

    chflags
    名稱:
    chflags – 改變文件的標志
    概述:
    chflags [-fhv] [-R [-H | -L | -P]] 標志 文件
    描述:
    工具chflags修改指定文件的文件標志。
     
    選項如下:
    -f 如果chflags不能修改文件標志,nor modify the exit status to reflect such failures,則不顯示診斷信息。
    -H 如果開啟-R選項,將改變軟連接指向的文件的文件標志(遍歷樹中的軟連接除外)。
    -h 如果文件是軟連接,只改變該鏈接的文件標志,而不改變該鏈接所指向的文件的標志。
    -L 如果-R選項開啟,將改變所有軟連接所指向的文件的文件標志。
    -P 如果-R選項開啟,將不改變所有軟連接所指向的文件的文件標志。這是默認選項。
    -R Change the file flags for the file hierachies rooted int the files instead of just the files themselves.
    -v 當修改標志時顯示文件名。如果 –v 出現兩次以上,則以八進制同時顯示舊標志和新 標志。
     
    文件標志以一個八進制數或一系列以逗號分隔的關鍵詞來顯示。下面是當前定義的關 鍵詞:
    arch,archived
    存檔文件標志(超級用戶獨有)
    opaque 不透明文件標志(適用於文件所有者或超級用戶)
    nodump nodump文件標志(適用於文件所有者和超級用戶)
    sappnd,sappend
    僅允許附加 文件標志(超級用戶獨有)
    schg,schange,simmutable
    不可更改 文件標志(超級用戶獨有)
    sunlnk,sunlink
    不可刪除 文件標志(超級用戶獨有)
    uappnd,uappend
    只允許用戶附加 文件標志(適用於所有者和超級用戶)
    uchg,uchange,uimmutable
    不允許用戶更改 文件標志(適用於所有者和超級用戶)
    uunlnk,uunlink
    不允許用戶刪除 文件標志(適用於所有者和超級用戶)
     
    在關鍵詞前面添加或者去除“no”將清除相應的文件標志。例如:
    nouchg 清除 不可更改 文件標志(適用於所有者或超級用戶)
    dump 清除 nodump 文件標志(適用於所有者或超級用戶)
     
    八進制數值對應的文件標志:
    0 清除所有文件標志
    1 nodump
    2 uchg
    3 uchg,nodump
    4 uappnd
    10 opaque
    20 uunlnk
     
    Other combinations of keywords may be placed by using the octets assigned.但是,以上這些是最常用的。
     
    你可以使用 “ls -lo”來查看文件的文件標志。
     
    注意:能否改變某些標志依賴於當前內核的安全級別設定。查看security(7)來獲得更多的 信息。
    退出狀態:
    成功 0,失敗>0.
    實例:
    無
    參考:
    ls(1), chflags(2), stat(2), fts(3), security(7), symlink(7)
    標准:
    無
    歷史:
    chflags最早出現在4.4BSD當中。
    BUGS:
    Only a limited number of utilities are chflags aware. Some of these
    tools include ls(1), cp(1), find(1), install(1), dump(8), and restore(8).
    In particular a tool which is not currently chflags aware is the pax(1)
    utility.chio
————————————————
版權聲明:本文為CSDN博主「lipingqingqing」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/lipingqingqing/article/details/8844797


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM