Apr 09 2007

LCoTD: The Filesystem (Part 3: Operating System Directories and File Protections)

Published by georgegumpert at 6:27 pm under Linux Command of the Day, Linux Resources, Series ()

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

In today’s installment, I will cover Operating System directories, and file protections. The ls and cat commands will be used, and you will be introduced to chown, chmod, and chgrp.

Operating System Directories

Operating System Directories are where the mystical files that keep the operating system alive live, like so:

/boot
Files for booting the system. This is where the kernel lives, typically named /boot/vmlinuz.

/lost+found
Damaged files that were rescued by a disk recovery tool.

/proc
Describes currently running processes; for advanced users.

The files in /proc provide views into the running kernel and have special properties. They always appear to be zero sized, read-only, and dated now:

$ ls -l /proc/version
-r--r--r-- 1 root root 0 Oct 3 22:55 /proc/version

However, their contents magically contain information about the Linux kernel:

$ cat /proc/version
Linux version 2.4.22-1.2115.nptl ....

Mostly these files are used by programs. Go ahead and explore. Here are some examples.

/proc/ioports A list of your computer’s input/output hardware.
/proc/version The operating system version. The uname command prints the same information.
/proc/uptime System uptime, i.e., seconds elapsed since the system was last booted. run the uptime command for a more human-readable result.
/proc/nnn Where nnn is a positive integer, information about the Linux process with process ID nnn.
/proc/self Information about hte current process you’re running: a symbolic link to /proc/nnn file, automatically updated. Try ls -l /proc/self a few times in a row: you’ll see /proc/self changing where it points.

File Protections

A Linux system may have many users with login accounts. To maintain privacy and security, each user can access only some files on the system, not all. This access control is embodied in two questions:

Who has permission Every file and directory has an owner who has permission to do anything with it. Typically the user who created a file is its owner, but relationships can get more complex.
Additionally, a predefined group of users may have permission to access a file. Groups are defined by the system administrator.

Finally, a file or directory can be opened to all users with login accounts on the system. You’ll also see this set of users called the world or simply other.

What kind of permission is granted? File owners, groups, and the world may each have permission to read, write (modify), and execute (run) particular files. Permissions also extend to directories, which users may read (access files within the directory), write (create and delete files within the directory), and execute (enter the directory).

To see the ownership and permissions of a file, run:

$ ls -l filename

To see the ownership and permissions of a directory, run:

$ ls -ld directory_name

The file permissions are the 10 leftmost characters in the output, a string of r (read), w (write), x (execute), and other letters. For example:

drwxr-x---

Here’s what these letters and symbols mean:

Position Meaning
1

File type:
- = file
d = directory
l = symbolic link
p = named pipe
c = character device
b = block device.

2-4 Read, write, and execute permissions for the file’s owner.
5-7 Read, write, and execute permissions for the file’s group.
8-10 Read, write, and execute permissions for all other users.

To change the owner, group ownership, or permissions of a file, use the chown, chgrp, and chmod commands, respectively.

Sphere: Related Content

If you found this article useful and use StumbleUpon, please give it a thumbs up so more people can read it! Thank you!

Please take the time to check out this thread and leave a comment letting me know what you would like to see from this site. It's still relatively young and trying to find its way- you can make design pitstop the resource you always wanted!

One Response to “LCoTD: The Filesystem (Part 3: Operating System Directories and File Protections)”

  1. Hi George - thx for including the Related Content plug-in on your site. Best,

    Tony

Leave a Reply