Permission Denied on editing .bash_profile? - macos

I am trying to set adb path so I can access it easily from any directory.To set the path I am trying to edit the .bash_profile to insert the following line :
export PATH=$PATH:/Users/anshulsinghla/Library/Android/sdk/platform-tools/
Command I use to open file: open -e .bash_profile
But I always get a prompt saying "You Don't own the file .bash_profile and don't have permission to write to it. You can duplicate this document and edit the duplicate.Only the duplicate will include your changes".
I tried checking the who is the owner and what permission do they have with following command :
ls -la ~ | grep bash
Output:
-rw------- 1 anshulsinghla staff 6820 Jun 22 10:09 .bash_history
-rw-r--r-- 1 anshulsinghla staff 659 Jun 22 10:11 .bash_profile
It clearly shows I am the owner of the file and I do have read/write permissions but why it never let me edit the file, someone please help me.
Thanks

All the diagnostics have been using ~, so try:
open -e ~/.bash_profile
What did we learn from this? When diagnosing an error, always use exactly the same filename as was used in the error.
The original command did not try to edit .bash_profile in your home directory, yet in the comments everyone was looking at your home directory.

Related

Why can't I run the go binary from within the /bin directory?

I downloaded go1.7.5.darwin-amd64.tar.gz for osx 10.12.2.
Unpacked the tar and went to the /bin directory to see if the Go executable would run.
$ cd Downloads/go/bin
$ ls
total 54560
-rwxr-xr-x# 1 bryanwheelock staff 9884220 Feb 10 16:53 go
-rwxr-xr-x# 1 bryanwheelock staff 15065500 Feb 10 16:53 godoc
-rwxr-xr-x# 1 bryanwheelock staff 2976976 Feb 10 16:53 gofmt
bryanwheelock#Bryans-MacBook Fri Feb 10 16:57:45 ~/Downloads/go/bin
$ go version
-bash: go: command not found
When you type a command without giving the full path, your system will try to find it within all the folders provided in $PATH variable.
In typical Unix environment, your $PATH does not include "your current folder". So you need to either:
call go by its full path (i.e. $HOME/Downloads/go/bin/go); or
call go by its relative path (i.e. ./go); or
put $HOME/Downloads/go/bin in your $PATH variable; or
put . (Unix way of saying "your current folder") in your $PATH; or
put your go binary into folders that already in your $PATH. For example
sudo cp $HOME/Downloads/go/bin/* /usr/local/bin/.
sudo chmod +x go
seems like it does not have execute permission, so just change permission and run it then you should alias your go binary path to your environment to access binary every where.

Cannot cat a world readable file: permission denied

I want to read the content of a file at a known path in a different user home.
The file is world readable, and so are all the sub directories.
How ever, when I try to open it, I get a "permission denied"
cat /home/rails/current/tmp/pids/delayed_job.pid
cat: /home/rails/current/tmp/pids/delayed_job.pid: Permission denied
With
rails#tatoo:~/current/tmp/pids$ ls -l
total 4
-rw-r--r-- 1 rails rails 6 Dec 30 10:09 delayed_job.pid
What could I be missing ?
To be able to read a file, not only you need to have read access to the file r but you also need to have access right x for every directory in that file path up to the root directory.
As execution right doesn't make sense for a directory, the x bit is used to grant access rights for it.
Have a look here for a detailed explanation about directory permissions.

source .bash_profile permission denied

Mac Os Mavericks
added bin folder to home
added to .bash_profile this:
export PATH=$PATH;$HOME/bin
changed owner of .bash_profile to me (paul)
source ~/.bash_profile generates
/Users/paul/.bash_profile:4: permission denied: /Users/paul/bin
ls -la $HOME/bin is
drwxr-xr-x 2 paul staff 68 Aug 31 08:58 .
drwxr-xr-x+ 55 paul staff 1870 Aug 31 09:33 ..
What am I missing?
When you write
export PATH=$PATH;$HOME/bin
you actually have two commands export PATH=$PATH (that basically does nothing), and then $HOME/bin, which is expanded to /Users/paul/bin, and causes an error since you cannot execute a directory.
It should probably be
export PATH=$PATH:$HOME/bin
# ^
# + -------- colon (:) instead of semicolon (;)

Terminal issue my desktop has permission -rwxr-xr-x

So I did a command
sudo cp myfile /Desktop
my file was an executable and It changed my desktop to be an executable I need to reset to be a directory with permissions drwxrwxr-x+
Can someone please help Thanks
I think the correct command to change permissions on a file/folder is chmod or you could reset to default using umask (but I'm not sure about how to use this as well)

Run script on mac prompt "Permission denied"

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.
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.
Did you give yourself the rights to execute the script?
The following command as super user will do this for you:
sudo chmod 755 'filename'
For details you should read the man page of chmod.
Please read the whole answer before attempting to run with sudo
Try running sudo /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme
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.
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
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 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>
In my case, I had made a stupid typo in the shebang.
So in case someone else on with fat fingers stumbles across this question:
Whoops: #!/usr/local/bin ruby
I meant to write: #!/usr/bin/env ruby
The vague error ZSH gives sent me down the wrong path:
ZSH: zsh: permission denied: ./foo.rb
Bash: bash: ./foo.rb: /usr/local/bin: bad interpreter: Permission denied
You should run the script as 'superuser', just add 'sudo' in front of the command and type your password when prompted.
So try:
sudo /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme
If this doesn't work, try adapting the permissions:
sudo chmod 755 /dvtcolorconvert.rb
sudo chmod 755 ~/Themes/ObsidianCode.xccolortheme
To run in the administrator mode in mac
sudo su
use source before file name,,
like my file which i want to run from terminal is ./jay/bin/activate
so i used command "source ./jay/bin/activate"
Check the permissions on your Ruby script (may not have execute permission), your theme file and directory (in case it can't read the theme or tries to create other themes in there), and the directory you're in when you run the script (in case it makes temporary files in the current directory rather then /tmp).
Any one of them could be causing you grief.

Resources