OSX - always hide certain files

﹥>﹥吖頭↗ 提交于 2019-12-10 19:57:41

问题


I know how to show and hide hidden files in the Terminal - but is there a way to hide certain files like .DS_STORE when showing hidden files? Make certain files super-hidden, so to speak?


回答1:


Use chflags with the hidden option

ie: chflags hidden fileToHide to hide the file from the Finde

and chflags nohidden fileToHide to show the file

Please do keep in mind the warning in man page:

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.

What that means is that while you won't see in the Finder or Open/Save dialog boxes, the Terminal will still see it and possibly other programs that don't respect BSD flags.




回答2:


To follow up on @ibz's answer, an alias would work fine, but you may want to make a shell script that takes parameters for a little more flexibility.

#!/bin/bash

/bin/ls $@ | grep -v .DS_Store 

Create the above in ~/bin and name it lv, chmod 755 on it, and remember to add ~/bin to your path in your .bash_profile

export PATH=~/bin:$PATH

You can also name it ls as long as you put ~/bin first in your PATH and use the full path to /bin/ls in your script so that you don't get recursive interpretation. Whenever you want to use the real ls, then you'll need to specify the full path.




回答3:


To follow up on @tvanfosson's answer, a script would work fine, but you can make it simpler by defining a function in your .bashrc. :)

function lv { ls $@ | grep -v .DS_Store; }



回答4:


Do something like this in your .bashrc

alias lv="ls -al | grep -v .DS_Store"

Now use lv instead of ls to see all the files (including hidden), but excluding .DS_Store.



来源:https://stackoverflow.com/questions/393868/osx-always-hide-certain-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!