Using Linux


Using the terminal

The terminal window provides a text interface to the operating system. Here you will give most of the commands for file manipulation and compiling & running programs. When you open a terminal window, you will see the so called command prompt:

[/home/master]>                                                      

This means that Linux is waiting for you to enter a command. The command prompt also indicates in which directory you are right now. The hard disk is divided into directories, each of which can contain files and subdirectories. For example, the home (sub)directories of all users are stored within the /home directory. Since you logged in as user master you are currently in the directory /home/master. To display the contents of a directory you can use the command ls -l. Try to view the contents of your home directory:

[/home/master]> ls -l
total 4
drwxr-xr-x   2 master   master       1024 Oct 12 11:53 Exercises/
-rw-r--r--   1 master   master        261 Oct 12 14:05 copy-me
drwxr-xr-x   2 master   master       1024 Oct 12 14:59 exercise1/
drwxr-xr-x   4 master   master       1024 Sep  4 15:59 molmol/
[/home/master]>

The rightmost column contains the names of the files and subdirectories in your homedirectory. Names which end with a slash (/) are directories, the other names are files.

Changing directories

You can enter a subdirectory with the command cd. Try to go to the exercise1 directory:

[/home/master]> cd exercise1
[/home/master/exercise1]>                                           

To go back to the previous directory, you can use cd ..:

[/home/master/exercise1]> cd ..
[/home/master]>                                                      

Copying files

You can copy files with the command cp. Try to copy the file copy-me to the file new-file:

[/home/master]> cp copy-me new-file
[/home/master]> ls -l
total 5
drwxr-xr-x   2 master   master       1024 Oct 12 11:53 Exercises/
-rw-r--r--   1 master   master        261 Oct 12 14:05 copy-me
drwxr-xr-x   2 master   master       1024 Oct 12 14:59 exercise1/
drwxr-xr-x   4 master   master       1024 Sep  4 15:59 molmol/
-rw-r--r--   1 master   master        261 Oct 12 15:03 new-file
[/home/master]>

Renaming files

You can rename files with the command mv. Try to rename the file new-file to the file old-file:

[/home/master]> mv new-file old-file
[/home/master]> ls -l
total 5
drwxr-xr-x   2 master   master       1024 Oct 12 11:53 Exercises/
-rw-r--r--   1 master   master        261 Oct 12 14:05 copy-me
drwxr-xr-x   2 master   master       1024 Oct 12 14:59 exercise1/
drwxr-xr-x   4 master   master       1024 Sep  4 15:59 molmol/
-rw-r--r--   1 master   master        261 Oct 12 15:03 old-file
[/home/master]>

Deleting files

You can delete files with the command rm. Try to delete the file old-file:

[/home/master]> rm old-file
rm: remove `old-file'? y
[/home/master]> ls -l
total 4
drwxr-xr-x   2 master   master       1024 Oct 12 11:53 Exercises/
-rw-r--r--   1 master   master        261 Oct 12 14:05 copy-me
drwxr-xr-x   2 master   master       1024 Oct 12 14:59 exercise1/
drwxr-xr-x   4 master   master       1024 Sep  4 15:59 molmol/
[/home/master]>

These are the basic file manipulation skills that you will need during this course.


Next: Editing text files