Mastering Essential Linux Commands: A Beginner’s Guide

linux commands

In the world of Linux, the command line is a powerful tool that enables users to interact with the operating system and perform a wide range of tasks efficiently. Whether you’re a newcomer to Linux or an experienced user, mastering essential commands is a fundamental step in your journey. In this comprehensive guide, we’ll explore some of the most commonly used Linux commands, unlocking the door to efficient file management, navigation, and system operations.

The “ls” Command: Listing Directory Contents

One of the most basic yet essential commands in Linux is “ls,” which stands for “list.” This command allows you to view the contents of a directory, including files and subdirectories. By running “ls” in the terminal, you’ll get a list of all items in the current working directory.

I like to use the argurments after the “ls” command “-lth” that formats the output that tells me all the information in a list format.

Listing directory contents with ls command

The “cd” Command: Navigating Directories

The “cd” command, short for “change directory,” is your passport to traversing the Linux file system hierarchy. With this command, you can move between different directories, making it easier to access and manage files across your system. For example, “cd /home/username” will take you to your home directory, while “cd ..” will move you up one level in the directory structure.

So to really navigate directories let’s throw in the bonus commands: pwd (print working directory), ls | grep */ (which depicts only the directories contained in a directory). The screenshot below depicts the current working directory, then the ls | grep */ depicts the directories which I could navigate to, then using “cd” to navigate to the Documents directory for example, then pwd’ing the current working directory again (which is Documents), then simply typing “cd” again which returns the user to the home directory, lastly pwd’ing to confirm that I returned home.

Navigating directories with the cd command

Creating and Removing Directories with “mkdir” and “rm”

As you work with files and directories, you’ll inevitably need to create new folders or remove existing ones. The “mkdir” command allows you to create new directories with a single command. For instance, “mkdir project_files” will create a new directory named “project_files” in your current working directory.

Conversely, the “rm” command is used to remove files or directories. To delete a file, simply run “rm filename.txt”. However, be cautious when using “rm” with directories, as the command “rm -r directory_name” will recursively delete the specified directory and all its contents.

In the below example, I combined a few commands we have already covered, like “ls” and “cd”, to show how easy it is to navigate to the Documents/TheLawOfTheWorld directory and create a new directory called images, then using the “ls” command to confirm the directory was created, then using “rmdir” to remove the directory, lastly using “ls” again to confirm its removal.

Creating and removing directories using mkdir and rm commands

Copying and Moving Files with “cp” and “mv”

The “cp” and “mv” commands are essential for managing files in Linux. The “cp” command allows you to create copies of files or directories, while “mv” is used to move or rename them.

For example, “cp file.txt /path/to/destination” will create a copy of “file.txt” in the specified destination directory. Similarly, “mv file.txt /path/to/destination” will move “file.txt” to the destination directory, effectively cutting and pasting it.

In the next example, I simply download “lightening-network-paper.pdf” from https://lightning.network/lightning-network-paper.pdf and then “cp” it from the Downloads directory to the Documents directory. As you can see, now i have two copies of this 3.0M file. In this case it would be better to use the “mv” command so that there is only one copy of this file in the Documents directory and not in both the Downloads and the Documents directory.

Copying and moving files with cp and mv commands

Wildcards and Pattern Matching

Linux commands often support wildcards and pattern matching, which can greatly enhance your productivity by allowing you to perform operations on multiple files or directories at once. The most common wildcard is the asterisk (*), which represents any character or set of characters.

For instance, in the below screenshot I wanted to view pdf files in the Documents directory, but there were too many files, so to truncate the “ls” results simpy use “ls *pdf” to view only pdf files.

using wildcards to fillter ls output to only view pdf files

These are just a few examples of essential Linux commands that every user should be familiar with. As you delve deeper into the world of Linux, you’ll discover a vast array of additional commands and utilities that can streamline your workflow and enhance your productivity.

Remember, practice is key to mastering these commands. Don’t hesitate to experiment in a safe environment, and always exercise caution when modifying or deleting files and directories.

[Linux Command Line Basics]: https://linuxcommand.org/lc3_lts0010.php

[GNU Core Utilities]: https://www.gnu.org/software/coreutils/manual/coreutils.html

[Linux Documentation Project]: https://tldp.org/LDP/intro-linux/html/index.html

[fedora]: https://docs.fedoraproject.org/en-US/defensive-coding/programming-languages/Shell/