This course will get you up to speed with the fundamentals of Linux and prepare you for further study. We'll look at the essentials of Linux including the directory structure, basic commands, the shell, and using the command line.
Gain a foundational understanding of:
- Linux directories and permissions
- Shell scripting and the command line
- Anyone with little to no knowledge of Linux who wants to learn more about the operating system
- Professionals who want to learn about Linux to enhance their career prospects
This is a beginner-level course so there are no prerequisites, but an interest in Linux and programming knowledge in general would be beneficial.
In this lesson, we're going to talk about the Linux directory structure where you can find different components of the Linux operating system, and we'll see how applications can use the same conventions as the Linux operating system for their directory structure as well. First, I'd like to share with you some of the most common top-level directories that you'll see when using the Linux operating system. There might be several top-level directories to be aware of, but these first few are the most important and they're the ones that you'll interact with the most often.
The Linux directory structure is like a tree. The base of the Linux file system hierarchy begins at the root. Directories will start to branch off the root, but everything starts at root. The directory separator in Linux is symbolized by a forward slash. Most of the time, we just abbreviate this to slash. Often root is referred to as slash since there are no other directories. If you hear someone say look in slash or that file is in slash, they are referring to the root directory.
Bin or /bin is where you'll find binary files or executable files. Programs are written in source code and this is human readable text. These text files are then compiled into machine-readable binaries. They are called binaries, because machine code is a string of zeros and ones. Just know that applications as you can run are sometimes located in /bin.
Slash etc or etc is where you'll find configuration files. Configuration files control how the operating system or applications behave. For example, there's a configuration file in /etc that tells the operating system whether to boot into a text mode or into a graphical mode. Slash home is where user home directories live. So for example, my home directory would be /home/Jason.
Linux systems can and often do have multiple users or multiple user accounts. And the home directory is where you can separate your data from another account's data. You can store anything you want to in your home directory. You could store documents, or music files, or your vacation pictures.
Opt is where optional or a third-party software lives. Opt is for software that is not bundled with the operating system. For example, Google Earth is not part of the standard Linux operating system, so Google Earth gets installed in opt. Slash tmp is called temp, and it's for temporary space and most Linux distributions clear/tmp at boot time. So if you put some files in temp and the Linux server gets rebooted, or your Linux desktop gets rebooted, your files will be gone.
Now, temp is a great place to store temporary files, but do not put anything in temp that you want to keep long-term. slash usr is called user, and this is where user related programs live. Each one of these directories can have sub-directories. For example, we already talked about home/home/username. User is no different. There will be a sub directory structure within user and you'll find binary programs and executables located in /usr/bin, user bin.
Slash var also called var is for variable data. Think of things that change often. Things that change often on the Linux system are typically log files that are generated either by the operating system itself or applications. And then next, we typically talk about directories. In other operating systems they may call the similar concept folders. If you think about it in terms of folders, then slash or root is the main folder and each one of these are sub folders. Again, folder and directories are often used interchangeably.
In Linux again, we're gonna use the term directory. Here's a graphic that illustrates that each one of the directories hang off of slash or start at the root. This graphic just illustrates that each directory can have many sub-directories. Here's yet another way to visualize this. In this example, we can see /home/Jason has three directories, documents, downloads, and music.
Up until this point, we've only talked about a few top level directories. However, when you actually get on a live Linux system, you're going to see that there are several other top level directories. I want to expose you to these other top level directories so that you're slightly familiar with them when you see them.
On this screen maybe the most interesting one we see there that we haven't covered yet is /cdrom. And oftentimes the Linux distributions will use that directory as what's called a mount point. And when you insert your CD ROM it will get mounted on /cdrom, so that is where you can access the files that are located on the CD ROM. Other Linux distributions use slash media. Again, this is where you could find files that are located on CD ROMs or DVDs that you place inside your computer.
We've already talked about opt. Some Linux operating systems use /srv as a location to place data that is served by the Linux server. For example, web files would be an srv www, or if it's an FTP server maybe the files would be located in /srv/ftp. We mentioned earlier about user having sub-directories user bin, user library, et cetera.
Let's switch gears and start talking about application directory structures. You'll find that some applications that are not bundled with the Linux operating system are installed in user local and often they're installed in user local program name, and from there they'll have their own sub-directory structure. In this example, CrashPlan is backup software that's not bundled with the Linux operating system.
If you were to install it from their website, it would install into user local crashplan. And if you wanted to find the binary for this program you would look in user local crashplan bin. If you wanted to configure how the program behaves at runtime, you would modify configuration files that are located in user local crashplan etc. If you wanted to see the log files that the program is generating, again, look in log, user local crashplan log.
We've already talked about how applications can be installed in opt. Avg is antivirus software. It's not bundled with the Linux operating system, and this particular application installs in opt, opt avg. Again, this is a common pattern, opt program name bin. Here is a slight variation that you'll sometimes see applications follow.
Let's take this fictitious application called MyApp, for example. Even though the main MyApp program gets installed in opt myapp where maybe the binary's live and the libraries live, you'll also see that it can install files in etc opt myapp, and that's where you would find the configuration files. The log files would be in /var/opt/myapp.
Sometimes when applications get installed they're not given their own directory structure, they're installed in a shared manner. So maybe MyApp gets installed in user local and this case it would be user local bin myapp, and the configuration file could be user local etc myapp.conf. User local bin would not only contain myapp, but other applications that were installed in this shared manner.
Another common practice is to use opt company name, or opt organization name. For example, if you work for the Acme Corporation and you logged on to one of their Linux servers, you may see something like opt acme bin where the software that was written for that company or by that company is installed. Another slight variation on this theme is opt company name product name. A real life example is Google. When you install Google Chrome on Linux it installs into opt Google Chrome, Earth installs to opt Google Earth.
Here's yet another slight variation opt organization name, or opt company organization name, or even user local company name organization name. The most important thing to know about applications that are not shipped with the Linux operating system is that they're typically found in /opt called opt, or in /usr called user. And when these applications are installed, they're typically installed in user local /usr/local.
The most common top-level directories that you'll interact with on the Linux system are slash also called root, bin, etc, home, opt, temp, user, and var. And applications that are not shipped with the operating system are typically installed in user local and opt.
Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Amazon.com. Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.