Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • single Tab – completes file or directory name up to any ambiguous part
    • if nothing shows up, there is no unambiguous match
  • Tab twice – display all possible completions
    • you then decide where to go next

Let's have some fun with the Tab key. Follow along if you can:

Code Block
languagebash
cd /st                   # hit Tab key - expands to /stor/ which is the only match
cd /stor/w               # hit Tab key again - expands to /stor/work/, again the only match
cd /stor/work/C          # hit Tab once - nothing happens because there are multiple matches
cd ~

...

 /stor/work/C          # hit Tab a 2nd time - all matching directories listed
cd /stor/work/CB         # hit Tab key - expands to /stor/work/CBRS_unix
cd /stor/work/CBRS_unix  # press Enter to change to that directory
cd                       # go Home

Relative pathname syntax

Rather than always typing a full pathname (that is, a pathname starting with the / root directory) of where you want to go, you can specify a directory relative to where you are. This is where the special directory names . (single periodcurrent directory) and .. (double periodparent of current directory) come in handy.

Here are some examples. Follow along if you can – and use the Tab key to help out!

Expand
titleStructure of the /stor/work/CBRS_unix directory

Image Added


Code Block
languagebash
pwd                     # where am I now, really? /stor/home/student01
cd ..                   # up one level - now I'm in /stor/home
cd ../work/CBRS_unix/   # change into /stor/work/CBRS_unix using relative syntax
cd ./unix/docs/         # change into the unix/docs sub-directory relative to /stor/work/CBRS_unix
cd ../../fastq/         # go up two levels, then into fastq directory
cd ../../../home/       # change to the /stor/home directory using relative syntax
cd                      # go Home

Pathname wildcards ("globbing")

Since another we've seen that a goal of Unix is to type as little as possible, there are several metacharacters that serve as wildcards to represent sets of characters when typing file names. Using these metacharacters is called globbing (don't ask me why (smile)) and the pattern is called a glob.

...

Code Block
languagebash
ls *.txt        # lists all files with names ending in ".txt"
ls [a-z]*.txt   # does the same but only lists files starting with a lowercase letter
ls [ABhi]*      # lists all filenames whose 1st letter is A, B, h, or i
ls *.{txt,tsv}  # lists filenames ending in either .txt or .tsv
Exercise 4-

...

2

Design a wildcard that will match the files haiku.txt and mobydick.txt but not jabberwocky.txt.

...