...
Table of Contents | ||
---|---|---|
|
...
01 Getting Started
01.01 Getting Started: What is Linux and Linux Distributions (distro)
What is an Operating System?
When you turn your device on, it boots up the operating system, which The main software on a system. It manages the communication/interface between your applications and the hardware it is running on.
As shown in the image above, an operating system (OS) functions between the computer’s hardware and the applications that run on the computer.
What is Linux?
Linux is an Operating Systems – similar to Windows, Mac OS, iOS, Android.
Linux is open-source – freely available – so you can download, modify and redistribute.
Due to this there are 10s of varieties of Linux Distributions (distros):
Debian
Ubuntu (based on Debian)
Fedora
Amazon Linux 2
Commercial: Red Hat (which we are using today)
Rocky Linux
There is a lot of commonality across these distros.
...
01.02 Getting Started: Types of Environments
Types of Environment:
Desktop: Windows type Graphical User Interface (GUI) - mouse point and click.
Terminal: Program that opens a graphical window and runs a:
Shell which is a command interpreter that processes the typed commands.
Interface to the OS.
Provides a Command-Line Interface (CLI) – text-based input/output.
Different Shells share common commands, but syntax and behavior can be different.
...
02 Using the Terminal
What does a prompt look like?
General syntax of shell command.
Commands/options are case sensitive.
Getting Help:
Man pages (
man
)Options:
<command> --help
...
02.01 Login
Open up Chrome
Navigate to: https://southpass.arcc.uwyo.edu/
Start Beartooth Shell Access
...
...
...
Headers and Sections
...
Code Examples
...
Two Column Tables are nice ways to separate content/ Background info along with a code example on the same “Slide”. Please notice the table width. This should stop scroll bars from appearing
Bullets are nice to include for distinct points
yep
they
sure
are
This is 14 lines
...
Code Block |
---|
Please use the "code snippet" in the + button when creating code examples.
Also please do not go past the width of the table.
This is to prevent scroll bars appearing This is the Max number of code lines to show an example
|
Straight Code - No context
Code Block |
---|
Limit to 16 lines in the example. This is the end |
Same Thing With Images
...
Two Column Tables are nice ways to separate content/ Background info along with an image example on the same “Slide”. Please notice the table width. This should stop scroll bars from appearing
Bullets are nice to include for distinct points
yep
they
sure
are
This is 14 lines
...
...
Alternatively No Table
...
Finally The End
...
Link to Previous sub-module or Home Module
...
...
02.02 Download Slides
...
...
02.03 The Command-Line Prompt
...
02.04 Syntax of a Shell Command
...
02.05 Case Sensitive
Code Block |
---|
# Lists what is in the current location.
[arcc-t05@blog1 ~]$ ls
Desktop Documents Downloads
# Throws an error.
[arcc-t05@blog1 ~]$ LS
-bash: LS: command not found
Filename ≠ FiLeNaMe ≠ FILENAME |
Code Block |
---|
Filename ≠ FiLeNaMe ≠ FILENAME |
...
02.06 Getting Help: man
Code Block |
---|
[arcc-t05@blog1 ~]$ man ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alpha‐
betically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
...
Manual page ls(1) line 1 (press h for help or q to quit) |
...
02.07 Getting Help: <command --help>
Code Block |
---|
[arcc-t05@blog1 ~]$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE with -l, scale sizes by SIZE when printing them;
e.g., '--block-size=M'; see SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
|
...
02.08 Getting Help: Options
Typically, options can have a:
short-name: “
-a
”:Single letter following a single “
-
”
long-name: “
--all
”:More descriptive word after two dashes “
--
”
Short options can be grouped:
“
ls -a –l
” can be shortened to “ls –al
”
...
02.09 Single vs Multiple Lines
Code Block |
---|
[arcc-t05@blog1 ~]$ ls -al ~
[arcc-t05@blog1 ~]$ ls \
> -al \
> ~ |
...
02.10 Exercises
Questions:
Is there a difference between running
ls
versusls -al
?How can you find out what the
–al
options do?What does the
pwd
command do?From the command line, what happens if you press the up/down arrow keys?
...
02.11 Answers
1: Is there a difference between running ls
versus ls -al
?
Code Block |
---|
[arcc-t05@blog1 ~]$ ls
Desktop Documents Downloads
[arcc-t05@blog1 ~]$ ls -al
total 76
drwxr-x--- 8 arcc-t05 arcc-t05 4096 Oct 3 13:57 .
drwxr-xr-x 925 root root 32768 Sep 27 16:21 ..
-rw------- 1 arcc-t05 arcc-t05 212 Sep 12 15:44 .bash_history
-rw-r--r-- 1 arcc-t05 arcc-t05 18 Aug 10 17:00 .bash_logout
-rw-r--r-- 1 arcc-t05 arcc-t05 141 Aug 10 17:00 .bash_profile
-rw-r--r-- 1 arcc-t05 arcc-t05 376 Aug 10 17:00 .bashrc
drwx------ 3 arcc-t05 arcc-t05 4096 Sep 12 11:36 .config
drwxr-xr-x 2 arcc-t05 arcc-t05 4096 Aug 10 17:00 Desktop
drwxr-xr-x 2 arcc-t05 arcc-t05 4096 Aug 10 17:00 Documents |
...
02.12a Answers
2: How can you find out what the –al
options do?
Use
man ls
orls --help
-a, --all do not ignore entries starting with .
-l use a long listing format
Options are also case sensitive:
Code Block [arcc-t05@blog1 ~]$ ls -A .bash_history .bash_profile .config Documents .emacs .kshrc .mozilla .zshrc .bash_logout .bashrc Desktop Downloads .esd_auth .lesshst .sshWhat does the pwd command do?
...
02.12b Answers
3: What does the pwd
command do?
Use
man pwd
orpwd --help
pwd - print name of current/working directory
4: From the command line, what happens if you press the up/down arrow keys?
Steps through the previous commands you’ve typed.
...
03 File System
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.
...
03.01 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. |
|
|
|
Syntax | Uses the back slash: “\” | Uses the forward slash: “/” |
Home folder |
|
|
Application Install |
|
|
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) |
...
03.02 Linux Hierarchical Structure: Example
...
03.03 Absolute Path: /home/arcc-t05/
Path starts with a “/”
...
03.04 Absolute Path: /home/arcc-t05/workshop/projects/p01/etc/
...
03.05 Relative Path: workshop/projects/p01/etc/
Path does not start with a “/”
...
03.06 Relative Path: p01/etc/
...
03.07 Ex: Starting at / (root), what is the absolute path to the bits folder?
...
03.08 Ans: /usr/include/bits/
...
03.09 Ex: Starting in the home folder what is the relative path to the Jan folder?
...
03.10 Ans: arcc-t05/workshop/data/2023/Jan/
...
03.11a Commands: <command --help>
Command | Description | ||
pwd |
| ||
cd |
| ||
ls |
| ||
mkdir |
| ||
mv |
|
...
03.11b Commands: <command --help>
Command | Description | ||
cp |
| ||
rmdir |
| ||
rm |
|
...
03.12 pwd: Print the name of the current working directory.
Code Block |
---|
# Reset: Type the following:
[arcc-t05@blog1 ???]$ cd
[arcc-t05@blog1 ~]$
# The ~ “tilda” character represents your home directory.
[arcc-t05@blog1 ~]$ pwd
/home/arcc-t05
|
...
03.13a cd: Change the shell working directory.
Code Block |
---|
# Reset: cd
# Move up one level.
# Move into the folder’s parent.
[arcc-t05@blog1 ~]$ cd ..
[arcc-t05@blog1 ~]$ pwd
/home
[arcc-t05@blog1 home]$ cd ..
[arcc-t05@blog1 /]$ pwd
/
# In the ‘root’ folder
[arcc-t05@blog1 /]$ ls
# Are we defining an absolute or relative path?
[arcc-t05@blog1 /]$ cd opt
[arcc-t05@blog1 opt]$ pwd
/opt |
...
03.13b cd: Change the shell working directory.
Code Block |
---|
[arcc-t05@blog1 opt]$ cd
[arcc-t05@blog1 ~]$
# Are we defining an absolute or relative path?
[arcc-t05@blog1 ~]$ cd /usr/include/asm
[arcc-t05@blog1 asm]$ pwd
/usr/include/asm
[arcc-t05@blog1 asm]$ cd ../..
[arcc-t05@blog1 usr]$ pwd
/usr
[arcc-t05@blog1 usr]$ cd
[arcc-t05@blog1 ~] |
...
03.14 ls: List information about the FILEs (cwd by default)
Code Block |
---|
# Reset: cd
# List files in the user’s home folder.
[arcc-t05@blog1 ~]$ ls
# List long format that includes ownership and permission details.
[arcc-t05@blog1 ~]$ ls -l
# List all files, including hidden files and folders start with “.”.
[arcc-t05@blog1 ~]$ ls –a
# Notice how ‘short-name’ options are grouped.
# List all files with long format.
[arcc-t05@blog1 ~]$ ls –al
# List all files with long format, in reverse order.
[arcc-t05@blog1 ~]$ ls –alr
# List all files with long format, in reverse order, in human readable form.
[arcc-t05@blog1 ~]$ ls –alrh |
...
03.15a mkdir: Create the DIRECTORY(ies), if they do not already exist.
Code Block |
---|
$ cd
[~]$ ls
Desktop Documents Downloads
[~]$ mkdir folder01
[~]$ ls
Desktop Documents Downloads folder01
[~]$ mkdir folder01
mkdir: cannot create directory ‘folder01’: File exists
[~]$ cd folder01/
[folder01]$ pwd
/home/arcc-t05/folder01 |
...
03.15b mkdir: Create the DIRECTORY(ies), if they do not already exist.
Code Block |
---|
[folder01]$ mkdir folder02
[folder01]$ ls
folder02
[folder01]$ cd folder02/
[folder02]$ pwd
/home/arcc-t05/folder01/folder02
[folder02]$ cd ../..
[~]$ pwd
/home/arcc-t05 |
...
03.16a mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
Code Block |
---|
$ cd
# Create an empty file.
[~]$ touch myfil.txt
[~]$ ls
Desktop Documents Downloads folder01 myfil.txt
# Rename the file ‘myfil.txt’ to ‘myfile.txt’:
[~]$ mv myfil.txt myfile.txt
[~]$ ls
Desktop Documents Downloads folder01 myfile.txt |
...
03.16b mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
Code Block |
---|
# Move the file ‘myfile.txt’ into the directory ‘folder01’
[~]$ mv myfile.txt folder01/
[~]$ ls
Desktop Documents Downloads folder01
# We can ‘ls’ what is in a relative folder.
[~]$ ls folder01/
folder02 myfile.txt |
...
03.17 cp: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Code Block |
---|
$ cd
# Use the touch command to create an empty file.
[~]$ touch myfile02.txt
[~]$ ls
Desktop Documents Downloads folder01 myfile02.txt
# Copy (duplicate) a file.
[~]$ cp myfile02.txt myfile02b.txt
[~]$ ls
Desktop Documents Downloads folder01 myfile02b.txt myfile02.txt
# Copy a file into an existing folder.
[~]$ cp myfile02b.txt folder01/
[~]$ ls folder01/
folder02 myfile02b.txt myfile.txt |
...
03.18 cp: folders
Code Block |
---|
[~]$ cp folder01
cp: missing destination file operand after 'folder01'
Try 'cp --help' for more information.
[~]$ ls folder01
folder02 myfile02b.txt myfile.txt
[~]$ cp folder01 folder03
cp: -r not specified; omitting directory 'folder01’
# “recursively” copy a folder and all its contents.
[~]$ cp –r folder01 folder03
[~]$ ls
Desktop Documents Downloads folder01 folder03 myfile02b.txt myfile02.txt
[~]$ ls folder03
folder02 myfile02b.txt myfile.txt |
...
03.19 rmdir: Remove the DIRECTORY(ies), if they are empty.
Code Block |
---|
[~]$ ls
Desktop Documents Downloads folder01 folder03 myfile02b.txt myfile02.txt
[~]$ mkdir folder04
[~]$ ls
Desktop Documents Downloads folder01 folder03 folder04 myfile02b.txt
myfile02.txt
# Can remove folder04 since it is empty.
[~]$ rmdir folder04
[~]$ ls
Desktop Documents Downloads folder01 folder03 myfile02b.txt myfile02.txt
[~]$ rmdir folder03/
rmdir: failed to remove 'folder03/': Directory not empty |
...
03.20a rm: Remove (unlink) the FILE(s).
Code Block |
---|
[~]$ cd
[~]$ cd folder03
[folder03]$ ls
folder02 myfile02b.txt myfile.txt
[folder03]$ ls folder02/
[folder03]$
# ‘folder02’ is empty.
[folder03]$ rmdir folder02/
[folder03]$ ls
myfile02b.txt myfile.txt
[folder03]$ rm myfile.txt
[folder03]$ ls
myfile02b.txt
[folder03]$ rm myfile02b.txt |
...
03.20b rm: Remove (unlink) the FILE(s).
Code Block |
---|
[folder03]$ ls
[folder03]$
# ‘folder03’ is now empty.
[folder03]$ cd ..
[~]$ rmdir folder03/
[~]$ ls
Desktop Documents Downloads folder01 myfile02b.txt myfile02.txt
# This has taken a lot of individual steps.
# Can we do this quicker? |
...
03.21 rm: folders and file(s)
Code Block |
---|
[~]$ cd
[~]$ rm folder01/
rm: cannot remove 'folder01/': Is a directory
[~]$ rm --help
Usage: rm [OPTION]... [FILE]...
Remove (unlink) the FILE(s).
...
-r, -R, --recursive remove directories and their contents recursively
...
[~]$ rm -r folder01/
[~]$ ls
Desktop Documents Downloads myfile02b.txt myfile02.txt
# Can remove multiple files.
[~]$ rm myfile02b.txt myfile02.txt
[~]$ ls
Desktop Documents Downloads |
...
03.22 rm: WARNING
From the command-line there is NO trash bin.
Using rm
/rmdir
is FINAL!
...
03.23 history
Code Block |
---|
[~]$ history --help
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
Display or manipulate the history list.
...
[~]$ history
...
219 rm -f folder01/
220 rm -r folder01/
221 ls
222 rm myfile02b.txt myfile02.txt
223 ls
224 history
# Repeat command ‘223’
[arcc-t05@blog1 ~]$ !223
ls
Desktop Documents Downloads |
...
03.24 Exercises
Questions:
How can you return to your home folder?
What command do you use if you’ve forgotten where you are in the folder hierarchy?
How can you list what is in a folder as well as any subfolders?
Go back through the command related slides are try for yourself.
...
03.25 Answers
1: How can you return to your home folder?
Use:
cd
orcd ~
2: What command do you use if you’ve forgotten where you are in the folder hierarchy?
Use:
pwd
3: How can you list what is a folder as well as any subfolders?
Code Block |
---|
[]$ man ls
-R, --recursive
list subdirectories recursively
[]$ ls -R |
...
03.26 File Ownership and Permissions
What does the output of ls –l
mean?
Code Block |
---|
[arcc-t05@blog1 ~]$ cd /project/arccanetrain/intro_to_linux
[arcc-t05@blog1 intro_to_linux]$ ls -al
total 54
drwxrwsr-x 4 salexan5 arccanetrain 4096 Oct 6 08:09 .
drwxrws--- 40 root arccanetrain 4096 Oct 6 08:09 ..
drwxrwsr-x 2 salexan5 arccanetrain 4096 Oct 5 11:19 clusters
drwxrwsr-x 6 salexan5 arccanetrain 4096 Oct 5 14:56 data
-rw-rw-r-- 1 salexan5 arccanetrain 874 Oct 5 15:30 fruits.txt
-rw-rw-r-- 1 salexan5 arccanetrain 34472 Oct 5 10:57 software.csv
-rw-rw-r-- 1 salexan5 arccanetrain 1603 Oct 6 08:08 vegatables.txt
-rw-rw-r-- 1 arcc-t05 arccanetrain 26 Oct 5 07:20 workshop_all.txt
-rw------- 1 arcc-t05 arccanetrain 23 Oct 5 07:20 workshop_me.txt |
The first character on the left indicates if it is a directory “d” or a file “-”.
Code Block |
---|
drwxrwsr-x clusters # A folder.
-rw-rw-r-- workshop_all.txt # A file. |
...
03.27 File Ownership and Permissions
Code Block |
---|
-rw-rw-r-- 1 arcc-t05 arccanetrain 26 Oct 5 07:20 workshop_all.txt |
...
User: This is the owner of the file/folder. By default, the person who created it becomes its owner.
arcc-t05
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.
arccanetrain
is the group.All the
arcc-txx
users 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.
...
03.28 Permission Denied
Code Block |
---|
[]$ cd /project/arccanetrain/
# drwxr-sr-x 2 arcc-t01 arccanetrain 4096 May 16 16:26 arcc-t01
# No one other than arcc-t01 has permission to write within this folder.
[arccanetrain]$ cd arcc-t01/
# Can arc-t05 create (write) a file within this folder?
[arcc-t01]$ touch text.txt
touch: cannot touch 'text.txt': Permission denied
[arcc-t01]$ cd ../intro_to_linux
# -rw-rw-r-- 1 arcc-t05 arccanetrain 26 Oct 5 07:20 workshop_all.txt
# Anyone within the group can read/write this file.
[intro_to_linux]$ cat workshop_all.txt
Everybody can read this.
# Only arcc-t05 can read/write this file.
# -rw------- 1 arcc-t05 arccanetrain 23 Oct 5 07:20 workshop_me.txt
[intro_to_linux]$ cat workshop_me.txt
cat: workshop_me.txt: Permission denied |
...
03.29 Exercise: Try it
Code Block |
---|
[]$ cd /project/arccanetrain/
[arccanetrain]$ cd arcc-t05
[arcc-t05]$ touch test.txt
# Do you get a “Permission denied”?
# Navigate into the intro_to_linux folder.
[arcc-t05]$ cd ../intro_to_linux
[intro_to_linux]$ cat workshop_all.txt
Everybody can read this.
[intro_to_linux]$ cat workshop_me.txt
# Do you get a “Permission denied”?
# Can you cd into the /opt folder?
# Justify your answer.
# Can you cd into the /root folder?
# Justify your answer. |
...
03.30 Answer
Code Block |
---|
# Can you cd into the /opt folder?
[arcc-t05@blog1 ~]$ cd /opt
[arcc-t05@blog1 opt]$
# Can you cd into the /root folder?
[arcc-t05@blog1 ~]$ cd /root
-bash: cd: /root: Permission denied
# Justify your answer.
[arcc-t05@blog1 ~]$ ls -l /
...
# “other” has read permissions
drwxr-xr-x. 5 root root 43 Jun 26 11:47 opt
...
# No permission set for other read permissions
dr-xr-x---. 17 root root 4096 Oct 4 12:58 root |
...
04 Next Steps, Summary
...
04.01 Next Steps, Suggestions
Next Steps on using Linux:
Practicing using Linux online.
Dual boot a Windows machine with Linux.
Run a container image.
UW Researcher? Create a project on the Beartooth cluster with your PI.
...
04.02 Further Trainings: UWYO LinkedIn
...
Introduction to Linux
Learning Linux Command Line
Linux: Files and Permissions
Linux: Over and Installation
Learning Linux Shell Scripting
...
04.03 Request an Account with ARCC
...
...
04.04 Summary
In this workshop we have:
Introduced the basics of the Linux OS using a command-line interface.
Taken a look at the hierarchical file system and how to navigate around it.
Introduced the basics of file/folder permissions and ownership.
How to view, create, update and delete files and folders.
...
04.05 The End
Any questions?
Thank you.