pspvncRandom Homebrew: pspvnc
Portable VNC client
Friends: Coding 'n Cracking - Nymphaea - PS3 Forum - darkforestgroup - daxhordes.org - Tgames - coldbird - gopsp.it - pspstation.org - prometheus - hgoel.info - MakeSmartTV - ps vita

Understanding Linux file permissions

Things that don't go in any other category

Understanding Linux file permissions

Postby m0skit0 » Mon Apr 11, 2011 7:11 am

Since I saw some Linux newcomers having file permission problems (such as "Permission denied" when trying to run an executable/script), I'm quickly introducing the UNIX-style file permissions.

On Linux (same goes for all POSIX systems) each file has its own permissions in relation to the system users, split between owner, group and others. Owner is the owner of the file, shown here (ls -l command output)

-rw-r--r-- 1 casey casey 3481 2011-04-02 09:49 /home/casey/.bashrc

Group is the group of the owner of the file, shown here

-rw-r--r-- 1 casey casey 3481 2011-04-02 09:49 /home/casey/.bashrc

Others are all the other users. So for each of these user groups you can set the file permissions, which are shown here

-rw-r--r-- 1 casey casey 3481 2011-04-02 09:49 /home/casey/.bashrc

So discarding first flag (-rw-r--r--) there are 3 groups of 3 flags each. First 3 flags indicate owner permissions, which are rw-, which means read/write but no execute permissions. Next 3 flags are group permissions r-- and last are other users permissions r--.

To change the permissions for a given file you MUST either be its owner or root. Use the chmod command. There are several ways to use chmod. Easier way is

Code: Select all
chmod [u/g/o][+-][rwx] file_path

u - user, g - group, o- others
+ add permission, - remove permission
r - read, w - write, x - execute

For example chmod g-x file removes execution permissions for the file owner group.

Another more advanced use of chmod is using octal permissions, which goes like this: each of the grouped permissions are considered an octal number (3 bits) since they're flags (0 not set, 1 set). So for example rw- = 110 = 6. Grouping the 3 fields we get 3 octal digits. So for example, setting a file permissions to being all permissions for owner and only reading for the rest would go

Code: Select all
chmod 744 file

where 744 = 111 100 100 = rwxr--r--

All this can also be done by GUI selecting the file, properties then permissions. I still prefer doing it on the terminal because IMO it's faster, and you might find yourself needing to do it through console some day.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4783
Joined: Mon Sep 27, 2010 6:01 pm

Re: Understanding Linux file permissions

Postby ASKidwai » Mon Apr 11, 2011 8:06 am

For a moment I thought you were asking for help with Linux :lol:

This is a great guide. +1
Image
Image
Image
Image
ASKidwai
 
Posts: 1411
Joined: Mon Jan 10, 2011 7:42 am
Location: 'Ere and There

Re: Understanding Linux file permissions

Postby waratte » Mon Apr 11, 2011 12:12 pm

ASKidwai wrote:For a moment I thought you were asking for help with Linux :lol:

I'd be scared. :lol:

m0skit0, how can I write a script to simplify this process?
waratte
 
Posts: 4066
Joined: Wed Oct 20, 2010 12:03 am

Re: Understanding Linux file permissions

Postby m0skit0 » Mon Apr 11, 2011 12:22 pm

I'm definitely no Linux guru, I'm very far from that. So it's not strange to see me posting Linux questions, but not on these forums, I have a reputation to maintain :lol:

waratte wrote:m0skit0, how can I write a script to simplify this process?

Simplify which process? it's an explanation. There's no process, it's one single command (chmod). Why would you want a script for a single command? If you have to do it for several files or with conditions, then you can think of a script.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4783
Joined: Mon Sep 27, 2010 6:01 pm

Re: Understanding Linux file permissions

Postby waratte » Mon Apr 11, 2011 12:39 pm

m0skit0 wrote:I'm definitely no Linux guru, I'm very far from that. So it's not strange to see me posting Linux questions, but not on these forums, I have a reputation to maintain :lol:

waratte wrote:m0skit0, how can I write a script to simplify this process?

Simplify which process? it's an explanation. There's no process, it's one single command (chmod). Why would you want a script for a single command? If you have to do it for several files or with conditions, then you can think of a script.

Sorry, I wasn't done and I accidently touched send. I wanted to assign permissions to several files in a folder. There are multiple folders and I want to assign permissions to it's contents based on the name of the folder and automatically move them to a directory, also based on the name on the folder. Then, I want to compress each folder to a different "compressor" based on the name on the folder. Lastly, I want to copy those files to one directory, assign all their permissions to me and pack it in a ".tar" file. How would I change permissions based on folder name.
waratte
 
Posts: 4066
Joined: Wed Oct 20, 2010 12:03 am

Re: Understanding Linux file permissions

Postby m0skit0 » Mon Apr 11, 2011 12:48 pm

Hm your script goes far beyond file permissions or what's being discussed on this topic, but we can think about it on another thread. I would definitely do it with Perl, since I'm in love with it lately (even if Ruby programmers would kill me :lol: ), but you can certainly use BASH advanced scripting features to do so.

waratte wrote:How would I change permissions based on folder name.

You can't, because directories (not folders, that's too microsoftian) have their own permissions (which meaning is slightly different from file permissions, for example the "execute" flag marks if that directory can be made the current working directory), so changing a directory permissions actually doesn't change the files inside it (like on Windows). You'll need to change the permissions of each of the files contained on that folder. GUI is your best option if there are not much folders.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4783
Joined: Mon Sep 27, 2010 6:01 pm


Return to Off-Topic

Who is online

Users browsing this forum: hgoel0974 and 1 guest