Software Carpentry logo

More Unix Shell

April 24, 2010: We are pleased to announce that Version 4 of this course is now under development. For updates and an early peek at the content, please check out the Software Carpentry blog at http://www.software-carpentry.org/blog/.

1) Introduction

2) You Can Skip This Lecture If...

3) Wildcards

Some characters (called wildcards) mean special things to the shell. (You will see this again when you get to regular expressions.)

$ ls bio/*.txt
bio/albus.txt   bio/ginny.txt   bio/harry.txt   bio/hermione.txt    bio/ron.txt

4) File Ownership and Permissions

5) Directory Permissions

6) Changing Permissions

7) Changing Permissions Continued

8) Ownership and Permission: Windows

9) Configuration

# Add personal tools directory to PATH.
PATH=$HOME/bin:$PATH

# Personal settings.
export EDITOR=/local/bin/emacs
export PRINTER=gryffindor-laserwriter

# Change default behavior of commands.
alias ls="ls -F"

10) The Shell as a programming environment

11) Redirecting Input and Output

12) Redirection Examples

$ cd bio
$ wc *.txt > words.len
$ cat words.len
   7   66  468 albus.txt
   5   46  311 ginny.txt
   5   49  342 harry.txt
   5   49  331 hermione.txt
   6   54  364 ron.txt
  28  264 1816 total

13) Pipes

$ wc -w *.txt > words.tmp
$ sort -n words.tmp
  46 ginny.txt
  49 harry.txt
  49 hermione.txt
  54 ron.txt
  66 albus.txt
 264 total
$ rm words.tmp
wc -w *.txt | sort -n
  46 ginny.txt
  49 harry.txt
  49 hermione.txt
  54 ron.txt
  66 albus.txt
 264 total
Pipes

Figure 10.2: Pipes

14) Combining Pipes

$ grep 'Title' spells.txt | sort | uniq -c | sort -n -r | head -10 > popular_spells.txt

15) Cygwin on Windows

16) Job control

17) grep

18) Shell Programs

#!/usr/bin/bash
rm -f *.junk

19) More Advanced Tools

chmod Change file and directory permissions.
du Print the disk space used by files and directories.
find Find files with names that match patterns, that are of a certain age or size, etc.
grep Print lines matching a pattern.
gunzip Uncompress a file.
gzip Compress a file.
lpr Send a file to a printer.
lprm Remove a print job from a printer's queue.
lpq Check the status of a printer's queue.
ps Display running processes.
tar Archive files.
which Find the path to a program.
who See who is logged in.
xargs Execute a command for each line of input.

Table 10.2: Advanced Command-Line Tools

20) Summary