02. File and Directory types and modes -d, rwx

Displaying a file's access attributes

To display a file's access attributes, use the ls command with a -l option.

$ ls -l helloWorld.txt
-rwxr--r-- 1 JohnDoe staff Apr 01 10:45 helloWorld.txt

The -rwxr--r-- are called the file attributes. They are made up of the file type, and file modes, as you can see in the figure below.

The file type and file modes

File type

The first character represents the file type. Here are the options it can have.

-
Just a regular file.
d
A directory.
l
A symbolic link.
Note that the file modes for a symbolic link will always be rwxrwxrwx, which are just dummy variables.
c
A character device that handles data as a stream of bytes.
eg. terminal/modem.
b
A block special file.
eg. hard drive, cd-rom.
p
Named pipe.
s
A socket that permits network and bidirectional links.

You'll mainly be dealing with - (regular files) and d (directories).

File modes

The next nine characters represent the file modes for owner, group and all, respectively.

owner, group and all permission file modes

Let's see what values these modes can hold.

Regular file access attributes

For a regular file, we have three simple attributes.

r
Read (open and see contents of).
w
Write (edit and saving).
x
Execute (runnable).

Thus, if the owner, group, or all has any of these attributes listed in their file mode, that means they are permitted to perform that command.

For example, let's look at file1.txt.

$ ls -l file1.txt
-rwxr----- 1 JohnDoe staff Apr 01 20:40 file1.txt

From the file type we can tell that this is a regular file (-) The file modes tell us that the user can read, write and execute (rwx), group members can only read (r--), and the world has no access to anything (---).

Directory file access attributes

To view the directory permission attributes, specify a -d option - otherwise the shell will just list the files within that directory.

$ ls -dl dir1
drwxr-xr-x@ 6 JohnDoe JohnDoe 204 Mar 30 13:15 dir1

If the file is a directory (i.e. its first letter is d), then its file attribute meanings are a little different.

r
Contents can be listed.
w
Directories can be created, deleted and renamed.
x
Allows directory to be opened and entered.

For both r and w attributes to be valid, the x attribute must also be set.

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Linux for Beginners

Take your Linux skills to the next level! Try Linux & UNIX

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources

Ad