The Unix filesystem

Author

Marie-Hélène Burle

Bash allows to give instructions to a Unix operating system. The first thing we need to know is how storage is organized on such as system.

Structure

The Unix filesystem is a rooted tree of directories. The root is denoted by /.

Several directories exist under the root. Here are a few:

  • /bin     This is where binaries are stored.
  • /boot    There, you can find the files necessary for booting the system.
  • /home    This directory contains all the users home directories.

These directories in turn can contain other directories. /home for instance contains the directories:

  • /home/user001
  • /home/user002
  • /home/user003

The home directory of each user contain many files and directories.

Creating files and directories

Files can be created with a text editor:

nano newfile.txt

The file actually gets created when you save it from within the text editor.

or with the command touch:

touch newfile.txt

This creates an empty file.

touch can create multiple files at once:

touch file1 file2 file3

New directories can be created with mkdir. This command can also accept multiple arguments to create multiple directories at once:

mkdir dir1 dir2

Deleting

Files can be deleted with rm.

Directories can be deleted with rm -r (recursive) or, if they are empty, with rmdir.

Be careful that these commands are irreversible.

Copying, moving, and renaming

Copying is done with the cp command.

Example:

cp thesis/src/script1 thesis/ms

Moving and renaming are both done with the mv command.

Examples:

# rename script1 to script
mv thesis/src/script1 thesis/src/script

# move graph1 to the ms directory
mv thesis/results/graph1 thesis/ms
# this also works:
# mv thesis/results/graph1 thesis/ms/graph1

Your turn:

Why is there only one command to move and rename?