Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: Permission denied when trying to open a file

Tags:

linux

bash

I recently decided to try to learn some bash scripting and as a fun exercise I decided to make a script to open up a daily file for me to write notes in whenever the script is run.

It worked fine until I logged out and back in to the system later, when I received an error

/usr/local/bin/notes: line 45: /home/MY_USERNAME/notes/2010-10-01:Permission denied

Code

I might be mistaken, but this certainly doesn't seem like something that shouldn't require extra permissions, does it?

Editor is set to nano

File's permissions are -rw-rw-r--

Script's permissions are -rwxr-xr-x

like image 864
Mike Avatar asked Oct 01 '10 20:10

Mike


1 Answers

check the permission on the file with

ls -l /path/to/your/file

you should see something like

-rw-r--r--

r mean readable, w writeable, and x executable.

the first set is for your user, the second set of three is for your group, and the third set is for anyone.

so in my example, the file i have shown is read/write for me, and read only for my group and for any other user.

Use the chmod command to change permissions.

chmod 744 file

will make the file read/write/exec for you, and just read for user/world.

like image 103
hvgotcodes Avatar answered Sep 22 '22 09:09

hvgotcodes