Advanced Shell Tricks Copyright © The University of Southampton 2011 This work is licensed under the Creative Commons Attribution License See

Slides:



Advertisements
Similar presentations
UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
Advertisements

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
CS 497C – Introduction to UNIX Lecture 21: - The Shell Chin-Chih Chang
Redirection & Pipes Understanding UNIX Input and Output.
BIF703 Redirection Continued: Pipes. Redirection Recall from the previous slides we defined stdin, stdout, and stderr and we learned how to redirect these.
Guide To UNIX Using Linux Third Edition
Unix Shell Scripts. What are scripts ? Text files in certain format that are run by another program Examples: –Perl –Javascript –Shell scripts (we learn.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Chapter 4: UNIX File Processing Input and Output.
Introduction to UNIX/Linux Exercises Dan Stanzione.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>,
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT I/O Redirection.
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
The “File System” Under UNIX, (almost) everything is a “file”: –Normal files –Directories –Hardware –Sockets –Pipes Things that are not files: –Users –Groups.
RjpSystem Level Programming Operating Systems 1 Having fun withy the Unix Operating System Praxis Week 7 Rob Pooley.
Advanced UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
CS 470 Lab 5 Comment your code. Description of Lab5 Create Four projects – Driver – Producer – Filter – Consumer.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Pipes and Redirection in Linux ASFA Programming III C. Yarbrough.
Pipes and Filters Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Shell Scripting – Putting it All Together. Agenda Escaping Characters Wildcards Redirecting Output Chaining and Conditional Chaining Unnamed and Named.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Linux+ Guide to Linux Certification, Second Edition
Compunet Corporation Introduction to Unix (CA263) Round and Round By Tariq Ibn Aziz Dammam Community College.
CSC Programming for Science Lecture 18: More Data Files.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson
Various 2. readonly readonly x=4 x=44 #this will give an error (like what in java?)
Batch Files More flow of control Copyright © by Curt Hill.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
The Linux Operating System
stdin, stdout, stderr Redirection
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Fossil Fuel Composition
Presented by, Mr. Satish Pise
Combustion Reactions Element or compound reacts with oxygen, releasing energy (heat, light) O2 always a reactant Hydrocarbon often other reactant Products.
Chapter Four UNIX File Processing.
Organic compounds contain carbon and usually hydrogen.
Exploring Shell Commands, Streams, and Redirection
More advanced BASH usage
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Lecture 4 Redirecting standard I/O & Pipes
Notes #2: Hydrocarbons WCHS Chemistry.
CSC 4630 Meeting 4 January 29, 2007.
Presented by, Mr. Satish Pise
Exploring Shell Commands, Streams, and Redirection
Presentation transcript:

Advanced Shell Tricks Copyright © The University of Southampton 2011 This work is licensed under the Creative Commons Attribution License See for more information. The Unix Shell

Unix ShellAdvanced Shell Tricks “How should I do this?” Some technical problem…

Unix ShellAdvanced Shell Tricks With smartphones, you’ll often hear people say something like “There’s an app for that… check this out!” “How should I do this?”

Unix ShellAdvanced Shell Tricks With smartphones, you’ll often hear people say something like “There’s an app for that… check this out!” “There’s a shell trick for that… check this out!” Whereas Unix shell programmers will say “How should I do this?”

Unix ShellAdvanced Shell Tricks In previous episodes, we’ve seen how to: – Combine existing programs using pipes & filters $ wc –l *.pdb | sort | head -1

Unix ShellAdvanced Shell Tricks In previous episodes, we’ve seen how to: – Combine existing programs using pipes & filters – Redirect output from programs to files $ wc –l *.pdb > lengths

Unix ShellAdvanced Shell Tricks In previous episodes, we’ve seen how to: – Combine existing programs using pipes & filters – Redirect output from programs to files – Use variables to control program operation $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula

Unix ShellAdvanced Shell Tricks In previous episodes, we’ve seen how to: – Combine existing programs using pipes & filters – Redirect output from programs to files – Use variables to control program operation Very powerful when used together

Unix ShellAdvanced Shell Tricks In previous episodes, we’ve seen how to: – Combine existing programs using pipes & filters – Redirect output from programs to files – Use variables to control program operation Very powerful when used together But there are other useful things we can do with these – let’s take a look…

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data The ‘redirection’ operator

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files But what about adding this together with other results generated later? list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data butane.ent heptane.ent hexane.ent nonane.ent decane.ent

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files But what about adding this together with other results generated later? $ ls *.ent > more-files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data butane.ent heptane.ent hexane.ent nonane.ent decane.ent

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files But what about adding this together with other results generated later? $ ls *.ent > more-files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data butane.ent heptane.ent hexane.ent nonane.ent decane.ent We just want the ent files

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files But what about adding this together with other results generated later? $ ls *.ent > more-files $ cat files more-files > all-files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb butane.ent heptane.ent hexane.ent nonane.ent decane.ent data append files into a single new file

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files But what about adding this together with other results generated later? $ ls *.ent > more-files $ cat files more-files > all-files Instead, we can do… $ ls *.ent >> files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb butane.ent heptane.ent hexane.ent nonane.ent decane.ent data append files into a single new file

Unix ShellAdvanced Shell Tricks First, let’s revisit redirection… $ ls *.pdb > files But what about adding this together with other results generated later? $ ls *.ent > more-files $ cat files more-files > all-files Instead, we can do… $ ls *.ent >> files list all pdb files redirect to a file cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb butane.ent heptane.ent hexane.ent nonane.ent decane.ent data append files into a single new file Note the double >’s – the append’ operator

Unix ShellAdvanced Shell Tricks We know that… Normally, standard output is directed to a display:

Unix ShellAdvanced Shell Tricks shell We know that… Normally, standard output is directed to a display: ls

Unix ShellAdvanced Shell Tricks shell We know that… Normally, standard output is directed to a display: But we have redirected it to a file instead: ls files

Unix ShellAdvanced Shell Tricks But what happens with error messages?

Unix ShellAdvanced Shell Tricks But what happens with error messages? For example… $ ls /some/nonexistent/path > files ls: /some/nonexistent/path: No such file or directory

Unix ShellAdvanced Shell Tricks But what happens with error messages? For example… $ ls /some/nonexistent/path > files ls: /some/nonexistent/path: No such file or directory No files are listed in files, as you might expect.

Unix ShellAdvanced Shell Tricks But what happens with error messages? For example… $ ls /some/nonexistent/path > files ls: /some/nonexistent/path: No such file or directory No files are listed in files, as you might expect. But why isn’t the error message in files?

Unix ShellAdvanced Shell Tricks This is because error messages are sent to the standard error (stderr), separate to stdout

Unix ShellAdvanced Shell Tricks shell This is because error messages are sent to the standard error (stderr), separate to stdout So what was happening with the previous example? ls files

Unix ShellAdvanced Shell Tricks This is because error messages are sent to the standard error (stderr), separate to stdout So what was happening with the previous example? stderr stdout files stderr stdout shell ls

Unix ShellAdvanced Shell Tricks shell This is because error messages are sent to the standard error (stderr), separate to stdout So what was happening with the previous example? ls files stderr stdout stderr stdout

Unix ShellAdvanced Shell Tricks We can capture standard error as well as standard output

Unix ShellAdvanced Shell Tricks We can capture standard error as well as standard output To redirect the standard error to a file, we can do: $ ls /some/nonexistent/path 2> error-log Redirect as before, but with a slightly different operator

Unix ShellAdvanced Shell Tricks We can capture standard error as well as standard output To redirect the standard error to a file, we can do: $ ls /some/nonexistent/path 2> error-log Now we have any error messages stored in error-log

Unix ShellAdvanced Shell Tricks We can capture standard error as well as standard output To redirect the standard error to a file, we can do: $ ls /some/nonexistent/path 2> error-log Now we have any error messages stored in error-log To redirect both stdout and stderr, we can then do: $ ls /usr /some/nonexistent/path > files 2> error-log

Unix ShellAdvanced Shell Tricks We can capture standard error as well as standard output To redirect the standard error to a file, we can do: $ ls /some/nonexistent/path 2> error-log Now we have any error messages stored in error-log To redirect both stdout and stderr, we can then do: $ ls /usr /some/nonexistent/path > files 2> error-log We can use both stdout and stderr redirection – at the same time

Unix ShellAdvanced Shell Tricks We can capture standard error as well as standard output To redirect the standard error to a file, we can do: $ ls /some/nonexistent/path 2> error-log Now we have any error messages stored in error-log To redirect both stdout and stderr, we can then do: $ ls /usr /some/nonexistent/path > files 2> error-log Which would give us contents of /usr in files as well.

Unix ShellAdvanced Shell Tricks So why a ‘2’ before the ‘>’ ?

Unix ShellAdvanced Shell Tricks So why a ‘2’ before the ‘>’ ? Both stdout and stderr can be referenced by numbers: $ ls /usr /some/nonexistent/path 1> files 2> error-log

Unix ShellAdvanced Shell Tricks So why a ‘2’ before the ‘>’ ? Both stdout and stderr can be referenced by numbers: $ ls /usr /some/nonexistent/path 1> files 2> error-log Refers to stderr Refers to stdout

Unix ShellAdvanced Shell Tricks So why a ‘2’ before the ‘>’ ? Both stdout and stderr can be referenced by numbers: $ ls /usr /some/nonexistent/path 1> files 2> error-log To just redirect both to the same file we can also do: $ ls /usr /some/nonexistent/path &> everything With ‘&’ denoting both stdout and stderr

Unix ShellAdvanced Shell Tricks So why a ‘2’ before the ‘>’ ? Both stdout and stderr can be referenced by numbers: $ ls /usr /some/nonexistent/path 1> files 2> error-log To just redirect both to the same file we can also do: $ ls /usr /some/nonexistent/path &> everything With ‘&’ denoting both stdout and stderr We can also use append for each of these too: $ ls /usr /some/nonexistent/path 1>> files 2>> error-log

Unix ShellAdvanced Shell Tricks >1> Redirect stdout to a file 2> Redirect stderr to a file &> Redirect both stdout and stderr to the same file

Unix ShellAdvanced Shell Tricks >1> Redirect stdout to a file 2> Redirect stderr to a file &> Redirect both stdout and stderr to the same file >>1>> Redirect and append stdout to a file 2>> Redirect and append stderr to a file &>> Redirect and append both stdout and stderr to a file

Unix ShellAdvanced Shell Tricks We’ve seen how pipes and filters work with using a single program on some input data…

Unix ShellAdvanced Shell Tricks We’ve seen how pipes and filters work with using a single program on some input data… a_program 1 2 3

Unix ShellAdvanced Shell Tricks We’ve seen how pipes and filters work with using a single program on some input data… But what about running the same program separately, for each input?

Unix ShellAdvanced Shell Tricks We’ve seen how pipes and filters work with using a single program on some input data… But what about running the same program separately, for each input? a_program 3 a_program 1 a_program 2...

Unix ShellAdvanced Shell Tricks We’ve seen how pipes and filters work with using a single program on some input data… But what about running the same program separately, for each input? a_program 3 a_program 1 a_program 2... We can use loops for this…

Unix ShellAdvanced Shell Tricks So what can we do with loops?

Unix ShellAdvanced Shell Tricks So what can we do with loops? Let’s go back to our first set of pdb files, and assume we want to compress each of them cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data

Unix ShellAdvanced Shell Tricks So what can we do with loops? Let’s go back to our first set of pdb files, and assume we want to compress each of them We could do the following for each: $ zip cubane.pdb.zip cubane.pdb adding: cubane.pdb (deflated 73%) cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data

Unix ShellAdvanced Shell Tricks So what can we do with loops? Let’s go back to our first set of pdb files, and assume we want to compress each of them We could do the following for each: $ zip cubane.pdb.zip cubane.pdb adding: cubane.pdb (deflated 73%) cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data typical output from the zip command

Unix ShellAdvanced Shell Tricks So what can we do with loops? Let’s go back to our first set of pdb files, and assume we want to compress each of them We could do the following for each: $ zip cubane.pdb.zip cubane.pdb adding: cubane.pdb (deflated 73%) cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data typical output from the zip command The zip file we wish to create

Unix ShellAdvanced Shell Tricks So what can we do with loops? Let’s go back to our first set of pdb files, and assume we want to compress each of them We could do the following for each: $ zip cubane.pdb.zip cubane.pdb adding: cubane.pdb (deflated 73%) cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data typical output from the zip command The file(s) we wish to add to the zip file The zip file we wish to create

Unix ShellAdvanced Shell Tricks So what can we do with loops? Let’s go back to our first set of pdb files, and assume we want to compress each of them We could do the following for each: $ zip cubane.pdb.zip cubane.pdb adding: cubane.pdb (deflated 73%) Not efficient for many files cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb data

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done For each pdb file in this directory…

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done Run this command

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done This is the end of the loop

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done The semicolons separate each part of the loop construct

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done This expands to a list of every pdb file

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done This variable holds the next pdb file in the list

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done We reference the ‘file’ variable, and use ‘.’ to add the zip extension to the filename

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done We reference the ‘file’ variable again

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done adding: cubane.pdb (deflated 73%) adding: ethane.pdb (deflated 70%) adding: methane.pdb (deflated 66%) adding: octane.pdb (deflated 75%) adding: pentane.pdb (deflated 74%) adding: propane.pdb (deflated 71%)

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done adding: cubane.pdb (deflated 73%) adding: ethane.pdb (deflated 70%) … In one line, we’ve ended up with all files zipped

Unix ShellAdvanced Shell Tricks Using a loop, we can iterate over each file, and run zip on each of them: $ for file in *.pdb; do zip $file.zip $file; done adding: cubane.pdb (deflated 73%) adding: ethane.pdb (deflated 70%) … In one line, we’ve ended up with all files zipped $ ls *.zip cubane.pdb.zipmethane.pdb.zippentane.pdb.zip ethane.pdb.zipoctane.pdb.zippropane.pdb.zip

Unix ShellAdvanced Shell Tricks Now instead, what if we wanted to output the first line of each pdb file?

Unix ShellAdvanced Shell Tricks Now instead, what if we wanted to output the first line of each pdb file? We could use head -1 *.pdb for that, but it would produce: ==> cubane.pdb <== COMPND CUBANE ==> ethane.pdb <== COMPND ETHANE ==> methane.pdb <== COMPND METHANE …

Unix ShellAdvanced Shell Tricks Now instead, what if we wanted to output the first line of each pdb file? We could use head -1 *.pdb for that, but it would produce: ==> cubane.pdb <== COMPND CUBANE ==> ethane.pdb <== COMPND ETHANE ==> methane.pdb <== COMPND METHANE … head produces this (it’s not in the file)

Unix ShellAdvanced Shell Tricks Now instead, what if we wanted to output the first line of each pdb file? We could use head -1 *.pdb for that, but it would produce: ==> cubane.pdb <== COMPND CUBANE ==> ethane.pdb <== COMPND ETHANE ==> methane.pdb <== COMPND METHANE … head produces this (it’s not in the file) this is actually the first line in this file!

Unix ShellAdvanced Shell Tricks Now instead, what if we wanted to output the first line of each pdb file? We could use head -1 *.pdb for that, but it would produce: ==> cubane.pdb <== COMPND CUBANE ==> ethane.pdb <== COMPND ETHANE ==> methane.pdb <== COMPND METHANE … Perhaps we only want the actual first lines… head produces this (it’s not in the file) this is actually the first line in this file!

Unix ShellAdvanced Shell Tricks However, using a loop:

Unix ShellAdvanced Shell Tricks However, using a loop: $ for file in *.pdb; do head -1 $file; done

Unix ShellAdvanced Shell Tricks However, using a loop: $ for file in *.pdb; do head -1 $file; done We use $file as we did before, but this time with the head command

Unix ShellAdvanced Shell Tricks However, using a loop: $ for file in *.pdb; do head -1 $file; done COMPND CUBANE COMPND ETHANE COMPND METHANE COMPND OCTANE COMPND PENTANE COMPND PROPANE

Unix ShellAdvanced Shell Tricks What if we wanted this list sorted in reverse afterwards?

Unix ShellAdvanced Shell Tricks What if we wanted this list sorted in reverse afterwards? Simple! $ (for file in ls *.pdb; do head -1 $file; done) | sort –r

Unix ShellAdvanced Shell Tricks What if we wanted this list sorted in reverse afterwards? Simple! $ (for file in ls *.pdb; do head -1 $file; done) | sort –r Using a pipe, we can just add this on the end

Unix ShellAdvanced Shell Tricks What if we wanted this list sorted in reverse afterwards? Simple! $ (for file in ls *.pdb; do head -1 $file; done) | sort –r COMPND PROPANE COMPND PENTANE COMPND OCTANE COMPND METHANE COMPND ETHANE COMPND CUBANE

Unix ShellAdvanced Shell Tricks zip Create a compressed zip file with other files in it for …; do … done; Loop over a list of data and run a command once for each element in the list

July 2011 created by Steve Crouch Copyright © Software Carpentry and The University of Southampton This work is licensed under the Creative Commons Attribution License See for more information.