OsGate.org Logo

File system basics - filesystem directory

System System

Date 01.08.2010

Visits 3794

"In a Linux system and more in general in a UNIX system, there are some rules to follow in order to begin with its utilisation. One other difference that we can find in a UNIX system, is for example the directory hierarchy."


In a Linux system, and more in general in the whole UNIX world, plays and important role the file system, intended as the structure of file and folders.

All the UNIX systems follow a clear and exact structure, starting from root directory, also known as "/". Lets take a look on file system definitions and characteristics.

Other characteristics of the file system are shown below, like devices or symbolic / hard link.


When you use a UNIX system you must notice that there are a few basic rules to follow when working with file or directories:

  • all is a file
  • 5 types of file: normal files, directory, block device, charter device and pipe
  • No unit letter for device such as C:, D: o A:
  • Inverted tree structure with the root "/" at the top
  • case sensitive, uppercase and lowercase letters are different, a file called /etc/server.conf is different from one called /etc/Server.Conf.

These are the primary rules to begin to use a UNIX system starting from his file system.

FHS: filesystem hierarchy standard

The FHS is the standard for defining folders structure in a unix-like file system (http://www.pathname.com/fhs/). In fact starting from the root folder we can find quite the same structure in every UNIX system.

There are also some case where this standard is not adopted, like the GoboLinux distribution (http://www.gobolinux.org/) that proposes a different approach.

Here is the FHS standard:

/ => root, main access point
/bin => binaries such as ls and mv accessible from all users
/boot => contains file for boot loader
/dev => peripherals and devices of the system
/etc => all configurations file (et cetera)
/home => home directory for users
/lib => libraries for binaries in /bin and /sbin
/mnt => contains temporary mounted file system
/media => mount point of removable media like usb drives or CD-ROM
/opt => add on software that are not present in a default installation
/proc => virtual filesystem with information about kernel and processes, accessible through cat or more/less
/root => home of root user
/sbin => binaries for root user like mount, ifconfig or arp
/srv => data of system services (is rarely)
/tmp => temporary files
/usr => contains data shared on the system , like users binaries
/var => files that change in the time , like log files, web pages or print queue

Basic movements

If you're using Linux or one other UNIX for the first time, you've to know some basics commands for moving through files and directories.

The commands we will see are for a basic manipulation, such as copy, delete, move, rename, and so on.

Move file / directory

mv source destination

Rename file / directory

mv old_name new_name

Copy file / directory

cp source_file destination_file

If you want to copy a folder you must specify the recursive option -R

cp -R source_dir destination_dir

Delete file / directory

rm file
rm -R directory

Print current directory


Change directory

cd new_directory

List file

ls or ls -l


For representing a common link between a file and the file system are present two types of link, the symbolic link and the hard link.

These two kind of link are very differents and we will see these differences.

Symbolic link

Symbolic link are files that simply point to another resource located locally or remotely, and are surely the most used link.

Create a symbolic link with "ln":

ln -s source destination

You can display symbolic link with an "ls -l", and you can see also a "l" as first character, at the very beginning of the line and permissions on these link are always 777:

ls -l 
lrwxrwxrwx 1 root root 8 2009-08-30 00:40 tmp -> /var/tmp

If you delete the pointed object, the symbolic link will point a non-existent object .

Hard link

Hard link are a sort of "copy", we say a sort because a real copy of a file doesn't share the same inode, but it uses a new one, instead hard link use the same inode of the pointed file.

Sharing the same inode they share also the other information, like owner, permissions, creation/modification/last access time, etc,.... Note also that every changes you made to one of the files of the hard link are replicated to the other.

If you delete the pointed object the hard link will still exists and vice versa.

You can create an hard link with "ln":

ln -P source destination

With "ls -l" command there are no differences between hard link, but with the "stat" command you can see that the inode between the files of an hard link is the same.

snake@darkstar:~$ stat links 
File: `links'
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 754685 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 1000/ snake) Gid: ( 100/ users)
Access: 2010-07-30 16:38:55.000000000 +0200
Modify: 2010-07-30 16:39:01.000000000 +0200
Change: 2010-07-30 16:39:01.000000000 +0200

snake@darkstar:~$ stat hard_test 
File: `hard_test'
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 754685 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 1000/ snake) Gid: ( 100/ users)
Access: 2010-07-30 16:38:55.000000000 +0200
Modify: 2010-07-30 16:39:01.000000000 +0200
Change: 2010-07-30 16:39:01.000000000 +0200


All devices are created under the /dev directory, and each has a unique name. Webcams, usb drives, our local hard disk, cdrom, etc,..., you can find all in /dev.

The name of the device depends on the driver that it uses, for example for block devices like hard disks or usb drives, if they are SATA they will called sdX (X is the name of the drive, it could be a, b, c, and so on) due to the SATA driver.

For an IDE drive, the name will be hdX, but note that recently in the Linux kernel the IDE driver were deprecated, in favor of the SATA driver, so it's possible to have an IDE hard disk with the name sdX.

If devices have partition these are rapresented with number, for example /dev/sda1 or /dev/sdc2 for the second partition.