Versions Compared

Key

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

...

Note that in Unix, and on Macs, directories are separated by forward slash ( / ) characters, unlike Windows where the backslash ( \ ) is used. And the root of all the file systems is that 1st forward slash ( / ).

...

Navigating the file

...

So if you're on a new system, how do you know what file systems are available to you? The df (disk free) command will list all the available file systems. As its name suggests, it also shows file system sizes, so it's always good to use df -h (human readable) to see sizes in more readable form. Also, there can be many many file systems available on any given system, so always pipe the output to more.

Code Block
languagebash
df -h | more

This produces a rather busy display like this one:

Image Removed

Fortunately, you can ignore most of it. Focus on the Mounted on and Size columns.

  • Look for the / (forward slash), under the Mounted on column:
    • / (forward slash) is the root of the file system where the operating system is installed
    • Note its Size is 98G with 47G used
  • Look for Mounted on entries with large Size numbers:
    • Gigabytes (10^9 bytes), Terabytes (10^12 bytes), Petabytes (10^15 bytes)
  • Ignore file systems with names like /run, /dev, /snap, /sys, /boot, /tmp, /var – these are system related
  • Here we see a number starting with /stor (/stor, /stor/home, /stor/work, etc.)
    • Note its large Size: 39T - a sign that it's a file system you want to know about.

Here's a similar listing from the Lonestar6 compute cluster at TACC:

Image Removed

Here the big important file systems are /home1 (7.0T), /scratch (8.1P) and /work (6.8P). There's also /admin (3.5T) but its name suggests that normal users won't be able to access it.

Navigating the file system

Now that we know there are other places, how do we get there? Enter the cd (change directory) command:

  • cd <optional directory_name>
    • with no argument, always changes to your Home directory.

There are also some "special" built-in directory names:

  • ~ (tilde) means your Home directory
  • . (single period) means the current directory
  • .. (two periods) means the parent of the current directory (directory above it)
    • So ls .. means "list contents of the parent directory"
  • - (dash) means whatever directory you were in before this one

So these two expressions do the same thing – take you to your Home directory from wherever you are in the file system.

Code Block
languagebash
titleGo Home!
cd
cd ~

When you've changed into a directory, how do you know where you are in the file system?

  • On our system, we've arranged that the command prompt "follows you" around the file system.
  • On other systems you can use the pwd (present working directory) command to see the full pathname of the directory you're in

Exercise 4-1

What is the full pathname of your Home directory?

Expand
titleAnswer...

pwd will display something like /stor/home/student01

Change into the /stor/work/CBRS_unix directory then back to your Home directory. Then use the - (dash) to go back to /stor/work/CBRS_unix without typing it in, then Home again using ~ (tilde). How does the command prompt change?

...

titleAnswer...

...

languagebash

...

system

Now that we know there are other places, how do we get there? Enter the cd (change directory) command:

  • cd <optional directory_name>
    • with no argument, always changes to your Home directory.

There are also some "special" built-in directory names:

  • ~ (tilde) means your Home directory
  • . (single period) means the current directory
  • .. (two periods) means the parent of the current directory (directory above it)
    • So ls .. means "list contents of the parent directory"
  • - (dash) means whatever directory you were in before this one

So these two expressions do the same thing – take you to your Home directory from wherever you are in the file system.

Code Block
languagebash
titleGo Home!
cd
cd ~

When you've changed into a directory, how do you know where you are in the file system?

  • On our system, we've arranged that the command prompt "follows you" around the file system.
  • On other systems you can use the pwd (present working directory) command to see the full pathname of the directory you're in

Exercise 4-1

What is the full pathname of your Home directory?

Expand
titleAnswer...

pwd will display something like /stor/home/student01

Change into the /stor/work/CBRS_unix directory then back to your Home directory. Then use the - (dash) to go back to /stor/work/CBRS_unix without typing it in, then Home again using ~ (tilde). How does the command prompt change?

Expand
titleAnswer...


Code Block
languagebash
cd /stor/work/CBRS_unix
cd                          # Back home
cd -                        # Last directory (here /stor/work/CBRS_unix)
cd ~                        # And home again

The command prompt "follows you", displaying /stor/work/CBRS_unix when you're in that directory, and ~ when you're in your Home directory.

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! (See Tab key completion)

Expand
titleStructure of the /stor/work/CBRS_unix directory

Image Added


Code Block
languagebash
cd                      # make sure you're in your Home directory
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 
# Back home cd -
to /stor/work/CBRS_unix
cd ../../fastq/         # go up two levels, then into fastq directory
cd ../../../home/       # 
Last
change 
directory
to 
(here
the /stor/
work/CBRS_unix) cd ~
home directory using relative syntax
cd                      #
And
 
home
go 
again

The command prompt "follows you", displaying /stor/work/CBRS_unix when you're in that directory, and ~ when you're in your Home directory.

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! (See Tab key completion)

Expand
titleStructure of the /stor/work/CBRS_unix directory

Image Removed

Code Block
languagebash
cd                      # make sure you're in your Home directory
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 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.

  • 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:

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 in your Home directory.

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

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

Code Block
languagebash

Pathname wildcards ("globbing")

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

  • 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:

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 in your Home directory.

Expand
titleAnswer...

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

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


Finding file systems

So if you're on a new system, how do you know what file systems are available to you? The df (disk free) command will list all the available file systems. As its name suggests, it also shows file system sizes, so it's always good to use df -h (human readable) to see sizes in more readable form. Also, there can be many many file systems available on any given system, so always pipe the output to more.

Code Block
languagebash
df -h | more

This produces a rather busy display like this one:

Image Added

Fortunately, you can ignore most of it. Focus on the Mounted on and Size columns.

  • Look for the / (forward slash), under the Mounted on column:
    • / (forward slash) is the root of the file system where the operating system is installed
    • Note its Size is 98G with 47G used
  • Look for Mounted on entries with large Size numbers:
    • Gigabytes (10^9 bytes), Terabytes (10^12 bytes), Petabytes (10^15 bytes)
  • Ignore file systems with names like /run, /dev, /snap, /sys, /boot, /tmp, /var – these are system related
  • Here we see a number starting with /stor (/stor, /stor/home, /stor/work, etc.)
    • Note its large Size: 39T - a sign that it's a file system you want to know about.

Here's a similar listing from the Lonestar6 compute cluster at TACC:

Image Added

Here the big important file systems are /home1 (7.0T), /scratch (8.1P) and /work (6.8P). There's also /admin (3.5T) but its name suggests that normal users won't be able to access it.

File attributes

Let's revisit a listing of our Home directory contents. Before we created any files, an ls -l listing looked something like this:

...