Jump To Content

The Shell - Permissions

File Ownership and Permissions

On Unix, every user belongs to one or more groups - the groups command will show you which ones you are in. Also, every file is owned by a particular user and a particular group. As a results, you can assign read (r), write (w), and execute (x) permissions independently to user, group, and others.
Read: can look at contents, but not modify them
Write: can modify contents
Execute: can run the file (e.g., it's a program)

ls -l shows this information, along with the file's size and a few other things. The permissions are displayed as three rwx triples. “Missing” permissions shown by a dash, "-". So, rw-rw-r-- means:
User and group can read and write
Everyone else can read, but not write
No one can execute

Directory Permissions

Execute permission means something different for directories. It means you can “go into” a directory, but does not mean you can read its contents. If tools/ has permission rwx--x--x , then:
If someone other than the owner does ls tools, permission is denied
But anyone who wants to can run tools/pfold

Changing Permissions

To change permissions, you need to use the command chmod. For example, chmod u+x broom allows broom's owner to run it, whereas chmod o-r notes.txt takes away the world's read permission for notes.txt.

Any set of shell commands can be turned into a program! If it's worth doing again, it's worth automating.
For example, create a file called nojunk
#!/usr/bin/bash
rm -f *.junk
(use man rm to find out what the “-f” flag does)

The line #!/usr/bin/bash means “run this using the Bash shell”. In fact, any program name can follow the #!

Now, change permissions to rwxr-xr-x, then run it with ./nojunk. Or, if $HOME/bin is in your search path, move it there. Don't call your temporary test programs test. There's already a /usr/bin/test on your computer, so your PATH may cause that program to run instead of your new one. Confusion results, so use something else!

Ownership and Permission: Windows

Of course, it all works differently on Windows - not better or worse, just different. Windows XP uses access control lists (ACLs). Every file and directory has a list of (who, what) pairs, where “who” can be a group. Some versions of Unix provide ACLs as well, but many tools don't understand them. Older versions of Windows (such as Windows 95 and Windows 2000) are fundamentally insecure, and shouldn't be used.

Cygwin does its best to make the Windows model look like Unix's, but when you trip over the differences, please consult a system administrator.

More Advanced Tools

chmod Change file and directory permissions.
du Print the disk space used by files and directories.
find Find files with names that match patterns, that are of a certain age or size, etc.
grep Print lines matching a pattern.
gunzip Uncompress a file.
gzip Compress a file.
lpr Send a file to a printer.
lprm Remove a print job from a printer's queue.
lpq Check the status of a printer's queue.
ps Display running processes.
tar Archive files.
which Find the path to a program.
who See who is logged in.
xargs Execute a command for each line of input.
ashchristopher
  • Authority 58
Post Body
ashchristopher said:

chmod also takes octal values for permissions.

for example: rwx r—r— == 744

  • Quote
  • Posted 9 months ago.
  • Your comment will be modifiable for 10 minutes after posted.

Page Author

Avatar
viverson
Name
viverson

From Here You Can…

Information

  • 115 Views
  • 1 Comment
  • Ratings Likes 0 Negative 0
© 2008 Vicki Iverson, All Rights Reserved.