Skip to content

A guide to files and folders on Linux

Beginner's Linux Tutorials

Find this tutorial useful?





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.
/var Application data, including things like your MySQL databases, for example, as well as cache files, Unix mail storage and any other application data that isn’t really specific to one user
/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.
Version 1.2 — 2010-07-25 — added /var.

Find this tutorial useful?





Like this post?

24 Comments

  1. Marc wrote:

    Nice intro!

    Tuesday, July 18, 2006 at 14:04 | Permalink | Using Mozilla Firefox Mozilla Firefox 1.5.0.4 on Mac OS X Mac OS X Mach
  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 20:22 | Permalink | Using Mozilla Firefox Mozilla Firefox 1.5.0.4 on Windows 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 20:21 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.0 on Windows Windows Vista
  4. fred wrote:

    Thanks Man. Pretty informative.

    Monday, August 4, 2008 at 15:16 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.0.1 on Linux 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 21:19 | Permalink | Using Mozilla Firefox Mozilla Firefox 1.0.4 on Fedora Linux 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 21:48 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.0.5 on Mac OS X Mac OS X 10
  7. Tim Moor wrote:

    Thanks for the intro. I have been a long time Linux user but I must admit that I did not know all the purposes of the various root level directories.

    Thanks

    Thursday, August 27, 2009 at 05:53 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.0.13 on Ubuntu Linux Ubuntu Linux
  8. Peik wrote:

    /usr actually DOES stand for “user”, not “Unix System Resources”, but it is a very misleading name. Ages ago, this directory used to be the equivalent of /home, but its role has since changed.

    See the debate on Wikipedia: http://en.wikipedia.org/wiki/Talk:Filesystem_Hierarchy_Standard#.2Fusr_as_a_backronym

    Thursday, October 22, 2009 at 19:23 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.5.3 on Windows Windows XP
  9. Arunmozhi A wrote:

    Very good information for linux newbie. They will understand the file system and permissions etc. Good Work. Keep it up.

    Wednesday, December 9, 2009 at 10:33 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.5.5 on Linux Linux
  10. aditya wrote:

    Good explanation.

    Sunday, April 11, 2010 at 18:42 | Permalink | Using Google Chrome Google Chrome 4.1.249.1045 on Windows Windows XP
  11. Josh wrote:

    Linux filesystem just makes more sense. I’m not an expert but I know from experience that windows deteriorates in speed after the first six months and there are loose files everywhere. But maybe that’s just me

    Saturday, May 8, 2010 at 07:06 | Permalink | Using Safari Safari 528.16 on iOS iOS 3.1.3
  12. Ryan wrote:

    Hey Peter – thank you much for the linux file system layout. I’m a linux newbie and I’m spinning my head trying to figure everything out. What can I say – I’m a recovering windows addict.

    Thanks again!
    Ryan

    Friday, June 4, 2010 at 05:02 | Permalink | Using Google Chrome Google Chrome 5.0.342.9 on Linux Linux
  13. What about /var and /opt

    Saturday, July 24, 2010 at 20:12 | Permalink | Using Opera Opera 9.80 on Linux Linux
  14. Peter wrote:

    Yordann Georgiev,

    /opt is listed in the guide — “Optional software – like desktop environments etc.”

    /var is for “files to which the system writes data during the course of its operation”. (http://www.linfo.org/var.html)

    You’ll often find /var used for application data, including things like your MySQL databases, for example, as well as cache files, Unix mail storage and any other application data that isn’t really specific to one user.

    I have updated the guide, thanks for pointing out its absence.

    Sunday, July 25, 2010 at 07:45 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.6.8 on Mac OS X Mac OS X 10
  15. Amit Patekar wrote:

    Thank you Peter, excellent articles for linux beginners, i am in web development using php , and was not sure where to find the “web directory” on linux its “/var/www/html”

    How the changes in the symlinks file gets reflected/saved to main file? or its the same file with symlinks as just the reference like shortcut?

    Wednesday, September 8, 2010 at 15:17 | Permalink | Using Google Chrome Google Chrome 5.0.375.127 on Windows Windows XP
  16. tonyz wrote:

    Peter the Rock… thanks for teaching this old man…I’m putting to the New!

    Saturday, September 11, 2010 at 19:45 | Permalink | Using Internet Explorer Internet Explorer 6.0 on Windows Windows Server 2003
  17. Peter wrote:

    Amit Patekar,

    A symlink acts as a redirect to its target. If you read the symlink (for example, cat), the original file’s contents are read. If you write to the symlink, the original file is updated. The symlink is completely transparent to the applications which make use of it (contrary to how a shortcut file is on Windows).

    The exceptions would be removing and renaming/moving the symlink — in this case it only affects the symlink and not the original file!

    Saturday, September 11, 2010 at 20:04 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.6.9 on Mac OS X Mac OS X 10
  18. elias.alberto wrote:

    Just like Tim Marchand said, this is an excellent and very concise explanation, perfect as quick reference for those like me, who are used to windows but want to go (or are getting used to) Linux. Thanks!

    If you’re computer literate but a linux-newbie like me, take my advice: while installing linux, use 3 partitions (swap, home and everything else). For filesystem, choose ext4. And if you’re gonna do dual booting, make a partition for windows, install windows and only then install linux (you can make the partitions while installing). A nice distro for starters is Ubuntu.

    Friday, October 15, 2010 at 23:17 | Permalink | Using Internet Explorer Internet Explorer 8.0 on Windows Windows 7
  19. Josh wrote:

    Finally, I know what /var, /usr, /bin etc. means. I’ve used Linux for ages but could never be arsed to look ’em up. Glad I stumbled along your blog!

    Saturday, April 30, 2011 at 15:18 | Permalink | Using Google Chrome Google Chrome 10.0.648.205 on Ubuntu Linux Ubuntu Linux
  20. Christoph Koydl wrote:

    Very nice! But that doesn’t answer the question: “Is a folder exactly a file?”

    regards

    Chris

    Sunday, August 7, 2011 at 06:29 | Permalink | Using Mozilla Firefox Mozilla Firefox 5.0 on Linux Linux
  21. Trent Torgerson wrote:

    Very nice, the list is very helpfull as I am a student just learning about Linux. So, what types of programs use these directories?

    Sunday, September 4, 2011 at 18:25 | Permalink | Using Internet Explorer Internet Explorer 8.0 on Windows Windows XP
  22. Sherri Graven wrote:

    Thanks for the help! I’m a newbie, pressed by work to learn Moodle. I’m installing right now, and got stuck:
    “you can either place the whole folder in your web server documents directory” (excerpt-http://docs.moodle.org/21/en/Installing_Moodle)

    As I said, I’m a newbie. I had to look up-web server documents directory. Give me a path, I’m fine, but the tutorial I was following (from Moodle) didn’t explain that very well.

    Thanks again!

    Wednesday, November 30, 2011 at 05:40 | Permalink | Using Mozilla Firefox Mozilla Firefox 7.0.1 on Linux Linux
  23. Nelson wrote:

    Mate, solid guide! Exactly what I’d been looking for. Clear, compact description of the core directories and their purposes. Cheers.

    Thursday, January 5, 2012 at 11:04 | Permalink | Using Mozilla Firefox Mozilla Firefox 3.6.24 on Ubuntu Linux Ubuntu Linux
  24. Yura wrote:

    Nice description – thanks a lot!
    The more I dig into Linux, the more I understand how better it is comparing to Windows :)

    However, GUI in Windows is still better in general :P

    Tuesday, January 31, 2012 at 13:26 | Permalink | Using Google Chrome Google Chrome 16.0.912.77 on Linux Linux

24 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 20:30

    […] 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 20:20

    […] 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 16:09

    […] 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

On some sites, you must be logged in to post a comment. This is not the case on this site.
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.