Reader small image

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803234243
Edition4th Edition
Concepts
Right arrow
Author (1)
Jay LaCroix
Jay LaCroix
author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix

Right arrow

Learning essential Linux commands

Building a solid competency on the command line is essential and effectively gives any system administrator or engineer superpowers. Our new abilities won’t allow us to leap tall buildings in a single bound but will definitely enable us to execute terminal commands as if we’re command-line ninjas. While we won’t completely master the art of using the command line in this section (that can only come with years and experience), we will definitely become more confident.

First, let’s talk about moving from one place to another within the Linux filesystem. Specifically, by “Linux filesystem,” I’m referring to the default structure of the various folders (also referred to as “directories”) contained within your Ubuntu installation. The Linux filesystem contains many important directories, each with its own designated purpose, which we’ll talk about in more detail later in this chapter...

Understanding the Linux filesystem layout

As I mentioned earlier, every directory in a Linux installation has a designated purpose. It isn’t a hard rule that you have to follow, more of a strong recommendation for where certain things are supposed to go.

You can certainly go against the recommendations; ultimately, you have full control over your installation. But, if you make it a habit to place files in strange locations, you may annoy your colleagues. In this section, we’ll go over the most common directories and talk about their purpose.

The term filesystem itself can be somewhat confusing in the Linux world because it can refer to two different things—the default directory structure, as well as the actual filesystem we choose when formatting a volume such as a hard drive or flash drive (ext4, XFS, and so on). Specific to this section, we’re going to take a quick look at the Linux filesystem in the context of the default directory structure...

Viewing the contents of files

The Linux filesystem contains many directories and files. In the case of files, we need to learn how to read and manipulate them to round out our knowledge. We’ll cover more topics surrounding file management in the next chapter. For now, we can benefit by taking a look at how to view the content of existing files.

We can print the contents of a file to the screen with the cat command, along with a filename as an argument. The following command, for example, can be used to view the contents of testfile.txt in our current working directory, which we created earlier in the chapter when we discussed the touch command. Sure, this exercise is rather pointless since that file is empty, but it offers a good first example:

cat testfile.txt

There’s no output, since again, the file is empty. So, let’s instead take a look at a more practical example. Here’s a file we can use cat against that actually does have content inside...

Viewing application log files

In the last section of this chapter, let’s explore log files a bit, as they bring several concepts that we’ve discussed full circle. We went through an overview of the default directory layout, practiced viewing files, and we learned how to search files for strings. We’ll discuss log files in greater detail later on in the book, but we can use all of these concepts to take an initial look at viewing log files now.

If you recall, during the discussion of the Linux filesystem layout earlier in this chapter, there was a table showing some of the most common directories that exist. Among the items in that table, I called out the /var/log directory. While logging is transitioning to a different style (more on that in Chapter 22, Troubleshooting Ubuntu Servers), we’ll have a series of logs in the /var/log directory. Go ahead and use the ls command yourself, and you’ll see there are quite a few files there. While I won...

Summary

There are more Linux commands than you’ll ever be able to memorize. Most of us just memorize our favorite commands and variations of commands, and you’ll develop your own menu of these commands as you learn and expand your knowledge. In this chapter, we covered many of the foundational commands that are, for the most part, essential. Commands such as grep, cat, cd, ls, and others were explored this time around. The next chapter is essentially a continuation of this one, but I wanted to split the foundational concepts into two chapters rather than one enormous one.

In the next chapter, we’ll expand our foundational knowledge with a deeper look at file management, including editing files, input/output streams, and symbolic links, and we’ll even reveal the secret to life itself. Well, maybe not the latter, but the next chapter will still be great. See you there!

Relevant video

Further reading

Join our community on Discord

Join our community’s Discord space for discussions with the author and other readers:

https://packt.link/LWaZ0

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Ubuntu Server - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803234243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix