The Unix filesystem
Unix shells allow to give instructions to a Unix operating system. The first thing you will need to know is how storage is organized on such a 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:
/binThis is where binaries are stored./bootThere, you can find the files necessary for booting the system./homeThis directory contains all the users’ home directories.
These directories in turn can contain other directories. /home for instance contains the directories:
/home/user01/home/user02/home/user03- …
The home directory of each user in turn contains their files and directories.
Creating files and directories
Files can be created with a text editor.
Example using nano, a simple text editor available on many systems:
nano newfile.txtThis opens the text editor “nano” with a blank file. The file actually gets created when you save it from within the text editor.
or with the command touch:
touch newfile.txtYour turn:
- What does the command
touchdo?
- How did you figure it out?
- What is the content of
newfile.txt?
- How did you figure it out?
touch can create multiple files at once:
touch file1 file2 file3New directories can be created with mkdir. This command can also accept multiple arguments to create multiple directories at once:
mkdir dir1 dir2Deleting
Files can be deleted with the command rm followed by their paths:
rm file1 file2Directories can be deleted with rm -r (“recursive”) followed by their paths or—if they are empty—with rmdir:
rm -r dir1
rmdir dir2 # only works if dir2 is emptyBe careful that these commands are irreversible. By default, there is no trash in Linux systems.
Copying, moving, and renaming
Copying is done with the cp command:
cp thesis/src/script1 thesis/msMoving and renaming are both done with the mv command:
# 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/graph1Your turn:
Why is there only one command to move and rename?