Mac上查看和修改文件权限

在安装java过程中,修改环境变量的时候发现要改的文件是只读文件,没法顺利进行修改,于是在网上找方法,觉得这个办法最好用。
用vim打开文件:

sudo vim /etc/profile

按下i(insert)突然最后一行弹出一段红字:

W10: Warning: Changing a readonly file

意为我在更改一个只读文件,所以报错。

还有一种是在修改后保存退出的时候报错:

E12 Can’t open file for writing

解决方法是修改文件的读写权限。

##首先查看该文件的权限
ls -l /etc/profile
##结果是只读权限
-r--r--r-  1 root  wheel  340  9  9 1059 /etc/profile
##修改该文件的权限
sudo chmod o+w /etc/profile
##查看此时文件的权限
ls -l /etc/profile
##此时权限更改为
-r--r--rw-  1 root  wheel  340  9  9 11:27 /etc/profile

这样再用vim打开文件的时候就不会提示没有权限啦

你可能感兴趣的:(工具安装)