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).
Linux on Spartan: Scripting, Archiving, File Manipulation

More Related Content

Similar to Linux on Spartan: Scripting, Archiving, File Manipulation

Similar to Linux on Spartan: Scripting, Archiving, File Manipulation (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

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
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 Modelsaagamshah0812
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
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
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

Linux on Spartan: Scripting, Archiving, File Manipulation

  • 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).