The Linux File System

Goals: Introduction to the Linux File System, its structure and how to navigate around it, as well as creating, moving and copying files and folders.

  • What the file system is, and a typical organization / hierarchy.

  • Some high-level comparison to that of Windows.

  • Absolute vs relative paths.

  • Commands: pwd, cd, ls, mv, cp, mkdir, rmdir, rm

  • History: history

  • File Ownership and Permissions.


  • Within this and following sections, we have tried to make the descriptions and examples generic.

  • If you are following along as part of a scheduled training or bootcamp, where you see <project-name> replace this with the project name being used for the workshop (which changes) and <username> with your username.

  • Also, the hostname that you might see might change depending on the cluster you’re using.

  • If you are training independently, please use your own project folder, but contact arcc-help@uwyo.edu if you would like a copy of the files and directories used in our examples.



Some high-level comparison to that of Windows

 

Windows

Linux

Structure

Uses (data) drives C:, D:, E:…

Uses a tree hierarchy starting at “/

Known as the root directory.

 

<drive>\<folder01>\<folder02> 

/<folder01>/<folder02> 

Syntax

Uses the back slash: “\”

Uses the forward slash: “/”

Home folder

C:\Users\<username>

/home/<username>

Application Install

C:\Program Files\

/usr/

Folder and Filenames

Case insensitive: FoLdEr = FOLDER

Case sensitive: FoLdEr ≠ FOLDER

 

 

Wherever you are within the hierarchy is known as your current working directory (cwd)


Linux OS General Structure


Linux Hierarchical Structure: Example

image-20240522-180610.png

Absolute Path: /home/arcc-t05/

Path starts with a “/”


Absolute Path: /home/arcc-t05/workshop/projects/p01/etc/


Relative Path: workshop/projects/p01/etc/

Path does not start with a “/”


Relative Path: p01/etc/


Ex: Starting at / (root), what is the absolute path to the bits folder?


Answer:

/usr/include/bits/


Ex: Starting in the home folder what is the relative path to the Jan folder?


Answer:

arcc-t05/workshop/data/2023/Jan/


Commands:

Commands are used to perform certain operating system tasks through the Command Line Interface, as directed by the interpreter (as opposed to a Graphical Interface Interpreter we would usually use).

The next couple of parts list and briefly summarize the commands we will be covering within this section:

pwd, cd, ls, mkdir, mv, cp, rmdir and rm.

We will then follow up with examples on how to use them.


<command --help> 

Command

Description

pwd

pwd: pwd [-LP] Print the name of the current working directory.

cd

cd: cd [-L|[-P [-e]] [-@]] [dir]     Change the shell working directory.

ls

Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default)

mkdir

mv


Commands: <command --help> 

Command

Description

cp

rmdir

rm


pwd: Print the name of the current working directory


cd: Change the shell working directory


cd: Change working directory (cont)


Answer:

Did we define an an absolute or relative path?

When we print out the working directory, we are presented with a '/' in front of opt, however when we changed directories to opt, our cd command did not have a '/'. Therefore, we defined the relative path to the opt directory.

 


cd: Change the shell working directory


Answer:

Relative path, since we specified the full path, starting with root: /



ls: List information about the FILEs (cwd by default)


mkdir: Create the DIRECTORY(ies), if they do not already exist


mkdir: Create the DIRECTORY(ies), if they do not already exist


mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY


mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY


cp: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY


cp: folders


rmdir: Remove the DIRECTORY(ies), if they are empty


rm: Remove (unlink) the FILE(s)


rm: Remove (unlink) the FILE(s)


rm: folders and file(s)


rm: WARNING

From the command-line there is NO trash bin!

Using rm/rmdir is FINAL!


history


Exercises: Navigation


Answers

  • Use: cd or cd ~ as a shortcut to return to your home folder instead of using a cd /home/$USER or cd /home/<insert_your_username>/

  • cd stands for: change directory


File Ownership and Permissions


File Ownership and Permissions

  • User: This is the owner of the file/folder. By default, the person who created it becomes its owner.

    • <username> is the owner

  • Group: A group is a collection of users. The primary purpose of the group is to define a set of privileges for a given resource that can be shared among the users within the group.

    • <project-name> is the group.

    • In general, for a workshop, all attending users / the arcc-txx users (if being used) have been setup to be within this group.

  • Other: This is any other user who has access to the file/folder. This person has neither created the file, nor do they belong to a user group.


Permission Denied


If we change directories, and go to /project/<project-name>/intro_to_linux, what permissions do the contents of this directory have?


Exercises: Permissions


Answers