Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Ubuntu Server - Fourth Edition

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product type Book
Published in Sep 2022
Publisher Packt
ISBN-13 9781803234243
Pages 584 pages
Edition 4th Edition
Languages
Concepts
Author (1):
Jay LaCroix Jay LaCroix
Profile icon Jay LaCroix

Table of Contents (26) Chapters

Preface 1. Deploying Ubuntu Server 2. Managing Users and Permissions 3. Managing Software Packages 4. Navigating and Essential Commands 5. Managing Files and Directories 6. Boosting Your Command-line Efficiency 7. Controlling and Managing Processes 8. Monitoring System Resources 9. Managing Storage Volumes 10. Connecting to Networks 11. Setting Up Network Services 12. Sharing and Transferring Files 13. Managing Databases 14. Serving Web Content 15. Automating Server Configuration with Ansible 16. Virtualization 17. Running Containers 18. Container Orchestration 19. Deploying Ubuntu in the Cloud 20. Automating Cloud Deployments with Terraform 21. Securing Your Server 22. Troubleshooting Ubuntu Servers 23. Preventing Disasters 24. Other Books You May Enjoy
25. Index

Managing Files and Directories

In Chapter 4, Navigating and Essential Commands, we started looking deeper into Linux commands. We went over the most essential commands and covered the filesystem layout, as well as various methods to view the contents of files. In this chapter (as well as the next), we’ll continue to expand on the command line and become more efficient while using the terminal. This time around, we’ll expand a bit further on file management, take a look at input/output streams, and we’ll also develop an understanding of symbolic links. Along the way, we will cover:

  • Copying, moving, and renaming files and directories
  • Editing files with the Nano and Vim text editors
  • Input and output streams
  • Using symbolic and hard links

Let’s begin the chapter by taking a look at some methods we can use to alter the files and directories in the filesystem, such as copying and moving them.

Copying, moving, and renaming files and directories

At this point, you should know how to move around within the filesystem (commands such as cd), inspect the contents of directories (ls), and even how to create empty files (the touch command). We even know how to remove files as well, such as executing the rm command against a file or directory. But until now, we haven’t looked at moving files around within your Ubuntu filesystem.

First, to make a copy of a file or directory, we use the cp command. Copying a file is fairly easy, and such a command would look similar to the following:

cp file1 file2

In that example, file2 is created as an exact copy of file1. Copying a file is useful in many situations, some of the most common of which are:

  • Copying a file to a backup medium, such as an external drive or network share
  • Creating a copy of a file before making a change, such as before editing a very important text file
  • Duplicating a log file...

Editing files with the Nano and Vim text editors

Now that we know how to copy and move files, it would be useful to know how to edit them. There are multiple forms of text editors for Ubuntu, some available in the command line, and others in graphical environments such as the text editor in the desktop version.

Some may feel that command-line text editors are more complicated than Graphical User Interface (GUI) editors (and to be honest, they can be), but the main benefit is that you can use the same editor regardless of whether or not you have a GUI. In a way, this means the non-graphical editors are a bit more portable, and you can rely on them more. Almost all installations of Ubuntu will include the nano text editor, and you can rely on that more often than something like a particular GUI editor being available. In addition, the vim editor is another popular consideration. It’s a bit more advanced than nano, but in my opinion, much more powerful. In the following sections...

Input and output streams

During our journey into Ubuntu Server so far, we’ve worked quite a bit within the terminal. We’ve been able to inspect the contents of files, insert text into files, and more. We’ve actually been working with streams the entire time without knowing it. In this section, we’re going to talk about this subject in more detail.

If you’ve studied computer science at all, then you probably already know that output refers to things that are printed out of the computer (for example, text being printed to the screen, or onto paper from a printer) and input refers to data that is being entered into a computer, whether that be on the command line, into a file, or similar.

Linux takes this concept a bit further. Streams in Linux refer to a special way to handle what’s going in or out, and beyond the input and output streams, we also have a third that refers to errors.

Output streams in Linux are referred to as Standard...

Using symbolic and hard links

If you’ve used a graphical operating system for more than a week, you’re probably more than familiar with the concept of shortcuts. Either on the desktop or within a menu, you will have shortcuts to files and applications. This could be a shortcut to your home or profile directory, a shortcut to an application, an individual file, and so on. We have the same concept in Linux.

With Linux, we can link files to other files, which gives us the ability to create our own shortcuts, which are effectively similar to shortcuts in graphical operating systems, but without the requirement of a GUI. This comes in the form of symbolic and hard links, which are two different methods by which we can link things. Symbolic and hard links are very similar, but to explain them, you’ll first need to understand the concept of inodes.

An inode is a data object that contains metadata regarding files within your filesystem. Although a full walkthrough...

Summary

In this chapter, we elevated our terminal kung-fu to another level and looked at concepts such as moving and copying files. We continued into a discussion of two popular text editors, Nano and Vim. Then, we took a dive into the subject of streams, and finished off the chapter with an understanding of the differences between symbolic and hard links, as well as how to create them.

In Chapter 6, Boosting Your Command-line Efficiency, we’ll dive a bit deeper into command-line tips and tricks, which will include a discussion on Bash history, writing basic scripts, and more.

Relevant videos

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 2022 Publisher: Packt ISBN-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.
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 €14.99/month. Cancel anytime}