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.
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.
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).
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).
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.
|/||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.