2 Synthesis‎ > ‎Computing‎ > ‎Linux‎ > ‎Shell‎ > ‎


When You Start

The file system is more than a file storage system in Linux. It is an address book to the devices that store and use files like disk, tapes and printers.

The system consists of files and then directories to collections of files and sub-directories.

When you mount a device like a disk drive or memory stick, in Linux, it is the process of allocating it a position in the directory structure so that it can be referred to and made use of.

If your using a GUI such as Ubuntu then you just need to start a terminal and you will get a window with a prompt rather like this;


Or if your account name isn't named "tom" then it will be your account name, and if your computer isn't named "gold" then it will be your computer name. You start in your home directory.

Typing ls and pressing the <Enter> key, will display all the files and directories in your home directory.

You can look at any directory just listed by typing;

ls <directory-name>

(if your directory-name has spaces in it put it in single quotes like this 'directory-name')

(When I write <directory-name> you need to replace it with the actual name)

and once you see what you have in it you can see what's in that to;

ls <directory-name>/<second-directory-name>

in fact ls works with any file path you give it;

ls <directory-path>

If you want a lot more detail in your listing use;

ls -l

At the moment your home directory is the current working directory but you can change the current working directory with;

cd <directory-path>
A bit more about file paths and directory paths below.

The Linux File System Structure

Lets look at the Linux file system structure. This command will list the directories and files at the root of the file system tree;

ls /
bin   cdrom  etc   initrd.img      lib    lost+found  mnt  proc  run   srv  tmp  var      vmlinuz.old
boot  dev    home  initrd.img.old  lib64  media       opt  root  sbin  sys  usr  vmlinuz

bin - contains the programs which are the commands used in the shell. You can use ls /bin to list its contents and you will see that ls its self is there in the list.

etc - contains configuration files for the system.

home - contains named home directories for each user to which they have free access.

mnt -  TODO

Here, only the most important directories in the system will be presented.

/bin is a place for most commonly used terminal commands, like ls, mount, rm, etc.

/boot contains files needed to start up the system, including the Linux kernel, a RAM disk image and bootloader configuration files.

/dev contains all device files, which are not regular files but instead refer to various hardware devices on the system, including hard drives.

/etc contains system-global configuration files, which affect the system's behavior for all users.

/home home sweet home, this is the place for users' home directories.

/lib contains very important dynamic libraries and kernel modules

/media is intended as a mount point for external devices, such as hard drives or removable media (floppies, CDs, DVDs).

/mnt is also a place for mount points, but dedicated specifically to "temporarily mounted" devices, such as network filesystems.

/opt can be used to store additional software for your system, which is not handled by the package manager.

/proc is a virtual filesystem that provides a mechanism for kernel to send information to processes.

/root is the superuser's home directory, not in /home/ to allow for booting the system even if /home/ is not available.

/run is a tmpfs (temporary file system) available early in the boot process where ephemeral run-time data is stored. Files under this directory are removed or truncated at the beginning of the boot process.
(It deprecates various legacy locations such as /var/run, /var/lock, /lib/init/rw in otherwise non-ephemeral directory trees as well as /dev/.* and /dev/shm  which are not device files.)

/sbin contains important administrative commands that should generally only be employed by the superuser.

/srv can contain data directories of services such as HTTP (/srv/www/) or FTP.

/sys is a virtual filesystem that can be accessed to set or obtain information about the kernel's view of the system.

/tmp is a place for temporary files used by applications.

/usr contains the majority of user utilities and applications, and partly replicates the root directory structure, containing for instance, among others, /usr/bin/ and /usr/lib.

/var is dedicated to variable data, such as logs, databases, websites, and temporary spool (e-mail etc.) files that persist from one boot to the next. A notable directory it contains is /var/log where system log files are kept.


  • By putting that / at the start, you're saying "Start at the root directory, and work down"
  • If you don't put the / at the front, you're saying "Start from the current directory and work down"
  • If you put ../ at the front, you're saying "Go up one directory and then start looking"
  • And if you put ~ at the front, you're saying "Look in my home directory"
  • When running a command by simply typing a path to it you have to say ./ to mean a command file in the curent directory.

File Descriptors

File descriptors can include "wildcards" so that more than one file can be refered to by a single string of characters.

Here is the basic set of wildcards:

  • * - represents zero or more characters
  • ? - represents a single character
  • [] - represents a range of characters

The best way to experiment with this is to use the ls command;

  • To list all the files beginning with G; ls g*
  • To list all the files beginning with g or k; ls [gk]*
  • To list all the files beginning with g h i j k; ls [g-k]*
  • To list all the files beginning with g or k; ls [gk]*
  • To list all the files of type jpg; ls *.jpg



For copying file contents;
    cp [options] <file path1> <file path2>
    cp [options] <file path> <directory path> 

-u, --update copy  only  when  the  SOURCE  file is newer than the destination file or when the destination file is missing.


Remove any file2 and turn file1 into file2;
    mv [options] <file path1> <file path2>
If no directory exists rename directory1 as directory2, else move directory1 as sub-directory of directory2;
    mv [options] <directory path1> <directory path2>
Move files into directory;
    mv [options] <file path> <directory path>


Make a directory
    mkdir [-p] [-m 444] <directory path>
the -p causes the entire directory path to be created.
the -m allows the access mode to be entered.


Remove a directory and sub-tree

    rm -rf <directory path>



In Linux systems file access is controlled as follows.

Access is defined by three permissions;
  • read permission (r)
  • write permission (w)
  • execute permission (x)
A set of permissions may be designated by a string such as r-- meaning read only or rw- meaning read and write or --x meaning execute only. These permissions can also be represented as octal and would be 4,6,1 consecutively. These are binary 100, 110 and 001.

Every file belongs to a user and a group and must have permissions set for;
  • the user
  • the group
  • the others
In a Linux commands this is done with a string such as
  • -rwxr-xr-x or 755 in three-digit octal.
  • -rw-rw-r-- or 664 in three-digit octal.
  • -r-x------ or 500 in three-digit octal.
When a person tries to access a file
  • if they are a user then the user access permissions will apply irrespective of the group or other permissions
  • else if they are a member of the file's group then the group access permissions will apply irrespective of the other permissions.
  • else the other access permissions will apply.
Thus one could create a group called "jerks" and use it to deny some people access to a file that was accessible to anybody who was not a member of the group. Of course this is of limited value because it would require the file to belong to the group jerks! Also on most systems a user can remove themselves from a group.

Directory Access

Directories are controlled in the same way but;
  • read permission - means you can access a list of the files in the directory.
  • write permission - means you can create, delete and rename files in the directory
  • execute permission ?TODO

  •   Execute permission is required for a user to cd into a directory.
  •     Read permission is required for a user to use a command such as ls to view the files contained in a directory.
  •     Execute-only permission allows a user to access the files in a directory as long as the user knows the names of the files in the directory, and the user is allowed to read the files.
  •     Write permission allows the user to create, delete, or modify any files or subdirectories, even if the file or subdirectory is owned by another user.
Directories also have some other access controls;
  • By setting the sticky bit users can only delete their own files. TODO what about rename?
  • set group id bit if set forces a files group to be the directories group.

Access Commands


Add Execute by User permission;

  • chmod u+x <file descriptor>

Assign Read Write Execute permission to User, Read Execute permission to Group, Execute permission to Others;

  • chmod 751 <file descriptor>
  • chmod u=rwx,g=rx,o=x <file descriptor>

Assign Read only permission to file for All that means User Group and Others;

  • chmod =r <file descriptor>
  • chmod a-wx,a+r <file descriptor>
  • chmod 444 <file descriptor>


  • Change the owner of file or files to "root"; chown root <file descriptor>
  • Likewise, but also change its group to "staff";   chown root:staff <file descriptor>
  • Change the owner of file or files and subfiles to "root"; chown -hR root <file descriptor>


Change the group of file or files to "staff"; chgrp staff <file descriptor>
Change the group of file or files and subfiles to "staff"; chgrp -hR staff <file descriptor>

© Tom de Havas 2011. The information under this section is my own work it may be reproduced without modification but must include this notice.

Users and Groups

Every user has a password and belongs to a primary group but can belong to many other groups.

Every user is allocated a UID, a unique number greater than 499.

Every group is allocated a GID, a unique number greater than 499.

Every user is allocated a home directory on the file system, usually;

  • /home/<user-name>

Information on users is stored in /etc/passwd file.

Groups are defined in the /etc/passwd file. It contains a list of the users that are members of the group.

When you create a file it will be assigned to your primary group. To assign it to another group you must use either;

  • Change your primary group with newgrp before you create the file or
  • change the files group with chgrp.

When you switch the system on if it goes directly to the command prompt then it displays a message which it gets from the file /etc/issue

You can display information for your account with the id command.

The following commands are not simple and need to be looked at before use;

  • useradd
  • usermod
  • userdel
  • groupadd
  • groupmod
  • groupdel
  • passwd    Change the password for the current user


file filename    Display file type of file with name filename

cat textfile    Throws content of textfile on the screen

pwd    Display present working directory

exit or logout    Leave this session

man command    Read man pages on command

info command    Read Info pages on command

apropos string    Search the whatis database for strings

tells you about terminals that are are running; tty

l tells you far more useful stuff about terminals; ps

Prints the name of the operating system, the systems internet name, operating system release number etc ; uname -a

who -H


Subpages (1): Links