How to see a file's permissions?

Listing permissions and file owners is easy and straightforward, which makes sense, given how important it al is in Linux.

The command to see the permissions will be ls (list directory contents). The ls command can list all files in a directory, or information about a given file if you feed it a filename.

When you type the ls command without any arguments, it will give a list of filenames, without any of their attributes, which is useful if you only need to know what files are present, and are not interested in more detailed file information.

To modify the output, most commands take so-called "parameter", or "arguments", which usually is either a letter or set of letters, following a dash, or a longer string followed by two dashes. Usually, each parameter has alternatives in both formats. For example, when you want ls to also list hidden files (which in UNIX and Linux means files whose names start with a .), you can either type

ls -a

which is just short for

ls --all

Command line parameters are case-sensitive, i.e. ls -a is not the same as ls -A, which is short for --almost-all, that will omit . (current directory) and .. (previous directory).

Parameters can also be combined. The ls command also takes an -l parameter (see below), which is often combined with the -a parameter, like this:

ls -la

which will list every file, including hidden files, in a long listing format (again, see below).

Calling the ls command with the -l parameter (meaning "long listing format") like this

ls -l

will change the output to include al sort of file information, including file permissions, owner and last modified date, followed by the filename itself. Calling it in a user's home directory would result in something like

ls -l

total:13
drwxr-xr-x  3 beowulf users 4096 Oct  9 12:17 Desktop
drwxr-xr-x 64 beowulf users 4096 Oct 23 14:57 Documents
drwxr-xr-x 56 beowulf users 4096 Jan  1 05:34 Downloads
-rw-r--r--  1 beowulf users  125 Mar 14 17:45 some_text_file.txt
-rw-rw-rw-  1 beowulf users 1295 Dec 32 23:61 some_log_file.log

There's a lot going on there. First, there is total, which basically counts the total blocks taken up on disk by everything listed. Makes little sense to see it, and you'd also need to know the default block size etc. What comes after is a lot more interesting. For each file, you would see the permissions, the number of links/files contained, user (owner), group assigned, size (in bytes), last modified date, and the filename itself.

To break the above output down:

Permissions # of files Owner Group Size (bytes) Last modified Filename
drwxr-xr-x 3 beowulf users 4096 Oct 9 12:17 Desktop
drwxr-xr-x 64 beowulf users 4096 Oct 23 14:57 Documents
drwxr-xr-x 56 beowulf users 4096 Jan 1 05:34 Downloads
-rw-r--r-- 1 beowulf users 125 May 14 17:45 some_text_file.txt
-rw-rw-rw- 1 beowulf users 1295 Dec 32 23:61 some_log_file.log

You now know everything about every file in the current directory.

Interestingly the -l parameter does not have a long alternative.

If you are interested in only a single file, you can specify a filename after the parameters, so the output will be restricted to that single file, like

ls -l some_text_file.txt

-rw-r--r-- 1 beowulf users 125 Mar 14 17:45 some_text_file.txt

So now you know that the file named some_text_file.txt is owned by the user beowulf, assigned the group users, and its permissions are -rw-r--r--, in other words, 644, meaning everyone can read the file, only its owner can modify it, and nobody can execute it.

Wanna try something totally meaningless? Type ls <filename>, without parameters. It will list the file without any file information included, basically giving you back the filename you've typed. This could even make sense if you only want to see if a given file exists and you are bound to the command line. :)