Table of Contents |
---|
About File Systems
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.
...
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 ( / ).
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.
...
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:
...
- 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 | |||||
---|---|---|---|---|---|
| |||||
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 period = current directory) and ..
(double period = parent of current directory) come in handy.
...
Code Block | ||
---|---|---|
| ||
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 ) and the pattern is called a glob.
...
Code Block | ||
---|---|---|
| ||
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 | |||||
---|---|---|---|---|---|
| |||||
There are always multiple ways of doing things in Unix. Here are two possible answers:
|
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:
...
Notice I call everything a file, even directories. That's because directories are just a special kind of file – one that contains information about the directory's contents.
Owner and Group
A file's owner is the Unix account that created the file (here student01, me). That account belongs to one or more Unix groups, and the group associated with a file is listed in field 4.
The owner will always be a member of the group associated with a file, and other accounts may also be members of the same group. The Unix group for our class is CCBB_Workshops_1. (To see the Unix groups you belong to, just type the groups command.)
Permissions
File permissions (and some information about the file type) are encoded in that 1st 10-character field. Permissions govern who can access a file, and what actions they are allowed.
...
docs | description |
---|---|
|
Exercise 4-3
What are the directory permissions and ownership of /stor/work/CBRS_unix/test? Can you list its contents? Why or why not?
...
Expand | ||
---|---|---|
| ||
ls -l /stor/work/CBRS_unix/test (or ls -ld /stor/work/CBRS_unix/test/anna_only) shows the permissions of the anna_only directory are Because group permissions are So ls -l /stor/work/CBRS_unix/test/anna_only reports a Permission denied error. |
Basic file manipulation commands
The basic file manipulation commands are:
...