For Linux users, the command line is an essentially, and ultra-powerful tool. While more user-friendly Linux operating systems (OS) offer loads of functionality without the need for entering the terminal, it's a necessary element of the OS. Contrary to popular opinion, the command line can even simplify certain actions.

Whether you're brand new to Linux distros, or a seasoned Linux veteran, the command line offers a bevy of uses. Try these tips for mastering the command line.

Files and Folders

folder-linux-command-line
Image Credit: ProSmile via Pixabay

Although you can easily create, move, and navigate between folders with a graphical user interface (GUI), the command line is perfectly capable of handling files and folders.

Change Directory

Changing directories is pretty simple. In a terminal, enter:

        cd
    

For instance, to navigate into a specific folder like the Downloads folder on your harddrive, merely enter the path to your desired directory:

        cd /home/user/Downloads
    

Changing directories is incredibly beneficial when installing software via the command line. To run an installer using the terminal, you'll first need to change into the folder where that installer resides.

Make Directory

In addition to switching folders, the command line allows for folder creation. You can make a directory by running the command:

        mkdir
    

Therefore, to make a folder called Apps, you would enter:

        mkdir Apps
    

But this makes a folder in the current directory. If you want to specify where a directory is created, you'll either need to change directory into that folder, or enter the full path:

        mkdir /home/user/Documents/Apps
    

If there aren't folders for the full path, running this command creates directories for all of the folders in the path.

Copy

An oft-used command when handling files and folders is copy:

        cp
    

To copy a file into another file, run:

        cp [NAME OF FILE 1] [NAME OF FILE 2]
    

Alternately, you can copy files into directories using this command:

        cp [NAME OF FILE] [NAME OF DIRECTORY]
    

Move

Like copying files and folders, you can move items with the terminal. That command is:

        mv
    

When moving the content of one file to another, run:

        mv [NAME OF FILE 1] [NAME OF FILE 2]
    

However, if the second file doesn't exist, the first file is renamed as the second file. But if the second file does exist, then its contents are replaced with those of the first file.You can also use the move command with directories:

        mv [NAME OF DIRECTORY 1] [NAME OF DIRECTORY 2]
    

Similar to how the move command handles files, if the second directory does not exist then the first directory is simply renamed. Yet if the second directory does exist, the contents of the first directory are moved into the second directory.

Remove

Want to remove files or folders? Just run:

        rm
    

When you're deleting a file, that would look like:

        rm [NAME OF FILE]
    

Or if you're deleting a directory:

        rm [NAME OF DIRECTORY]
    

Plus, you can remove multiple files and folders simultaneously:

        rm [NAME OF FILE 1] [NAME OF FILE 2]
    

Special Characters

Occasionally, files and folders with special characters or spaces present a problem. In these instances, use quotes. For example:

        cd /path/to/folder/"My Documents"
    

Running this without the quotes will fail to navigate into that directory.

History

linux command line master tricks

Using Linux requires the command line. Sometimes, you'll need to know the history of commands run in the terminal. Viewing recently run commands is as easy as entering:

        history
    

This yields a list that shows the command number and it corresponding bash command. Occasionally, this won't be sufficient and you'll need a timestamped history. In this case, run:

        histtimeformat
    

Then, you'll see a list of the command history with dates and times. Sometimes you may wish to search for a command. That's totally feasible with the command line. Just use CTRL + R at the bash prompt. Then, you'll see a message which reads:

        reverse-i-search
    

From here, you may begin to search for commands.

String Commands

FFmpeg-update-clean-OBS

While you can enter commands on separate lines, you can also run commands together. This is particularly useful when installing or updating software. That way, you can perform both actions simultaneously:

        sudo apt-get update && sudo apt-get upgrade
    

Rather than the double ampersands, you can also string commands together in the Linux command line with a semicolon:

        sudo apt-get update ; sudo apt-get upgrade
    

This performs the same action.

Add PPA

OBS-ppa-clean

A PPA is a personal package archive, or software repository not included in the default Linux OS system install. In order to load some software, you'll first need to add a PPA. Like many Linux actions, this is usually performed with the command line.

        sudo add-apt-repository [NAME OF REPOSITORY]
    

One of my favorite Linux software options is Open Broadcaster Software, used for game streaming. OBS requires a PPA addition before it's fully installed:

        sudo add-apt-repository ppa:obsproject/obs-studio
    

Re-Run Command

One of the most helpful commands to truly help you master the command line is the ability to repeat commands. A common method is by typing:

        !!
    

Moreover, you can use this and throw on a piece of the command you missed. For example, if you forget to run a command with super user permissions, entering

        sudo!!
    

runs the command once more, this time adding super user permissions the second time. It saves you from having to type everything out again. But that's not the only method to repeat commands. You can also use the up arrow to see previously entered commands, and hit enter to execute them again.

Similarly, you can enter:

        !-1
    

Alternatively, pressing Ctrl + P shows the previously run command. Then, hit enter to execute it.

List

list command linux command line master tricks
        ls
    

A basic but incredibly useful command is the list function. This presents a list in the terminal which shows the major directories under a specific file system. For instance:

        ls /apps
    

This yields a list of all the folders under the /apps directory.

How to Master the Linux Command Line: Final Thoughts

The Linux command line can seem daunting at first. But it's not as complicated as it may appear. Managing files and folders, viewing the history of commands, and stringing commands together rank among the most common uses of the terminal.

There are loads of beginner tips for learning the Linux command line. This multipurpose tool is even suitable for accessing Facebook. Want to run the command line on Android? Try Termux for the full functionality of the Linux terminal on Android operating systems.

What tips for mastering the command line do you suggest?