Skip to content

A guide to files and folders on Linux

Beginner's Linux Tutorials

In my second tutorial about Linux, I’m going to look at files and folders and how they work on Linux - because it’s very different compared to the Windows way of C:, D:, and E: etc.

Basically, in Linux (and other Unix-based systems, but I’ll keep it simple for now), there aren’t different drives. In Linux, everything you can access stems from the top folder in the stack. It’s called the root folder and it can be accessed using a single forward slash - /.

Everything else is a folder (or directory, in Unix speak) underneath this forward slash. Your home folder (the equivalent of My Documents) will be at /home/yourname. That means:

“From the root folder, go into the home directory and then go into the yourname directory.”

Also, remember that every folder and file is case-sensitive, so myfile is not the same as MYFILE or mYFilE. Just bear that in mind.

Mounting Media

So that’s fine for all the stuff on your computer, but what happens if I insert a CD or a USB stick or something? How do I access that? The answer is that the contents of the CD, for example, are mounted in a folder. That basically means that the folder becomes a container for everything on the CD.

Most of the time, when you insert some media, your distro does the work of automatically mounting the contents into a folder, so you don’t see this. To find mounted media, you need to look into a folder called /media (open it up in a file manager), or sometimes /mnt. There should be a list of folders corresponding to the media you have inserted (can’t see anything? Insert something).

Having said that, you aren’t restricted to mounting stuff in these folders, it’s just a convention; if you want you could mount something in your home directory, but I’ll leave that for another tutorial.

Symlinks
OK, got that? Because there are more concepts coming up now. Now in the Linux filesystem, there are also things called symlinks (in fact, there are also hard links, pipes, block devices, character devices and more, but I said I’m keeping it simple). Symlink means ’symbolic link’ and is a bit like a shortcut, but a lot more powerful. A symlink doesn’t just link to a different file, when you perform operations on it, it acts exactly as if it is that file. The advantages of this are a bit geeky, but believe me it comes in handy a lot of times.

An example of a symlink in action is in my home folder. I do a lot fo web development, so I need quick access to the files on my web server. Rather than me finding the web server documents folder (/var/www/html) every time I want to save or open, I create a symlink in my home directory. That way, not only do I get there quickly, but I can work with the web documents just as if they were actually inside my home directory (all the paths say /home/peter/htdocs/mylatestproject, rather than /var/www/html/mylatestproject).

Permissions

I won’t go into detail here, there’s enough stuff on permissions to make a tutorial in itself, but basically on your Linux filesystem, different people ‘own’ different folders and files and have the right to grant or deny other people permission to read and write to the files they own.

The super-administrator, root (not to be confused with the root filesystem / or root’s home folder /root) has access to every file regardless of its owner or permissions. This is why you should never run as root - it’s so easy to make a mistake that would bring down your whole system.

A lot of the files in Linux are owned, controlled and locked down by root. This includes important system files, folders and programs etc. You won’t be able to edit or delete these files yourself, without first logging on as root (be very careful).

For the files that you own (generally, stuff in your home folder), you can control permissions (you can prevent other users, but not root, from reading or writing to your data). By default, most distributions set your home folder to be readable by others, but not writable by others. It’s out of the scope of this tutorial to go into changing it, but if you’re interested, investigate the command chmod (or look at your file manager, it should be able to change permissions graphically).

Common Folders

I hope you have a fairly good understanding now of how the file system basically works, so now I’m going to iterate through some of the common folders you find on a Linux system, and what they’re for.

Name Purpose
/ The root folder, where everything starts, and everything is contained in this folder (or under subfolders of this folder).
/bin Contains system-critical programs (binaries)
/boot Contains files needed for booting (be careful!)
/dev Contains files which can be used to directly access your hardware (files to manipulate all your hard drives etc)
/etc Contains mainly configuration files for various programs/system stuff.
/home Contains a folder for each user (except root) where they can store their personal files.
/lib A folder for system-critical libraries.
/root The home folder for root - the super-administrator (generally will be locked to normal users so you can’t take a peek).
/media Contains folders for the media attached to your system (CDs, DVDs and USB sticks etc)
/opt Optional software - like desktop environments etc.
/proc A system folder, it’s a bit scary so I won’t go into it!
/sbin Contains essential programs only designed to be run by root.
/tmp Temporary files, deleted every restart.
/usr Stands for Unix System Resources (not user as is commonly said). Contains lots of stuff, so I’ll look into it below.
/usr/bin Contains virtually every single program you use.
/usr/lib Contains virtually every system library that programs require to run.
/usr/local Contains programs that you have manually compiled rather than installed from a package.
/usr/sbin Contains virtually every program designed to be run by the super-administrator, root.
/usr/X11R6 Houses files which power the X Window System (X version 11 release 6), which is the basis of almost every graphical environment.
. Dot (that’s a full stop) means the current directory. Mainly used to start programs in the current directory (like ./configure for example).
.. Two full stops means the directory one up from the current directory. So if you’re in /home/peter going to ../ would take you to /home.
~ The tilde symbol means your home directory - so that will be /home/yourusername.

This is just a brief look at the file system on Linux, but I hope it’s helped you understand a bit more how Linux works. More tutorials to come.

Version 1.0 - initial version
Version 1.1 - contains ., .. and ~ in Common Folders and finishes the section about case-sensitivity which I *cough* didn’t finish.

6 Comments

  1. Marc wrote:

    Nice intro!

    Tuesday, July 18, 2006 at 2:04 pm | Permalink | Posted in Mozilla Firefox 1.5.0.4 on Mac OS X
  2. Peter wrote:

    Thanks, Marc.

    I’ve done a little update now with ., .. and ~ under Common Folders and I finished a little bit about case-sensitivity.

    Tuesday, July 18, 2006 at 8:22 pm | Permalink | Posted in Mozilla Firefox 1.5.0.4 on Windows XP
  3. Tim Marchand wrote:

    As a Linux newbie, I appreciate having a concise listing of the common directories. Thanks for sharing your knowledge. That is one of the best characteristics of the open source community.

    Tuesday, July 8, 2008 at 8:21 pm | Permalink | Posted in Mozilla Firefox 3.0 on Windows Vista
  4. fred wrote:

    Thanks Man. Pretty informative.

    Monday, August 4, 2008 at 3:16 pm | Permalink | Posted in Mozilla Firefox 3.0.1 on Linux
  5. Harris wrote:

    I have saved a file (from windows) in the Linux partition (E:\), in E:\file.txt.
    How to I access it from linux?

    Monday, December 22, 2008 at 9:19 pm | Permalink | Posted in Mozilla Firefox 1.0.4 on Fedora Linux
  6. Peter wrote:

    Harris,

    This is a bit more complicated unfortunately than just pointing at the E drive.

    There are three steps you need to follow:

    1. identify which drive is the E drive in terms of which device it appears as under Linux (e.g. /dev/hda5 or similar).
    2. mount that device (e.g. /dev/hda5) into a folder (such as /mnt/Edrive), with a command like mount /dev/hda5 /mnt/Edrive
    3. retrieve the file from /mnt/Edrive/file.txt

    Without further information I can’t be of more specific help, however. If you do want more detailed help, drop me an email so I can follow up outside this comment thread.

    Monday, December 22, 2008 at 9:48 pm | Permalink | Posted in Mozilla Firefox 3.0.5 on Mac OS X

6 Trackbacks/Pingbacks

  1. [...] If you don’t know anything about how the file system works (i.e. you don’t understand where / is and what the symbol ~ represents), then I’d strongly recommend checking out my guide to files and folders before coming back here for the rest. Don’t worry, it’s written in nice and friendly language as well. [...]

  2. [...] The -R tells chmod to apply this to the whole folder, then I have my permissions I’m setting, then I have a dot (.). The dot tells chmod to affect this folder - as dot means ‘the current folder’. Lo and behold: [...]

  3. FOSSwire » Understanding file permissions - Part 1 on Monday, November 6, 2006 at 8:30 pm

    [...] If you don’t know anything about how the file system works (i.e. you don’t understand where / is and what the symbol ~ represents), then I’d strongly recommend checking out my guide to files and folders before coming back here for the rest. Don’t worry, it’s written in nice and friendly language as well. [...]

  4. FOSSwire » Understanding file permissions - Part 2 on Sunday, November 12, 2006 at 8:20 pm

    [...] The -R tells chmod to apply this to the whole folder, then I have my permissions I’m setting, then I have a dot (.). The dot tells chmod to affect this folder - as dot means ‘the current folder’. Lo and behold: [...]

  5. Installing .rpm files on Linux « Blog « Peter Upfold on Monday, August 4, 2008 at 4:09 pm

    [...] a complete newbie, I’d recommend reading my Linux Explained tutorial at Gizbuzz and my basic introduction into files and folders here to get you started with some of the concepts (I’m jumping in quite quickly to terminal stuff, [...]

  6. [...] where / is and what the symbol ~ represents), then I’d strongly recommend checking out my guide to files and folders before coming back here for the rest. Don’t worry, it’s written in nice and friendly [...]

Post a Comment

Your email address is not made public or shared. Required fields are marked with *.
*
*
*
Posting a comment signifies you accept the privacy policy.
Please note - usually your comment will appear straight away but sometimes it will be held for approval (this is due to the spam filter). If your comment is waiting to be approved, please don't post it again! It will appear eventually.