Skip to content

File Types#

Reviewing our output again:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
michael@develop:~$ ls -la ~
total 32
drwxr-xr-x 4 michael michael 4096 Mar 18 10:11 .
drwxr-xr-x 4 root    root    4096 Mar 18 08:01 ..
-rw------- 1 michael michael  312 Mar 18 08:46 .bash_history
-rw-r--r-- 1 michael michael  220 Feb 25  2020 .bash_logout
-rw-r--r-- 1 michael michael 3771 Feb 25  2020 .bashrc
drwx------ 2 michael michael 4096 Mar 18 07:24 .cache
drwxrwxr-x 3 michael michael 4096 Mar 18 09:23 .local
-rw-rw-r-- 1 michael michael    0 Mar 18 10:11 .my_secrets
-rw-r--r-- 1 michael michael  807 Feb 25  2020 .profile
-rw-r--r-- 1 michael michael    0 Mar 18 07:52 .sudo_as_admin_successful

We can breakdown the very first group: -rw-r--r--. This group is in fact another series of groups:

  1. Type: -
  2. User permissions: rw-
  3. Group permissions: r--
  4. Other permissions: r--

Note

We'll discussed the permission groups shortly.

The very first column, a - in our case, is the file type.

All you need to know is that - means a file; d means a directory; and l means a (symbolic) link. Everything else is uncommon and can be looked up in a manual page.

Just learn to recognise files, directories, and links within a directory listing.

A symbolic link (l) is like a special file type that means the file you're seeing is actually an "address" to another file. If you open the file and edit it, you'll be editing the file to which the symbolic link points, not the symbolic link itself. If you delete the symbolic link, you may actually delete the file it points to and the link. Instead of using rm my_link, you would instead use unlink my_link to play it safe.

Here's an example of a symbolic link in a listing:

1
2
3
$ ll
lrwxr-xr-x  1 michaelc  wheel      30 18 May 10:24 document -> myfiles/important_document.txt
drwxr-xr-x  3 michaelc  wheel      96 18 May 10:23 myfiles

Note

This listing was generated on my macOS machine. I like to move between systems when demonstrating this kind of work because it shows not much changes between systems.

We have two things in the listing:

  1. A symbolic link: l
  2. A directory d

The link can be clearly seen in the listing: document -> myfiles/important_document.txt. We can look inside the files:

1
2
3
4
5
$ cat document
Hello, world

$ cat myfiles/important_document.txt
Hello, world

And if we edit document, we can see it affects the original file:

1
2
3
4
$ echo 'I have changed my mind: goodbye!' > document

$ cat myfiles/important_document.txt
I have changed my mind: goodbye!

I edited document, but it edited myfiles/important_document.txt.

This is a simple concept to understand. Just have a play around and create your own symbolic links using the ln -s command (and remember man ln, of course.)