SlideShare a Scribd company logo
1 of 13
Download to read offline
More Linux on Spartan
COMP90024 Cluster and Cloud Computing
University of Melbourne, 21st
March 2023
lev.lafayette@unimelb.edu.au
Capability and Performance
Part One of this workshop introduced the Linux CLI on an
HPC system.
Part Two will extend the command knowledge and introduce
scripting.
Scripting allows for the automation of tasks.
When combined with wildcards, looping logic, conditional
statements, etc relatively short and simple commands can be
constructed that would otherwise be very time-consuming,
robotic, and demanding involvement from the user.
Archiving and Compression
UNIX-like systems have several archiving and compression
options often referred to as “tarballs”. The tar command (tape
archive) is the archiver; compression systems include gzip,
bzip2, xz and more.
To determine the type of a file: file class.tar.gz
To review the contents of a tarball: tar tf class.tar.gz
To recover from a tarbomb: tar tf tarbomb.tar | xargs rm -rf
To extract a tarball: tar xvf class.tar.gz
To create a tarball: tar cvfz name.tar.gz directory/
To create a bzip2 tarball: tar cvfj class.tar.bz2 class/
To create a xz tarball: tar cvfJ class.tar.xz class/
Advanced Redirections
Redirections can be modified by placing a file descriptor (fd)
next immediately before the redirector. These fd numbers are
0 (standard input, keyboard), 1 (standard output, display), 2
(standard error, display).
Standard error can also be redirected to the same destination
that standard output is directed to using 2>&1; it merges
stderr (2) into stdout (1).
ls -d seismic 2> error.txt
ls -d seismic 2>&1 error.txt
The tee command applies command1 and command2 to file
who -u | tee whofile.txt | grep username
File Attributes and Types
The ls -l command illustrates file ownership (user, group), file
type, permissions, and date when last modified.
The first character is type; a "-" for a regular file, a "d" for a
directory, and "l" for a symbolic link. Devices are expressed
like files: "b" for block devices, "c" for character devices.
Permissions are expressed in a block of three for "user,
group, others" and for permission type (read r, write w,
execute x).
An "s" in the execute field indicated setuid. There is "t", "save
text attribute", or more commonly known as "sticky bit" in the
execute field allows a user to delete or modify only those files
in the directory that they own or have write permission for.
Change Mode
The change permissions of a file use the chmod command.
To chmod a file you have to own it. The command is : `chmod
[option] [symbolic | octal] file`. For options, the most common
is `-R` which changes files and directories recursively. In
symbolic notation user reference is either u (user, owner), g
(group), o (others), a (all). Operation is either + (add), -
(remove), = (only equals), permissions are r (read), w (write),
x (execute).
In octal notation a three or four digit base-8 value is the sum
of the component bits. The value "r" adds 4 in octal notation
(binary 100), "w" adds 2 in octal notation (binary 010) and "x"
adds 1 in octal notation (binary 001). For special modes the
first octal digit is either set to 4 (setuid), 2 (setgid), or 1
(sticky).
Links and File Content
The ln command creates a link, associating one file with
another. There are two basic types; a hard link (the default)
and a symbolic link.
A hard link is a specific location of physical data, whereas a
symbolic link is an abstract location. Hard links cannot link
directories and nor can they cross system boundaries;
symbolic links can do both of these.
With a hard link: File1 -> Data1 and File2 -> Data1 . With a
symbolic link: File2 -> File1 -> Data1
The general syntax for links is: ln [option] source destination.
e.g., ls -s file1 file2
File Manipulation
The “cut” command copies a section from each line of a file,
based on the arguments parsed to it, whereas “paste”
merges lines of files together. See also “join”
cut -d',' -f3 shakes.csv > latitude.txt
cut -d',' -f4 shakes.csv > longitude.txt
paste -d " " latitude.txt longitude.txt > shakeslist.txt
The “sort” command will organise a text file into an order
specified by options. The general syntax is sort [option] [input
file] -o [filename]. Options include -b (ignore beginning
spaces), -d (use dictionary order, ignore punctuation), -m
(merge two input files into one sorted output, and -r (sort in
reverse order).
Shell Scripts
Shell scripts combine Linux commands with logical
operations.
The most basic form of scripting simply follows commands in
sequence (e.g., /usr/local/common/AdvLinux/backup1.sh).
Variables and command substitutions add to a script (e.g.,
/usr/local/common/AdvLinux/backup2.sh). Variables use ($)
to refer to its value. ${var}bar, invoke the variable, append
"bar". Command substitution comes in the form of $
(command).
Quotes disable and encapsulate some content; single quotes
interprets everything literally. e.g.,
echo "There are $(ls | wc -l) files in $(pwd)"
echo 'There are $(ls | wc -l) files in $(pwd)'
Scripts with Loops
Scripting allows for loops (for/do, while/do, util/do). The for
loop executes stated commands for each value in the list.
The while loop allows for repetitive execution of a list of
commands, as long as the command controlling the while
loop executes successfully. The until loop executes until the
test condition executes successfully.
for item in ./*.jpeg ; do convert "$item" "${item%.*}.png" ;
done
while read line; do sleep 5; ./setquota.sh $line; done <
quotalist.txt
x=5; until [ $x -le 0 ]; do echo "Until-do count down $x"; x=$
(( $x - 1 )); done
Scripts with Conditional
Branches
A set of branched conditions can be expressed through an
if/then/fi structure. A single test with an alternative set of
commands is expressed if/then/else/fi. Finally, a switch-like
structure can be constructed through a series of elif
statements in a if/then/elif/elif/.../else/fi
Conditionals can also be interrupted and resumed using the
“break” and “continue” statements. The break command
terminates the loop (breaks out of it), while continue causes a
jump to the next iteration (repetition) of the loop, skipping all
the remaining commands in that particular loop cycle.
A variant on the conditional is the “case” statement. The first
match executes the listed commands.
Shell Scripting and HPC Jobs
All shell commands and all shell scripting operations can be
included in Slurm job submission.
See: /usr/local/comm/AdvLinux/NAMD/drugdock.slurm for an
example which makes use of simple shell commands (cp,
mv, rm), globbing (*), variables (date2), shell substitution ($
(date +F%-H%.M%), redirects (2>), loops (for loop in {1..5})
etc.
A heredoc is a file or input literal, a section of source code
that is treated as a separate file. Heredocs can also be used
however to create Slurm scripts. (e.g,
/usr/local/common/AdvLinux/heres/herescript.sh).
2023comp90024_linux2.pdf

More Related Content

Similar to 2023comp90024_linux2.pdf

8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
southees
 
Lession1 Linux Preview
Lession1 Linux PreviewLession1 Linux Preview
Lession1 Linux Preview
leminhvuong
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
Dimas Prasetyo
 
Using Unix
Using UnixUsing Unix
Using Unix
Dr.Ravi
 
Unix fundamentals
Unix fundamentalsUnix fundamentals
Unix fundamentals
Dima Gomaa
 

Similar to 2023comp90024_linux2.pdf (20)

40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Basic Linux
Basic LinuxBasic Linux
Basic Linux
 
Lession1 Linux Preview
Lession1 Linux PreviewLession1 Linux Preview
Lession1 Linux Preview
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Unix Basics Commands
Unix Basics CommandsUnix Basics Commands
Unix Basics Commands
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Directories description
Directories descriptionDirectories description
Directories description
 
basic-unix.pdf
basic-unix.pdfbasic-unix.pdf
basic-unix.pdf
 
QSpiders - Unix Operating Systems and Commands
QSpiders - Unix Operating Systems  and CommandsQSpiders - Unix Operating Systems  and Commands
QSpiders - Unix Operating Systems and Commands
 
Basics of Linux
Basics of LinuxBasics of Linux
Basics of Linux
 
Chapter 4 Linux Basic Commands
Chapter 4 Linux Basic CommandsChapter 4 Linux Basic Commands
Chapter 4 Linux Basic Commands
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
 
Linux
LinuxLinux
Linux
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Shell-Scripting-1.pdf
Shell-Scripting-1.pdfShell-Scripting-1.pdf
Shell-Scripting-1.pdf
 
Linux day 2.ppt
Linux day  2.pptLinux day  2.ppt
Linux day 2.ppt
 
Linux
LinuxLinux
Linux
 
Unix fundamentals
Unix fundamentalsUnix fundamentals
Unix fundamentals
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 

2023comp90024_linux2.pdf

  • 1. More Linux on Spartan COMP90024 Cluster and Cloud Computing University of Melbourne, 21st March 2023 lev.lafayette@unimelb.edu.au
  • 2. Capability and Performance Part One of this workshop introduced the Linux CLI on an HPC system. Part Two will extend the command knowledge and introduce scripting. Scripting allows for the automation of tasks. When combined with wildcards, looping logic, conditional statements, etc relatively short and simple commands can be constructed that would otherwise be very time-consuming, robotic, and demanding involvement from the user.
  • 3. Archiving and Compression UNIX-like systems have several archiving and compression options often referred to as “tarballs”. The tar command (tape archive) is the archiver; compression systems include gzip, bzip2, xz and more. To determine the type of a file: file class.tar.gz To review the contents of a tarball: tar tf class.tar.gz To recover from a tarbomb: tar tf tarbomb.tar | xargs rm -rf To extract a tarball: tar xvf class.tar.gz To create a tarball: tar cvfz name.tar.gz directory/ To create a bzip2 tarball: tar cvfj class.tar.bz2 class/ To create a xz tarball: tar cvfJ class.tar.xz class/
  • 4. Advanced Redirections Redirections can be modified by placing a file descriptor (fd) next immediately before the redirector. These fd numbers are 0 (standard input, keyboard), 1 (standard output, display), 2 (standard error, display). Standard error can also be redirected to the same destination that standard output is directed to using 2>&1; it merges stderr (2) into stdout (1). ls -d seismic 2> error.txt ls -d seismic 2>&1 error.txt The tee command applies command1 and command2 to file who -u | tee whofile.txt | grep username
  • 5. File Attributes and Types The ls -l command illustrates file ownership (user, group), file type, permissions, and date when last modified. The first character is type; a "-" for a regular file, a "d" for a directory, and "l" for a symbolic link. Devices are expressed like files: "b" for block devices, "c" for character devices. Permissions are expressed in a block of three for "user, group, others" and for permission type (read r, write w, execute x). An "s" in the execute field indicated setuid. There is "t", "save text attribute", or more commonly known as "sticky bit" in the execute field allows a user to delete or modify only those files in the directory that they own or have write permission for.
  • 6. Change Mode The change permissions of a file use the chmod command. To chmod a file you have to own it. The command is : `chmod [option] [symbolic | octal] file`. For options, the most common is `-R` which changes files and directories recursively. In symbolic notation user reference is either u (user, owner), g (group), o (others), a (all). Operation is either + (add), - (remove), = (only equals), permissions are r (read), w (write), x (execute). In octal notation a three or four digit base-8 value is the sum of the component bits. The value "r" adds 4 in octal notation (binary 100), "w" adds 2 in octal notation (binary 010) and "x" adds 1 in octal notation (binary 001). For special modes the first octal digit is either set to 4 (setuid), 2 (setgid), or 1 (sticky).
  • 7. Links and File Content The ln command creates a link, associating one file with another. There are two basic types; a hard link (the default) and a symbolic link. A hard link is a specific location of physical data, whereas a symbolic link is an abstract location. Hard links cannot link directories and nor can they cross system boundaries; symbolic links can do both of these. With a hard link: File1 -> Data1 and File2 -> Data1 . With a symbolic link: File2 -> File1 -> Data1 The general syntax for links is: ln [option] source destination. e.g., ls -s file1 file2
  • 8. File Manipulation The “cut” command copies a section from each line of a file, based on the arguments parsed to it, whereas “paste” merges lines of files together. See also “join” cut -d',' -f3 shakes.csv > latitude.txt cut -d',' -f4 shakes.csv > longitude.txt paste -d " " latitude.txt longitude.txt > shakeslist.txt The “sort” command will organise a text file into an order specified by options. The general syntax is sort [option] [input file] -o [filename]. Options include -b (ignore beginning spaces), -d (use dictionary order, ignore punctuation), -m (merge two input files into one sorted output, and -r (sort in reverse order).
  • 9. Shell Scripts Shell scripts combine Linux commands with logical operations. The most basic form of scripting simply follows commands in sequence (e.g., /usr/local/common/AdvLinux/backup1.sh). Variables and command substitutions add to a script (e.g., /usr/local/common/AdvLinux/backup2.sh). Variables use ($) to refer to its value. ${var}bar, invoke the variable, append "bar". Command substitution comes in the form of $ (command). Quotes disable and encapsulate some content; single quotes interprets everything literally. e.g., echo "There are $(ls | wc -l) files in $(pwd)" echo 'There are $(ls | wc -l) files in $(pwd)'
  • 10. Scripts with Loops Scripting allows for loops (for/do, while/do, util/do). The for loop executes stated commands for each value in the list. The while loop allows for repetitive execution of a list of commands, as long as the command controlling the while loop executes successfully. The until loop executes until the test condition executes successfully. for item in ./*.jpeg ; do convert "$item" "${item%.*}.png" ; done while read line; do sleep 5; ./setquota.sh $line; done < quotalist.txt x=5; until [ $x -le 0 ]; do echo "Until-do count down $x"; x=$ (( $x - 1 )); done
  • 11. Scripts with Conditional Branches A set of branched conditions can be expressed through an if/then/fi structure. A single test with an alternative set of commands is expressed if/then/else/fi. Finally, a switch-like structure can be constructed through a series of elif statements in a if/then/elif/elif/.../else/fi Conditionals can also be interrupted and resumed using the “break” and “continue” statements. The break command terminates the loop (breaks out of it), while continue causes a jump to the next iteration (repetition) of the loop, skipping all the remaining commands in that particular loop cycle. A variant on the conditional is the “case” statement. The first match executes the listed commands.
  • 12. Shell Scripting and HPC Jobs All shell commands and all shell scripting operations can be included in Slurm job submission. See: /usr/local/comm/AdvLinux/NAMD/drugdock.slurm for an example which makes use of simple shell commands (cp, mv, rm), globbing (*), variables (date2), shell substitution ($ (date +F%-H%.M%), redirects (2>), loops (for loop in {1..5}) etc. A heredoc is a file or input literal, a section of source code that is treated as a separate file. Heredocs can also be used however to create Slurm scripts. (e.g, /usr/local/common/AdvLinux/heres/herescript.sh).