在Mac提示符“权限被拒绝"上运行脚本 [英] Run script on mac prompt "Permission denied"

查看:848
本文介绍了在Mac提示符“权限被拒绝"上运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Mac的新手,对终端命令不熟悉,我将dvtcolorconvert.rb文件放在卷的根目录中,此ruby脚本可以将xcode 3主题转换为xcode 4主题格式,即xxxxxxxx.dvtcolortheme格式.

I'm new to mac with not familiar on terminal command, i put the dvtcolorconvert.rb file on root directory of my volume, this ruby script can converting xcode 3 themes into xcode 4 themes format, which is xxxxxxxx.dvtcolortheme format.

然后在终端上运行脚本/dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme,但始终提示"权限被拒绝".

Then run the script /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme on terminal, but it's always prompt "Permission denied".

这是怎么了?有人可以帮助我解决这个问题吗?谢谢.

what's wrong with this? Anybody can help me solve this problem? Thanks.

推荐答案

在尝试使用sudo

尝试运行sudo /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme

sudo命令以超级用户"或"root"特权执行后面的命令.这应该使您可以从命令行执行几乎所有内容.也就是说,不要这样做!!如果您在计算机上运行脚本并且不需要它来访问操作系统的核心组件(我猜您不是,因为在您的主目录(〜/)内的某个东西上调用脚本,则该脚本应从您的主目录中运行,即:

The sudo command executes the commands which follow it with 'superuser' or 'root' privileges. This should allow you to execute almost anything from the command line. That said, DON'T DO THIS! If you are running a script on your computer and don't need it to access core components of your operating system (I'm guessing you're not since you are invoking the script on something inside your home directory (~/)), then it should be running from your home directory, ie:

~/dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme

将其移动到〜/或子目录,然后从那里执行.您永远都不会在这里遇到权限问题,也不会有访问或修改对操作系统至关重要的内容的风险.

Move it to ~/ or a sub directory and execute from there. You should never have permission issues there and there wont be a risk of it accessing or modifying anything critical to your OS.

如果仍然有问题,可以在与ruby脚本相同的目录中运行ls -l来检查文件的权限.您将获得如下内容:

If you are still having problems you can check the permissions on the file by running ls -l while in the same directory as the ruby script. You will get something like this:

$ ls -l  
total 13  
drwxr-xr-x    4 or019268 Administ    12288 Apr 10 18:14 TestWizard  
drwxr-xr-x    4 or019268 Administ     4096 Aug 27 12:41 Wizard.Controls  
drwxr-xr-x    5 or019268 Administ     8192 Sep  5 00:03 Wizard.UI  
-rw-r--r--    1 or019268 Administ     1375 Sep  5 00:03 readme.txt

您会注意到readme.txt文件在左侧显示-rw-r--r--.这显示了该文件的权限.右边的9个字符可以分成3个字符,分别为'rwx'的组(读,写,执行).如果我想向该文件添加执行权限,我将执行chmod 755 readme.txt,而该权限部分将变为rwxr-xr-x.现在,我可以通过运行./readme.txt(./告诉bash在当前目录中查找所需的命令,而不是搜索$ PATH变量)来执行此文件.

You will notice that the readme.txt file says -rw-r--r-- on the left. This shows the permissions for that file. The 9 characters from the right can be split into groups of 3 characters of 'rwx' (read, write, execute). If I want to add execute rights to this file I would execute chmod 755 readme.txt and that permissions portion would become rwxr-xr-x. I can now execute this file if I want to by running ./readme.txt (./ tells the bash to look in the current directory for the intended command rather that search the $PATH variable).

schluchc 暗示要查看chmod的手册页,方法是运行man chmod.这是获取有关给定命令man <command>

schluchc alludes to looking at the man page for chmod, do this by running man chmod. This is the best way to get documentation on a given command, man <command>

这篇关于在Mac提示符“权限被拒绝"上运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆