设为首页 收藏本站
查看: 871|回复: 0

[经验分享] mac 显示隐藏的文件

[复制链接]

尚未签到

发表于 2016-5-17 11:06:49 | 显示全部楼层 |阅读模式
It seems like every day I search Google for the command to show hidden files on Mac OS X, not to mention Googling for the command to then hide those hidden files a few minutes later.
Today I decided to make a short and easy to remember alias to speed up the process. All I need do now is type showFiles and hideFiles whenever I need to show/hide OS X’s hidden files. Here’s how you can do it too.

Show/Hide Hidden Files the Long Way

The long way to show hidden Mac OS X files is as follows:


  • Open Terminal found in Finder > Applications > Utilities
  • In Terminal, paste the following: defaults write com.apple.finder AppleShowAllFiles YES
  • Press return
  • Hold ‘alt’ on your keyboard, then right click on the Finder icon in the dock and click Relaunch.

DSC0000.png Relaunch Finder by right clicking the Finder Icon whilst hosting the ‘alt’ key



This will show all hidden files. To hide them again, follow the same steps but replace the Terminal command with:

defaults write com.apple.finder AppleShowAllFiles NO
It’s not the longest set of instructions or the biggest command to commit to memory but if you’re doing this a lot, it’s worth spending a few minutes now to save yourself a lot more time in the future.

Show/Hide Hidden Files using Terminal Aliases

A Terminal alias is a name or shortcut for one or multiple commands. Using an easy to remember alias, we can turn the above four step process into just one.
An alias can be made temporarily (just for the use of one terminal session) or permanently. As we want this to be a shortcut used now and in the future, let’s make it permanent:


  • Open Terminal found in Finder > Applications > Utilities
  • In Terminal, paste the following: sudo nano ~/.bash_profile
  • Enter your Mac’s administration password if required, then hit return
  • At the bottom of the open .bash_profile file, paste the following: alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'

  • Below that, paste the following: alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'

  • Press ctrl + O and hit return to save the file
  • Press ctrl + X to exit the file and return to the command line
  • In Terminal, paste the following: source ~/.bash_profile to refresh your profile and make the aliases available

DSC0001.png Adding aliases to .bash_profile via Terminal



Now when you want to show hidden files, all you need type in Terminal isshowFiles, then hideFiles when you want to hide them.
If you want to modify the behaviour or alias names, let’s take a closer look at the commands you just added:

alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app'

alias tells Terminal we’re adding a new alias.
showFiles is the name of the alias. Change this to what you wish.
We then give the alias two commands. The first being:

defaults write com.apple.finder AppleShowAllFiles YES;
This is the command to show hidden files and is ended with a semi-colon ; so we can then use the second command:

killall Finder/System/Library/CoreServices/Finder.app
This will relaunch the Finder (to replicate the step of holding ‘alt’ on the keyboard then right clicking the Finder icon in the dock).

Conclusion

With the aliases set up, all you need do in the future is type showFiles andhideFiles to show and hide Mac OS X’s hidden files respectively.
Aliases can be used to speed up your interaction with the Terminal. Set up an alias for navigating to your most used directories, to commit to a GitHub repo and so on.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-218183-1-1.html 上篇帖子: Mac下SecureCRT破解 下篇帖子: PHP获取本机网卡的MAC地址
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表