This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 2: Commands

Variations of ls

face Harry Coppock

As we saw previously ls someDirectory lists the contents in someDirectory. However, ls can return more information than this!

  • ls -l lists the contents of the working directory with detailed contents.

If I run this command in one of my directories an example output would be below:

-rw-r--r-- 1 hgc19 ibug 2459 Aug 27 17:09 data_visualisation.py

The first entry is a 10-character string representing the file permissions. The first character represent the file type: ‘-’ for a regular file and ‘d’ for a directory.

The next 3 groups of 3 characters indicate the file permissions for (1) the user, (2) group members, (3) anyone else. The 3 characters set represent the rwx (read, write and execute) rights. Dashes indicate that a particular permission in the rwx sequence has not been enabled.

The next entry represents the number of links to another program or file elsewhere on the system (do not worry about this).

Then, we have the name of the user who owns the file (hgc19), the name of the group that has file permissions (ibug) in addition to the file’s owner, file size (in bytes), the last time the file was modified, and finally the name of the file /directory.

Exercise:

Using man ls, work out how to print out the contents of your Downloads directory ordered by date modified and display the file size in an appropriate unit e.g. Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte (human readable format) using the ls command.

Bonus:

For the above python file, data_visualisation.py, it appears that I (hgc19) do not have execute permissions. However, I can run python data_visualisation.py. You can check this out for yourself by creating a simple python file which prints something like ‘Hello World’, check the file permissions and run the script. Why can you run python files even if you don’t have execute permissions?