The Unix filesystem
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 in turns many files and directories.
Absolute and relative paths
Absolute paths give the full path from the root (e.g. /bin
, /home/user009/file
).
Relative paths give the path relative to the working directory (e.g. ../dir/file
, dir
)
Your turn:
Is ~
an absolute or relative path?
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. Moving and renaming with the mv
command.
Your turn:
Why is there only one command to move and rename?