Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Navigating the file system

So far all the files we've been dealing with have been in your Home directory, which is your personal directory. All Unix systems will provide you with a Home directory of your own.


About File Systems 

Pathname wildcards ("globbing")

Since another 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.

  • asterisk ( * ) is the most common filename wildcard. It matches any length of any characters.
  • brackets ( [ ] ) match any character between the brackets.
    • and you can use a hyphen ( - ) to specify a range of characters (e.g. [A-G])
  • braces ( {  } ) enclose a list of comma-separated strings to match (e.g. {dog,pony})

And wildcards can be combined. Some examples:

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-6

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

 Answer...

There are always multiple ways of doing things in Unix. Here are two possible answers:

ls [hm]*.txt
ls {haiku,jabberwocky}.txt 

x

  • No labels