About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Introduction to Linux
Richard W. Pazzi
Ontario Tech University
Figure 1: By [email protected] Larry Ewing and The GIMP,
Attribution, https://commons.wikimedia.org/w/index.php?curid=80930
1 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Overview
About the labs
The Linux file system
Manipulating the file system
Manipulating things in the terminal
2 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Assignments
▶ Every lab will have an assignment
▶ Assignments will open on the day of the lab
▶ Assignments are due one week after the lab
3 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Ways to run Linux
▶ Virtual Machines (cloud or local)
▶ WSL (if host operating system is Windows)
▶ https://docs.microsoft.com/en-us/windows/wsl/install
▶ Natively (install it on your PC)
▶ macOS is a BSD distribution
▶ BSD and Linux are UNIX-based systems
▶ Any distribution is fine, but commands may differ
4 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Linux distros
Figure 2: Linux distros
5 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
The Linux file system
Figure 3: Linux file system
6 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
The home directory (∼)
▶ Default directory when you open a new terminal
Figure 4: New terminal window
7 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Manipulating the file system
▶ We can list contents, create, remove, navigate, etc.
▶ Each operation is performed using a specific command (additional
flags may be necessary)
▶ Frequently-used commands:
▶ pwd - print name of current/working directory
▶ echo - display a line of text
▶ ls - list directory contents
▶ mkdir - make directories
▶ touch - change file timestamps
▶ rm - remove files or directories
▶ mv - move (rename) files
▶ cp - copy files and directories
▶ cat - concatenate files and print on the standard output 8 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Using pwd
▶ pwd is used to see where you are in the filesystem
Figure 5: Use of pwd
9 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Using echo
▶ echo is used to see lines of text
▶ Most commonly used to send text to other commands and print
environment variables
Figure 6: Use of echo
10 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Listing
▶ ls <folder name> lists the contents of a directory
▶ To show hidden files/directories, include the -a flag
Figure 7: Listing contents
11 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Creating
▶ mkdir <folder name> creates directories
▶ touch <file name> creates files
Figure 8: Creating files and directories
12 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Removing
▶ rm <name> removes a file
▶ The -r flag removes items in a directory recursively, and then the
directory itself
Figure 9: Removing files and directories
13 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Moving (or renaming)
▶ To rename, mv <name> <new name>
▶ To move, mv <item> <destination>
Figure 10: Moving files and directories
14 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Copying
▶ cp <file> <destination> copies a file
▶ The -r flag copies folders and its contents to the destination
Figure 11: Copying files and directories
15 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Viewing contents of a file
▶ cat <name> prints the contents of a file
Figure 12: Printing the contents of a file
16 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Navigating
▶ cd <folder> goes to a directory
▶ .. represents the parent directory (to go back)
Figure 13: Navigating the file system
17 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Manipulating things in the terminal
▶ We can edit things, as well as change their permissions
▶ Famous CLI-based editors are vim, nano and emacs
▶ To edit a file, use editor name followed by file name
▶ E.g.: vim new file
▶ E.g.: nano new file
18 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Permissions
▶ Just like Windows, Linux also has permissions assigned to each
file/directory
▶ chmod changes permissions
▶ chown changes owner
19 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Listing permissions
▶ Permissions can be listed using ls -l
▶ -l means long output
Figure 14: Listing permissions
20 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Permissions explained
▶ Breaking the 10 fields down:
▶ E.g.: {-}{[rw-][r–][r–]}. {1} {uncle opal} {uncle opal} {0} {Sep 5
14:21} {new file}
▶ Field 1: The first character denotes if item is file (-), directory (d),
or a soft link (l)
▶ Fields 2, 3, 4: in groups of three, permissions that the owner, group
and others have over the item
▶ Field 5: number of links or directories inside this directory
▶ Field 6: who owns the item
▶ Field 7: to which group item belongs
▶ Field 8: size in bytes
▶ Field 9: date and time of last modification
▶ Field 10: item name
21 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Changing permissions
▶ Possible item permissions are read (4), write (2), execute (1), no
permission (0)
▶ To change permissions of an item, the chmod command must
contain three integers with the sum of the values
▶ Example 1: chmod 000 my file removes all permissions from
everyone over the item
▶ Example 2: chmod 400 my file gives the owner permission to
read, and no permissions to group and others
▶ Example 3: chmod 666 my file gives everyone permission to read
and write to that item
▶ Example 4: chmod 777 my file gives everyone permission to
read, write and execute item
22 / 23
About the labs The Linux file system Manipulating the file system Manipulating things in the terminal
Introduction to Linux
Richard W. Pazzi
Ontario Tech University
Figure 15: By [email protected] Larry Ewing and The GIMP,
Attribution, https://commons.wikimedia.org/w/index.php?curid=80930
23 / 23