Introduction to Linux: Course Overview and Objectives

I
n
t
r
o
d
u
c
t
i
o
n
 
t
o
 
L
i
n
u
x
C
D
 
P
o
o
n
,
 
M
a
r
k
 
R
e
e
d
,
 
W
i
l
l
i
a
m
 
S
c
h
u
l
z
h
t
t
p
s
:
/
/
i
t
s
.
u
n
c
.
e
d
u
/
r
e
s
e
a
r
c
h
-
c
o
m
p
u
t
i
n
g
/
ITS Research Computing
C
o
u
r
s
e
 
D
e
s
i
g
n
 
a
n
d
 
L
o
g
i
s
t
i
c
s
Course Design:
Lecture – background & intro to commands (~30 min)
Short Lab (~15 min)
Lecture – commands in detail (~40 min)
Final Lab (~35 min)
The exercises are an integral part of the course
Please 
follow
 along
 by trying examples if you like
learn by doing
Feel free to ask questions
Restrooms
Breaks
2
ITS Research Computing
C
o
u
r
s
e
 
O
u
t
l
i
n
e
Objectives
Operating Systems
History
Variations
User Interface
Commands
Conclusion
3
ITS Research Computing
O
b
j
e
c
t
i
v
e
s
What this course is:
An introduction to Linux hopefully to put it into a context
for better understanding
Gain the perspective to see what it is, what it can do,
why use it
What this course isn’t:
Just a list of Linux commands and what they do
(although there will be plenty of that :)
Not just to answer “How do I … ?”
4
ITS Research Computing
W
h
a
t
 
i
s
 
a
n
 
O
S
 
(
o
p
e
r
a
t
i
n
g
 
s
y
s
t
e
m
)
?
The most important program that
runs on a computer
Operating systems perform basic
tasks:
recognizing input from keyboard
and mouse
sending output to display screen
keeping track of files and
directories on the disk
controlling peripheral devices such
as disk drives and printers
networking, security, memory
management
5
ITS Research Computing
S
o
m
e
 
O
p
e
r
a
t
i
n
g
 
S
y
s
t
e
m
s
DOS, MS-DOS
MS Windows (95, 98, NT, Windows 10)
Linux: RedHat, SuSE, Ubuntu, 
Ubuntu Kylin,
Deepin, Windows Subsystem for Linux
Unix-like or *nix: HP-UX, Irix, Solaris, AIX, minix
 
MacOS variants, NeXT, XNU
6
ITS Research Computing
S
o
m
e
 
U
n
i
x
/
L
i
n
u
x
 
H
i
s
t
o
r
y
,
 
0
1969
 – First Unix was
developed at AT&T Bell
Labs by Ken Thompson
and Dennis Ritchie.
1977
 - First BSD
(Berkeley Software
Distribution) released by
Berkeley. Thomsen was
a visiting professor at
the time.
7
ITS Research Computing
S
o
m
e
 
U
n
i
x
/
L
i
n
u
x
 
H
i
s
t
o
r
y
,
 
1
1991
 - Linux was introduced by
Linus Torvalds, a student in
Finland, who posted to the
comp.os.minix:
"Hello everybody out there using
minix - I'm doing a (free)
operating system (just a hobby,
won't be big and professional like
gnu) for 386(486) AT clones…“
1993
 – FreeBSD project was
coordinated by Nate Williams,
Rod Grimes, and Jordan
Hubbard for running on 386
machines.
8
ITS Research Computing
S
o
m
e
 
U
n
i
x
/
L
i
n
u
x
 
H
i
s
t
o
r
y
,
 
3
The 
GNU
 (Gnu’s Not Unix) was
an effort to develop free and
open source applications.
Torvalds combined his 
kernel
with GNU software
 from
Richard Stallman (of emacs
fame) and the Free Software
Foundation, and Linux was off
and running.
Linux grows with contributions
world-wide
9
ITS Research Computing
K
e
y
 
F
e
a
t
u
r
e
s
 
o
f
 
L
i
n
u
x
Linux Features:
Multi-tasking
many programs
running
Multi-user
many users on the
same machine at once
Multi-platform
runs on many different
processor types
10
ITS Research Computing
V
a
r
i
a
t
i
o
n
s
 
o
n
 
a
 
T
h
e
m
e
11
ITS Research Computing
There are two major branches
 of Unix:
AT&T System V
BSD (Berkeley Software Distribution)
Lots of commercial Unix-like systems
AIX (IBM), IRIX (SGI), HP-UX (HP), OpenSolaris (Sun),
MacOS X. etc.
Linux is a Unix-like system
, free of proprietary
software for which source code is available and
freely distributed.
There are minor variations among these
Most are much more alike than they are different
S
o
m
e
 
L
i
n
u
x
 
d
i
s
t
r
i
b
u
t
i
o
n
s
There are many groups  packaging 
Linux
 for
distribution.
some freely available
others commercial
A partial listing:
Red Hat
CentOS
Ubuntu
Debian
SuSE
Inspur
Sunway RaiseOS
12
ITS Research Computing
U
s
e
r
 
I
n
t
e
r
f
a
c
e
The user interacts with the OS by giving it commands.
This interface is either 
via
command line or CLI (e.g., through the shell)
graphical user interface (GUI)
Don’t confuse the operating system’s user interface
with the OS itself (which does much more).
Most OSs can do both. Linux traditionally uses the
command line, but modern distributions rely heavily
on GUIs (similar to how DOS gave way to Windows)
13
ITS Research Computing
S
h
e
l
l
The 
C
ommand 
L
ine 
I
nterface (CLI) for Linux is
through the 
shell
This is the application (program) that interprets
what you type and carries out your directions
Common Shells:
tcsh – exTended C SHell
bash
 – Bourne Again Shell (most common, standard on
Longleaf and dogwood clusters)
ksh – Korn SHell
csh – C SHell (early popular shell)
14
ITS Research Computing
T
h
e
 
O
S
 
a
s
 
O
n
i
o
n
O
S
 
M
o
d
u
l
a
r
i
z
a
t
i
o
n
:
t
h
e
 
k
e
r
n
e
l
a
n
 
i
n
t
e
r
p
r
e
t
e
r
a
n
d
 
u
t
i
l
i
t
i
e
s
15
ITS Research Computing
Heart of the OS
The User Interface to the OS
The Stuff you want the system to do
E
x
a
m
p
l
e
 
L
i
n
u
x
 
c
o
m
m
a
n
d
s
The 
man
 (meaning manual) command for
documentation
Working with files and directories
pwd, cd, ls, mkdir, rmdir, cp, mv, rm, scp, cat, more,
less
Wildcards and regex
*, ?, [ ]
Permissions
chmod, chown, chgrp
Finding stuff
find, which, whereis, locate
There’s always more than one way to do something
16
ITS Research Computing
E
x
a
m
p
l
e
 
L
i
n
u
x
 
c
o
m
m
a
n
d
s
Packing and Unpacking stuff
tar, gzip, compress, gunzip, unzip, sort
Pipes and redirection
>, >>, <, |
Jobs and processes
ps, kill, pkill, ctrl-C, bg, ctrl-Z, &, fg, jobs
Quick and Easy: shortcuts and tricks of the trade
history, file completion, alias, environment variables
17
ITS Research Computing
H
i
e
r
a
r
c
h
i
c
a
l
 
F
i
l
e
 
S
y
s
t
e
m
Objectives
Operating Systems
History
Variations
User Interface
Commands
Conclusion
18
ITS Research Computing
C
o
m
m
a
n
d
s
 
i
n
 
G
e
n
e
r
a
l
Commands are 
case sensitive
Arguments typically are given with a dash “
-
multiple arguments usually only require the leading
dash
Commands are programs or applications that
the user invokes
The system finds the command by
specifying the full path
shell built in commands
looking in all directories in your PATH, typically this
includes /bin, /usr/bin (but maybe not “
.
”)
19
ITS Research Computing
A
 
C
o
m
m
a
n
d
 
t
o
 
E
x
p
l
a
i
n
 
C
o
m
m
a
n
d
s
man <command name>
man formats and prints the system manual pages
-k 
keyword search
do keyword search for applicable man pages (same as
the apropos command) in the whatis database
Arguments that appear in square brackets [
] are
optional
Of course, this information is available on the web now
20
ITS Research Computing
C
l
u
s
t
e
r
s
 
a
n
d
 
B
a
t
c
h
 
S
u
b
m
i
s
s
i
o
n
Slurm
 is the batch submission program we use on the
Longleaf and Dogwood clusters
Don’t run your HPC work on the login nodes
Submit your work to the entire cluster through 
Slurm
 using
sbatch
 and 
srun
The point here is to let the scheduler decide where and
when to best do the work
21
ITS Research Computing
W
o
r
k
i
n
g
 
w
i
t
h
 
F
i
l
e
s
 
a
n
d
D
i
r
e
c
t
o
r
i
e
s
22
ITS Research Computing
p
w
d
 
 
P
r
i
n
t
 
W
o
r
k
i
n
g
 
D
i
r
e
c
t
o
r
y
The 
pwd
 command shows the full, absolute path to your
current location in the filesystem
Absolute paths are “fully qualified” (e.g., /usr/bin/ls)
Relative paths reference locations one or more levels up or
down from the current working directory
“.” a period or single “dot” always refers to your current
directory
“..” dot-dot always refers to your 
parent directory 
(i.e.,
the one above your current directory in the  hierarchy)
After logging on to a Linux system, you are in your
home directory:
$ pwd /nas/longleaf/home/youronyen
23
ITS Research Computing
c
d
 
 
C
h
a
n
g
e
 
D
i
r
e
c
t
o
r
y
cd <path>
Changes your current working directory to path
(which can either an absolute or relative path).
a common relative paths to use is ‘
..
’ (i.e., the parent directory
of the current dir)
cd
by itself changes to your home directory
cd 
returns to your previous working directory
cd 
~
/projectA/run
the tilde grapheme ‘
~
’ is a shortcut for your home directory
24
ITS Research Computing
c
d
 
E
x
a
m
p
l
e
s
[longleaf]$ pwd
/nas/longleaf/apps/admin/scripts/accounts/longleaf
[longleaf]$ cd -
[longleaf]$ pwd
/nas/longleaf/home/wschulz
[longleaf]$ cd /etc
[longleaf]$ pwd
/etc
[longleaf]$ cd
[wschulz@longleaf-login2 ~]$ pwd
/nas/longleaf/home/wschulz
[wschulz@longleaf-login2 ~]$ cd -
/etc
[longleaf]$ cd ..
[longleaf]$ pwd
/
25
ITS Research Computing
l
s
 
-
-
 
L
i
s
t
ls
 - lists the contents of a directory.
If no target is given, then the contents of the
current working directory are displayed
By default, “
ls
” doesn't show you all the entries in
a directory - files and directories that begin with a
dot (
.
) are hidden (including '
.
' and '
..
' which are
always present)
The reason for this is that files that begin with a
.
” usually contain important configuration
information and should not be changed under
normal circumstances
26
ITS Research Computing
l
s
 
 
U
s
e
f
u
l
 
O
p
t
i
o
n
s
ls –a, show all files (or –A, to exclude ., ..)
ls –l, long listing
shows properties such as the size, type and
ownership of files
ls –t, sort by time
ls –d, list directory name, not contents
ls –h, human readable file sizes
ls –F,  classify, appends symbol indicating type
these can be combined,  “ls -a -l -h” or “ls –alh”
27
ITS Research Computing
l
s
 
-
a
l
ls -al 
lists directory contents with hidden files/directories
in long listing format
The command, 
ls -al
, lists the contents of a directory
including the hidden file/directory names starting with
"
.
" in a long listing.
totoro% ls -al
total 1096
drwxr-xr-x   27 root root   4096 2008-03-24 14:30 ./
drwxr-xr-x   27 root root   4096 2008-03-24 14:30 ../
drwxr-xr-x    2 root root   2048 2003-05-05 14:04 afs/
-rw-r--r--    1 root root      0 2008-03-24 14:30
.autofsck
...
totoro%
28
ITS Research Computing
l
s
 
-
l
 
 
L
i
s
t
 
C
o
n
t
e
n
t
s
 
i
n
 
L
o
n
g
 
F
o
r
m
The command 
ls -l
 lists the contents of a directory
in long listing format
29
ITS Research Computing
m
k
d
i
r
 
M
a
k
e
 
d
i
r
e
c
t
o
r
y
mkdir
 <New_Directory>
Creates a subdirectory called New_Directory in the
current working directory. You can only create
subdirectories in a directory for which you have write
permission.
-p option
creates parent directories as needed, e.g.,
mkdir –p myprojects/projA/example2/test
30
ITS Research Computing
m
k
d
i
r
 
E
x
a
m
p
l
e
The command 
mkdir
 makes directories.
gamera% cd
gamera% pwd
/afs/isis.unc.edu/home/t/o/totoro
gamera% alias ls
 
ls -F
 
gamera% ls
Desktop/   intel/  nsmail/    private/  public_html/
dumpster/  ms@     OldFiles/  public/   temp/
gamera% mkdir 
new_dir
gamera% ls
Desktop/   intel/  
new_dir/  
OldFiles/  public/  temp/
dumpster/  ms@     nsmail/   private/   public_html/
gamera%
31
ITS Research Computing
R
m
d
i
r
 
 
R
e
m
o
v
e
 
E
m
p
t
y
 
D
i
r
e
c
t
o
r
i
e
s
r
m
 
r
 
R
e
m
o
v
e
 
F
i
l
e
s
 
o
r
 
D
i
r
e
c
t
o
r
i
e
s
rmdir
 <uselessDirectory>
removes a subdirectory from the
current working directory. You can only
remove subdirectories if they are
completely empty (i.e., of all entries
besides the '
.
' and '
..
' directories)
Use “
rm –r
” to remove directories and
contents in one step
32
ITS Research Computing
L
a
b
 
E
x
e
r
c
i
s
e
s
Please try out all or some of the exercises that follow
to get your feet wet
Accounts: Use any Linux machine you have access
to, such as 
longleaf.unc.edu
, a Macbook terminal
Use the 
VCL
:
g
o
 
t
o
 
v
c
l
.
u
n
c
.
e
d
u
Or use the web-based 
OpenOndemand
 
portal at
 
https://ondemand.rc.unc.edu
  where you can use the
shell emulator, a Longleaf Desktop session, Juptyer and
much more
 
If you need a Longleaf account let us know!
33
ITS Research Computing
E
x
e
r
c
i
s
e
 
1
Try these commands at your Linux command prompt and check the
output:
echo hello world
date
time date
hostname
whoami
who
clear
history
cal 2021
pwd
echo $SHELL
34
ITS Research Computing
E
x
e
r
c
i
s
e
 
2
35
ITS Research Computing
cd
pwd
cd /etc
pwd
cd /
ls -al
ls -l
cd
mkdir temp_dir
cd temp_dir
mkdir temp_subdir
cd
ls -l
ls -l temp*
rmdir temp_dir
rm -r temp_dir
1.
E
n
t
e
r
 
t
h
e
s
e
 
c
o
m
m
a
n
d
s
 
a
t
t
h
e
 
p
r
o
m
p
t
,
 
h
i
t
 
"
e
n
t
e
r
,
"
 
a
n
d
t
r
y
 
t
o
 
i
n
t
e
r
p
r
e
t
 
t
h
e
 
o
u
t
p
u
t
.
2.
I
f
 
y
o
u
 
e
n
c
o
u
n
t
e
r
 
a
n
 
e
r
r
o
r
,
f
i
g
u
r
e
 
o
u
t
 
w
h
y
W
i
l
d
c
a
r
d
s
Multiple filenames can be specified using special
pattern-matching characters. The rules are:
'
?
' matches any single character in that position in the
filename
'
*
' matches zero or more characters in the filename.
[…]
’ Characters enclosed in square brackets match
any name that has one of those characters in that
position
Note that the shell expands the patterns before
the command is executed
36
ITS Research Computing
W
i
l
d
c
a
r
d
 
E
x
a
m
p
l
e
s
climate.0[6-8].*.dat
get only months June-August (i.e., 6-8) for all years
clim*2001*
get only climate files for year 2001
*.??.*
only files that have 2 characters between dots
37
ITS Research Computing
Given:
climate.01.2000.dat  climate.06.2000.dat   climate.07.2000.dat  climate.12.2000.dat
climate.02.2000.dat  climate.06.2001.dat   climate.08.2000.dat  climate.total.dat 
climate.03.2000.dat  climate.06.2002.dat   climate.09.2000.dat  Climate.txt
climate.04.2000.dat  climate.06.2003.dat   climate.10.2000.dat  seasonal.2000.dat
climate.05.2000.dat  climate.06.2004.dat   climate.11.2000.dat  seasonal.2001.dat
c
p
 
C
o
p
y
cp <source-file(s)> <destination>
cp
” copy files or entire directories
<source-file(s)> and <destination> specify the
source and destination of the copy respectively.
To copy entire directories (including their
contents), use a recursive copy:
cp -r 
source-directories destination-directory
This copies all files in all subdirectories below
source
38
ITS Research Computing
m
v
 
M
o
v
e
 
/
 
R
e
n
a
m
e
mv <source> <destination>
“mv” is used to rename files/directories and/or move
them from one directory into another.
By default the destination will be silently overwritten
by source.
-i option for interactive
this will prompt you before overwriting a file
39
ITS Research Computing
r
m
 
R
e
m
o
v
e
rm <target-file(s)>
Removes specified files. Works as advertised, it
really
 removes the file, on many systems there is
no backup 
file or
 
undelete
. (ls -tlu .snapshot)
-i for interactive
use this to be prompted before deletion
-r for recursive
removes directories, subdirectories and their contents
(files).
-f for force
removes w/o prompting
40
ITS Research Computing
s
c
p
 
S
e
c
u
r
e
 
C
o
p
y
“scp” is commonly used to copy files between any 2
hosts on a network using the ssh protocol.
commonly used to securely upload/download your files
from your home machine to desired machine
Format:
scp [options] <host:file1> <host:file2>
form of host may be username@host (default
username is your current login name)
the “host:” is omitted if the target machine is the one
you are on
file path is relative to your home directory
Options:
-r recursive (used for directories)
41
ITS Research Computing
c
a
t
 
C
o
n
c
a
t
e
n
a
t
e
cat <target-file(s)>
displays the contents of target-file(s) to
standard out (typically your screen)
one after the other
useful for combining files together
more and less are better to just display
file content
42
ITS Research Computing
m
o
r
e
 
a
n
d
 
l
e
s
s
more <target-file(s)>
“more” displays the contents of target-file(s)  on the
screen, pausing at the end of each screenful and asking
the user to press a key (useful for long files)
“less” is just like more, except that has a few extra
features (such as allowing users to scroll backwards
and forwards through the displayed file)
not a standard utility, so may not be present on all
UNIX systems
43
ITS Research Computing
M
o
r
e
 
o
f
 
m
o
r
e
 
a
n
d
 
l
e
s
s
Options at the prompt:
h - help
spacebar – scroll forward one screen
<CR> - scroll forward 1 line (can change this to
be whatever number of lines you wish)
b – back, go back a screen (does not work w/
all mores)
q – quit
/<regexp> - search for regular expression
44
ITS Research Computing
h
e
a
d
 
a
n
d
 
t
a
i
l
head and tail display the first and last 10 lines in
a file respectively. You can change the number
of lines as an option, e.g.
    $ tail -n20 messages.txt
    $ head -n5 messages.txt
tail includes a useful -f option that can be used
to continuously monitor the last few lines of a
(possibly changing) file. This can be used to
monitor log files, for example:
tail -f /var/log/messages
45
ITS Research Computing
c
h
m
o
d
 
C
h
a
n
g
e
 
M
o
d
e
 chmod <options> <files>
Used to change permissions on files.
“chmod” accepts options in two forms
a sequence of 3 octal digits (see man page for
details)
symbolically, using the symbols u (user), g
(group), o (other), a (all), r (read), w (write), x
(execute), + (add permission), - (take away
permission) and = (assign permission).
-R recursive
apply to this directory and all entries below it
46
ITS Research Computing
l
s
 
-
l
 
 
L
i
s
t
 
C
o
n
t
e
n
t
s
 
i
n
 
L
o
n
g
 
F
o
r
m
Remember, the command 
ls -l
 lists the contents of
a directory in long listing format
47
ITS Research Computing
c
h
m
o
d
 
C
h
a
n
g
e
 
F
i
l
e
 
P
e
r
m
i
s
s
i
o
n
s
For example, the command:
 chmod ug=rw,o-rw,a-x *.txt
sets the permissions on all files ending in *.txt to
rw-rw---- (i.e., the owner and users in the file's group
can read and write to the file, while others do not have
any access).
X is useful to give execute permission only to files
which are already executable.
Note that execute permission is required to “cd”
into a directory
To share files with others (e.g., RC support)
chmod –R a+rX <my_directory>
48
ITS Research Computing
c
h
o
w
n
 
C
h
a
n
g
e
 
O
w
n
e
r
chown <owner> <files>
can be used to change the owner that a file or
directory belongs to
-R recursive
recursively change owners
49
ITS Research Computing
c
h
g
r
p
 
C
h
a
n
g
e
 
G
r
o
u
p
chgrp <group> <files>
Can be used to change the group that a file or
directory belongs to
-R recursive
recursively change groups
50
ITS Research Computing
f
i
n
d
Search for files in the directory hierarchy
find <dir> -name <targetfile> [-print]
starting in 
dir
, look for 
targetfile
 and print out the
location (i.e., full path). The 
–print
 is not required in
Linux
find
” is a very powerful command with many
options, please see the man page (or 
info find
).
“find” can find files in many different ways, e.g. by
type, by permissions, by size, by age, by
modification time, by age relative to another file,
etc.
51
ITS Research Computing
f
i
n
d
You can also execute commands on the files you
find using the -exec option.
find . -name "*.txt" -exec wc -l '{}’ \;
“wc –l” counts the number of lines in every .txt file
in and below the current directory. The '{}' is
replaced by the name of each file found and the ';'
ends the -exec clause.
To keep the shell from expanding or removing
characters, escape them using quotes (“ ”, ‘ ’, or \)
52
ITS Research Computing
l
o
c
a
t
e
locate <pattern>
Find files by name
searches for *pattern* unless wildcards have been
used
Faster than find because it searches a database that
has been pre-prepared
only as accurate as the last db update
-i ignore case
case insensitive search
53
ITS Research Computing
w
h
i
c
h
 
a
n
d
 
w
h
e
r
e
i
s
If you can execute an application program
or system utility by typing its name at the
shell prompt, you can use which to find
out where it is stored on the system. This
is useful if there are multiple commands
with the same name (or perhaps aliases
or shell built-ins)
“whereis” looks in standard places (but not
everywhere!) for binaries, sources and
man pages
54
ITS Research Computing
t
a
r
 
T
a
p
e
 
A
r
c
h
i
v
e
Name is misleading and dates back to when it
was used mainly for tapes
Now tar is mostly used to collect together sets  of
files and directory trees into a single file, which is
usually called a “tar file” and by convention ends
with the extension 
.tar
This archive, or tar file, is a file that contains other
files plus information about them, such as  their
filename, owner, timestamps, and access
permissions
This allows collections of files to be moved
around, shared, or transported easily by simply
manipulating the single tar file
55
ITS Research Computing
t
a
r
tar <operation> [options] <file(s)>
Typical operations
-c – create
-x – extract
-t – list
Some options:
-v verbose
-z filter through gzip
-f <thisfile> use file 
thisfile
56
ITS Research Computing
t
a
r
 
E
x
a
m
p
l
e
s
Create an archive by tarring up everything in the myproject
mydata and mysrc directories
tar -cvf myproject.tar myproject mydata mysrc.tar
Note: it is usually much better to use relative directory paths
so there are no issues with file permissions when untarring
the file
Note too that tarring doesn’t necessarily imply compressing
List contents of a tar archive
tar -tvf ncarData.tar
Extract data from the archive
tar -xvf ncarData.tar
Unzip and untar in one step (note by convention these files
usually end with the extension .tar.gz or more commonly,
.tgz)
  
tar -xzf ncarData.tgz
  tar -xzf ncarData.tar.gz
57
ITS Research Computing
c
o
m
p
r
e
s
s
 
a
n
d
 
g
z
i
p
“compress” and “gzip” (gnu zip) are utilities for
compressing and decompressing individual files
(which may be or may not be archive files)
compress <thisfile>
thisfile is replaced with the compressed file called
thisfile.Z
use uncompress <thisfile.Z> to restore
gzip <thisfile>
thisfile is replaced with the compressed file called
thisfile.gz
use gunzip or “gzip –d” to restore
58
ITS Research Computing
s
o
r
t
sort <filenames>
Sort lines contained in a group of files
alphabetically, writes to standard output unless
the “-o” option is used
Very useful when combined with other commands
(especially pipes “|”)
A few useful Options:
-r, --reverse
-n, --numeric-sort
-k, --key=<pos1> [,<pos2>]
59
ITS Research Computing
R
e
d
i
r
e
c
t
i
o
n
 
O
p
e
r
a
t
i
o
n
s
 
(
I
/
O
)
output
 from programs
usually written to the screen
referred to as standard output (stdout)
input
 for programs
usually comes from the keyboard (if no file arguments
are given
referred to as standard input (stdin)
error
 messages from processes go to  another
output channel
usually written to the screen
referred to as standard error (stderr)
60
ITS Research Computing
R
e
d
i
r
e
c
t
i
o
n
 
a
n
d
 
P
i
p
e
s
You start to experience the power of
Unix when you combine simple
commands together to perform
complex tasks
Most (all?) Linux commands can be
piped together
Use “-” as the value for an argument to
mean “read this from standard input.”
61
ITS Research Computing
R
e
d
i
r
e
c
t
i
o
n
 
a
n
d
 
P
i
p
e
s
>
  
redirects stdout
>>
 
 
append stdout
<
 
  
redirects stdin
stderr varies by shell, use 
&
 in tcsh/csh 
 
 
and use 
2>
 in bash/ksh/sh
The
 |
 pipe operator (connects) stdout of
one command to stdin of another 
  
 
command
62
ITS Research Computing
R
e
d
i
r
e
c
t
i
o
n
 
a
n
d
 
P
i
p
e
 
E
x
a
m
p
l
e
s
cat file1 file2 file3 > file_all
cat file2 file3 >> file1
sbatch < slurm_script.sh
ls –lt * | more
cat a.tar.gz | gunzip | tar –xvf -
63
ITS Research Computing
J
o
b
s
 
a
n
d
 
P
r
o
c
e
s
s
e
s
64
ITS Research Computing
p
s
 
P
r
o
c
e
s
s
 
S
t
a
t
u
s
Snapshot of current processes
I
n
 
p
a
r
t
i
c
u
l
a
r
 
y
o
u
 
w
a
n
t
 
t
o
 
k
n
o
w
 
t
h
e
 
p
i
d
pid = process id
Many options
varies somewhat with Unix flavors
you can customize the output if desired
ps -u <my_onyen>
show all processes owned by my_onyen
ps -elf
show all processes in long format
65
ITS Research Computing
k
i
l
l
,
 
p
k
i
l
l
 
a
n
d
 
c
t
r
l
-
C
 
C
o
m
m
a
n
d
s
ctrl-C
to kill a process running that hasn’t returned
kill
 <pid>
kill processes with the TERM signal
kill -9
 <pid>
kill processes with the KILL signal (stronger form)
pkill
 <name>
looks up process by name or another attribute (not in all
Unixes)
You can only kill processes you own (unless of course
you are root).
66
ITS Research Computing
b
g
,
 
f
g
,
 
c
t
r
l
-
Z
,
 
a
n
d
 
&
 
C
o
m
m
a
n
d
s
To run a job in the background, just end the command
with “
&
”. This allows the job to run but the shell will
return control to the user (recall Linux is innately
multiprocess)
myLongRunningJob &
If a job is already running and you want to interrupt it
and put it in the background use 
^Z
 (control-Z) and 
bg
to return a job to the foreground, use 
fg
67
ITS Research Computing
j
o
b
s
 
C
o
m
m
a
n
d
The jobs command shows all processes running in
the background
Use 
fg %n
 to move job n to the foreground
fg
 by itself will foreground the default job
kill %n
 will kill job n
Example:
68
ITS Research Computing
gamera$ jobs
[1]  + Running        giant_robot.py
[2]  - Running        emacs
[3]    Running        spyder
h
i
s
t
o
r
y
 
C
o
m
m
a
n
d
history
 
outputs an indexed list of the commands
you’ve entered
By default, history lengths is typically set to recall the
last 500 or 1000 commands across sessions. The
environment variables HISTFILE, HISTFILESIZE and
HISTSIZE define history’s behavior and can be set
!<history_index_#> 
is a great shortcut for repeating
past commands
Of course, the up and down arrow keys can always
be used to scroll through recent commands
69
ITS Research Computing
F
i
l
e
 
C
o
m
p
l
e
t
i
o
n
To avoid typos and save keystrokes, use file
completion. The 
<tab> 
character will complete
up until the next non-unique character
bash:
a second <tab> shows all possible completions
tcsh:
^d shows you all possible completions
“set autolist” will show you completions
automatically (put this in your .cshrc)
70
ITS Research Computing
A
l
i
a
s
 
C
o
m
m
a
n
d
alias
” allows you to create shortcuts for
commonly used commands
You can pass arguments to “
alias
alias
” alone shows all currently defined aliases
(i.e., those defined in your shell session)
Examples:
alias ls ‘ls –CFA’
alias lm ‘ls –lt | more’
alias h history
71
ITS Research Computing
E
n
v
i
r
o
n
m
e
n
t
 
V
a
r
i
a
b
l
e
s
Used by many applications
Can be modified by the user
Affect the runtime behavior for applications (including the
shell)
You can save variable values in a special files called
resource files
PATH
 is one you are already familiar with
To see what is set in your current shell session, try these
commands:
echo $PATH
printenv
env
72
ITS Research Computing
E
x
e
r
c
i
s
e
 
3
73
ITS Research Computing
1.
T
h
e
s
e
 
a
r
e
 
O
S
-
r
e
l
a
t
e
d
 
c
o
m
m
a
n
d
s
t
h
a
t
 
p
r
o
v
i
d
e
 
i
n
f
o
r
m
a
t
i
o
n
 
a
b
o
u
t
 
t
h
e
s
y
s
t
e
m
.
2.
E
n
t
e
r
 
t
h
e
s
e
 
c
o
m
m
a
n
d
s
 
a
n
d
 
s
e
e
w
h
a
t
 
t
h
e
y
 
d
o
.
uptime
top
man ls
history
hostname
arch
top
a
E
x
e
r
c
i
s
e
 
4
74
ITS Research Computing
cd
pwd
cp /etc/motd .
cat motd
mkdir new_dir
mv motd new_dir
cat motd
cd new_dir
cat motd
cd
rm -r new_dir
more /etc/motd
head /etc/motd
tail /etc/motd
head –n5 /etc/motd
head –n10 /etc/motd
history > my_hist.txt
tail ./my_hist.txt
1.
E
n
t
e
r
 
t
h
e
s
e
 
c
o
m
m
a
n
d
s
 
a
t
t
h
e
 
p
r
o
m
p
t
,
 
h
i
t
 
"
e
n
t
e
r
,
"
 
a
n
d
t
r
y
 
t
o
 
i
n
t
e
r
p
r
e
t
 
t
h
e
 
o
u
t
p
u
t
.
2.
I
f
 
y
o
u
 
e
n
c
o
u
n
t
e
r
 
a
n
y
 
e
r
r
o
r
s
,
t
r
y
 
t
o
 
f
i
g
u
r
e
 
o
u
t
 
w
h
y
.
E
x
e
r
c
i
s
e
 
5
75
ITS Research Computing
Try these commands:
find /usr/include -name "*.h"
find /usr/include -name "*.h" | wc -l
find /usr/include/curl -name "*.h"
find /usr/include/curl -name "*.h" -exec wc -l '{}' \;
which tail
which date
whereis tail
whereis date
date
time date
w
w | wc -l
E
x
e
r
c
i
s
e
 
6
76
ITS Research Computing
Try these commands:
cd
mkdir tar_dir
cd tar_dir
echo hello world > file1
echo tar heel > file2
echo UNC-CH > file3
cat file1 file2 file3 > file4
ls –alt
cd
tar -cvf tar_dir.tar tar_dir
rm -r tar_dir
ls –alt | more
tar -xvf tar_dir.tar
ls –alt
who
Slide Note
Embed
Share

This introduction to Linux course provides a comprehensive overview of operating systems, including the history, variations, user interface, and essential commands. The course is designed with lectures, labs, and exercises to help participants gain a better understanding of Linux and its practical applications. It covers the basics of operating systems, important tasks performed by them, and a glimpse into the significant operating systems like DOS, Windows, Unix, and Linux. Additionally, the course delves into the history of Unix/Linux development, highlighting key milestones from its inception in 1969 to subsequent releases and distributions. Through this course, participants will not only learn Linux commands but also develop a perspective on the significance of operating systems and why Linux is a popular choice in the computing world.

  • Linux
  • Operating Systems
  • Commands
  • Course Overview
  • Unix

Uploaded on Sep 28, 2024 | 3 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Introduction to Linux CD Poon, Mark Reed, William Schulz https://its.unc.edu/research-computing/ ITS Research Computing

  2. Course Design and Logistics Course Design: Lecture background & intro to commands (~30 min) Short Lab (~15 min) Lecture commands in detail (~40 min) Final Lab (~35 min) The exercises are an integral part of the course Please follow along by trying examples if you like learn by doing Feel free to ask questions Restrooms Breaks ITS Research Computing 2

  3. Course Outline Objectives Operating Systems History Variations User Interface Commands Conclusion ITS Research Computing 3

  4. Objectives What this course is: An introduction to Linux hopefully to put it into a context for better understanding Gain the perspective to see what it is, what it can do, why use it What this course isn t: Just a list of Linux commands and what they do (although there will be plenty of that :) Not just to answer How do I ? ITS Research Computing 4

  5. What is an OS (operating system)? The most important program that runs on a computer Operating systems perform basic tasks: recognizing input from keyboard and mouse sending output to display screen keeping track of files and directories on the disk controlling peripheral devices such as disk drives and printers networking, security, memory management ITS Research Computing 5

  6. Some Operating Systems DOS, MS-DOS MS Windows (95, 98, NT, Windows 10) Linux: RedHat, SuSE, Ubuntu, Ubuntu Kylin, Deepin, Windows Subsystem for Linux Unix-like or *nix: HP-UX, Irix, Solaris, AIX, minix MacOS variants, NeXT, XNU ITS Research Computing 6

  7. Some Unix/Linux History, 0 1969 First Unix was developed at AT&T Bell Labs by Ken Thompson and Dennis Ritchie. 1977 - First BSD (Berkeley Software Distribution) released by Berkeley. Thomsen was a visiting professor at the time. ITS Research Computing 7

  8. Some Unix/Linux History, 1 1991 - Linux was introduced by Linus Torvalds, a student in Finland, who posted to the comp.os.minix: "Hello everybody out there using minix - I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones 1993 FreeBSD project was coordinated by Nate Williams, Rod Grimes, and Jordan Hubbard for running on 386 machines. ITS Research Computing 8

  9. Some Unix/Linux History, 3 The GNU (Gnu s Not Unix) was an effort to develop free and open source applications. Torvalds combined his kernel with GNU software from Richard Stallman (of emacs fame) and the Free Software Foundation, and Linux was off and running. Linux grows with contributions world-wide ITS Research Computing 9

  10. Key Features of Linux Linux Features: Multi-tasking many programs running Multi-user many users on the same machine at once Multi-platform runs on many different processor types ITS Research Computing 10

  11. Variations on a Theme There are two major branches of Unix: AT&T System V BSD (Berkeley Software Distribution) Lots of commercial Unix-like systems AIX (IBM), IRIX (SGI), HP-UX (HP), OpenSolaris (Sun), MacOS X. etc. Linux is a Unix-like system, free of proprietary software for which source code is available and freely distributed. There are minor variations among these Most are much more alike than they are different ITS Research Computing 11

  12. Some Linux distributions There are many groups packaging Linux for distribution. some freely available others commercial A partial listing: Red Hat CentOS Ubuntu Debian SuSE Inspur Sunway RaiseOS ITS Research Computing 12

  13. User Interface The user interacts with the OS by giving it commands. This interface is either via command line or CLI (e.g., through the shell) graphical user interface (GUI) Don t confuse the operating system s user interface with the OS itself (which does much more). Most OSs can do both. Linux traditionally uses the command line, but modern distributions rely heavily on GUIs (similar to how DOS gave way to Windows) ITS Research Computing 13

  14. Shell The Command Line Interface (CLI) for Linux is through the shell This is the application (program) that interprets what you type and carries out your directions Common Shells: tcsh exTended C SHell bash Bourne Again Shell (most common, standard on Longleaf and dogwood clusters) ksh Korn SHell csh C SHell (early popular shell) ITS Research Computing 14

  15. The OS as Onion Heart of the OS OS Modularization: the kernel an interpreter and utilities The User Interface to the OS The Stuff you want the system to do ITS Research Computing 15

  16. Example Linux commands The man (meaning manual) command for documentation Working with files and directories pwd, cd, ls, mkdir, rmdir, cp, mv, rm, scp, cat, more, less Wildcards and regex *, ?, [ ] Permissions chmod, chown, chgrp Finding stuff find, which, whereis, locate There s always more than one way to do something ITS Research Computing 16

  17. Example Linux commands Packing and Unpacking stuff tar, gzip, compress, gunzip, unzip, sort Pipes and redirection >, >>, <, | Jobs and processes ps, kill, pkill, ctrl-C, bg, ctrl-Z, &, fg, jobs Quick and Easy: shortcuts and tricks of the trade history, file completion, alias, environment variables ITS Research Computing 17

  18. Hierarchical File System Objectives Operating Systems History Variations User Interface Commands Conclusion ITS Research Computing 18

  19. Commands in General Commands are case sensitive Arguments typically are given with a dash - multiple arguments usually only require the leading dash Commands are programs or applications that the user invokes The system finds the command by specifying the full path shell built in commands looking in all directories in your PATH, typically this includes /bin, /usr/bin (but maybe not . ) ITS Research Computing 19

  20. A Command to Explain Commands man <command name> man formats and prints the system manual pages -k keyword search do keyword search for applicable man pages (same as the apropos command) in the whatis database Arguments that appear in square brackets [ ] are optional Of course, this information is available on the web now ITS Research Computing 20

  21. Clusters and Batch Submission Slurm is the batch submission program we use on the Longleaf and Dogwood clusters Don t run your HPC work on the login nodes Submit your work to the entire cluster through Slurm using sbatch and srun The point here is to let the scheduler decide where and when to best do the work ITS Research Computing 21

  22. Working with Files and Directories ITS Research Computing 22

  23. pwd Print Working Directory The pwd command shows the full, absolute path to your current location in the filesystem Absolute paths are fully qualified (e.g., /usr/bin/ls) Relative paths reference locations one or more levels up or down from the current working directory . a period or single dot always refers to your current directory .. dot-dot always refers to your parent directory (i.e., the one above your current directory in the hierarchy) After logging on to a Linux system, you are in your home directory: $ pwd /nas/longleaf/home/youronyen ITS Research Computing 23

  24. cd Change Directory cd <path> Changes your current working directory to path (which can either an absolute or relative path). a common relative paths to use is .. (i.e., the parent directory of the current dir) cd by itself changes to your home directory cd returns to your previous working directory cd ~/projectA/run the tilde grapheme ~ is a shortcut for your home directory ITS Research Computing 24

  25. cd Examples [longleaf]$ pwd /nas/longleaf/apps/admin/scripts/accounts/longleaf [longleaf]$ cd - [longleaf]$ pwd /nas/longleaf/home/wschulz [longleaf]$ cd /etc [longleaf]$ pwd /etc [longleaf]$ cd [wschulz@longleaf-login2 ~]$ pwd /nas/longleaf/home/wschulz [wschulz@longleaf-login2 ~]$ cd - /etc [longleaf]$ cd .. [longleaf]$ pwd / ITS Research Computing 25

  26. ls -- List ls - lists the contents of a directory. If no target is given, then the contents of the current working directory are displayed By default, ls doesn't show you all the entries in a directory - files and directories that begin with a dot (.) are hidden (including '.' and '..' which are always present) The reason for this is that files that begin with a . usually contain important configuration information and should not be changed under normal circumstances ITS Research Computing 26

  27. ls Useful Options ls a, show all files (or A, to exclude ., ..) ls l, long listing shows properties such as the size, type and ownership of files ls t, sort by time ls d, list directory name, not contents ls h, human readable file sizes ls F, classify, appends symbol indicating type these can be combined, ls -a -l -h or ls alh ITS Research Computing 27

  28. ls -al ls -al lists directory contents with hidden files/directories in long listing format The command, ls -al, lists the contents of a directory including the hidden file/directory names starting with "." in a long listing. totoro% ls -al total 1096 drwxr-xr-x drwxr-xr-x drwxr-xr-x -rw-r--r-- .autofsck ... totoro% 27 root root 27 root root 2 root root 1 root root 4096 2008-03-24 14:30 ./ 4096 2008-03-24 14:30 ../ 2048 2003-05-05 14:04 afs/ 0 2008-03-24 14:30 ITS Research Computing 28

  29. ls -l List Contents in Long Form The command ls -l lists the contents of a directory in long listing format ITS Research Computing 29

  30. mkdir Make directory mkdir <New_Directory> Creates a subdirectory called New_Directory in the current working directory. You can only create subdirectories in a directory for which you have write permission. -p option creates parent directories as needed, e.g., mkdir p myprojects/projA/example2/test ITS Research Computing 30

  31. mkdir Example The command mkdir makes directories. gamera% cd gamera% pwd /afs/isis.unc.edu/home/t/o/totoro gamera% alias ls ls -F gamera% ls Desktop/ intel/ nsmail/ dumpster/ ms@ gamera% mkdir new_dir gamera% ls Desktop/ intel/ new_dir/ OldFiles/ public/ dumpster/ ms@ nsmail/ gamera% private/ public_html/ OldFiles/ public/ temp/ temp/ private/ public_html/ ITS Research Computing 31

  32. Rmdir Remove Empty Directories rm r Remove Files or Directories rmdir <uselessDirectory> removes a subdirectory from the current working directory. You can only remove subdirectories if they are completely empty (i.e., of all entries besides the '.' and '..' directories) Use rm r to remove directories and contents in one step ITS Research Computing 32

  33. Lab Exercises Please try out all or some of the exercises that follow to get your feet wet Accounts: Use any Linux machine you have access to, such as longleaf.unc.edu, a Macbook terminal Use the VCL: go to vcl.unc.edu Or use the web-based OpenOndemand portal at https://ondemand.rc.unc.edu where you can use the shell emulator, a Longleaf Desktop session, Juptyer and much more If you need a Longleaf account let us know! ITS Research Computing 33

  34. Exercise 1 Try these commands at your Linux command prompt and check the output: echo hello world date time date hostname whoami who clear history cal 2021 pwd echo $SHELL ITS Research Computing 34

  35. Exercise 2 cd pwd cd /etc pwd cd / ls -al ls -l cd mkdir temp_dir cd temp_dir mkdir temp_subdir cd ls -l ls -l temp* rmdir temp_dir rm -r temp_dir 1. Enter these commands at the prompt, hit "enter," and try to interpret the output. 2. If you encounter an error, figure out why ITS Research Computing 35

  36. Wildcards Multiple filenames can be specified using special pattern-matching characters. The rules are: '?' matches any single character in that position in the filename '*' matches zero or more characters in the filename. [ ] Characters enclosed in square brackets match any name that has one of those characters in that position Note that the shell expands the patterns before the command is executed ITS Research Computing 36

  37. Wildcard Examples Given: climate.01.2000.dat climate.06.2000.dat climate.07.2000.dat climate.12.2000.dat climate.02.2000.dat climate.06.2001.dat climate.08.2000.dat climate.total.dat climate.03.2000.dat climate.06.2002.dat climate.09.2000.dat Climate.txt climate.04.2000.dat climate.06.2003.dat climate.10.2000.dat seasonal.2000.dat climate.05.2000.dat climate.06.2004.dat climate.11.2000.dat seasonal.2001.dat climate.0[6-8].*.dat get only months June-August (i.e., 6-8) for all years clim*2001* get only climate files for year 2001 *.??.* only files that have 2 characters between dots ITS Research Computing 37

  38. cp Copy cp <source-file(s)> <destination> cp copy files or entire directories <source-file(s)> and <destination> specify the source and destination of the copy respectively. To copy entire directories (including their contents), use a recursive copy: cp -r source-directories destination-directory This copies all files in all subdirectories below source ITS Research Computing 38

  39. mv Move / Rename mv <source> <destination> mv is used to rename files/directories and/or move them from one directory into another. By default the destination will be silently overwritten by source. -i option for interactive this will prompt you before overwriting a file ITS Research Computing 39

  40. rm Remove rm <target-file(s)> Removes specified files. Works as advertised, it really removes the file, on many systems there is no backup file or undelete. (ls -tlu .snapshot) -i for interactive use this to be prompted before deletion -r for recursive removes directories, subdirectories and their contents (files). -f for force removes w/o prompting ITS Research Computing 40

  41. scp Secure Copy scp is commonly used to copy files between any 2 hosts on a network using the ssh protocol. commonly used to securely upload/download your files from your home machine to desired machine Format: scp [options] <host:file1> <host:file2> form of host may be username@host (default username is your current login name) the host: is omitted if the target machine is the one you are on file path is relative to your home directory Options: -r recursive (used for directories) ITS Research Computing 41

  42. cat Concatenate cat <target-file(s)> displays the contents of target-file(s) to standard out (typically your screen) one after the other useful for combining files together more and less are better to just display file content ITS Research Computing 42

  43. more and less more <target-file(s)> more displays the contents of target-file(s) on the screen, pausing at the end of each screenful and asking the user to press a key (useful for long files) less is just like more, except that has a few extra features (such as allowing users to scroll backwards and forwards through the displayed file) not a standard utility, so may not be present on all UNIX systems ITS Research Computing 43

  44. More of more and less Options at the prompt: h - help spacebar scroll forward one screen <CR> - scroll forward 1 line (can change this to be whatever number of lines you wish) b back, go back a screen (does not work w/ all mores) q quit /<regexp> - search for regular expression ITS Research Computing 44

  45. head and tail head and tail display the first and last 10 lines in a file respectively. You can change the number of lines as an option, e.g. $ tail -n20 messages.txt $ head -n5 messages.txt tail includes a useful -f option that can be used to continuously monitor the last few lines of a (possibly changing) file. This can be used to monitor log files, for example: tail -f /var/log/messages ITS Research Computing 45

  46. chmod Change Mode chmod <options> <files> Used to change permissions on files. chmod accepts options in two forms a sequence of 3 octal digits (see man page for details) symbolically, using the symbols u (user), g (group), o (other), a (all), r (read), w (write), x (execute), + (add permission), - (take away permission) and = (assign permission). -R recursive apply to this directory and all entries below it ITS Research Computing 46

  47. ls -l List Contents in Long Form Remember, the command ls -l lists the contents of a directory in long listing format ITS Research Computing 47

  48. chmod Change File Permissions For example, the command: chmod ug=rw,o-rw,a-x *.txt sets the permissions on all files ending in *.txt to rw-rw---- (i.e., the owner and users in the file's group can read and write to the file, while others do not have any access). X is useful to give execute permission only to files which are already executable. Note that execute permission is required to cd into a directory To share files with others (e.g., RC support) chmod R a+rX <my_directory> ITS Research Computing 48

  49. chown Change Owner chown <owner> <files> can be used to change the owner that a file or directory belongs to -R recursive recursively change owners ITS Research Computing 49

  50. chgrp Change Group chgrp <group> <files> Can be used to change the group that a file or directory belongs to -R recursive recursively change groups ITS Research Computing 50

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#