Become a Linux Command Line Master With These Tips and Tricks
Pinterest Stumbleupon Whatsapp
Advertisement

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 5 Things Easier To Do In The Command Line [Linux] 5 Things Easier To Do In The Command Line [Linux] Read More .

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 Linux PPAs: Installation, Removal, and Security Linux PPAs: Installation, Removal, and Security PPAs -- personal package archives -- are a way to install Linux software via the Terminal. But are they safe to use? How can you remove a PPA? And which are the safest PPAs to... Read More , 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 Getting Started With Video Game Live Streaming on Linux Getting Started With Video Game Live Streaming on Linux Video game live streaming rose to prominence with the popularity of platforms like Twitch, but how can you stream your game play from a Linux computer? Read More . 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 A Quick Guide To Get Started With The Linux Command Line A Quick Guide To Get Started With The Linux Command Line You can do lots of amazing stuff with commands in Linux and it's really not difficult to learn. Read More . This multipurpose tool is even suitable for accessing Facebook Access Facebook From The Linux Command Line Access Facebook From The Linux Command Line Virtually everyone, especially in first world countries, is on Facebook. Friends, events, pictures, and plenty more are all commonly found on Facebook unlike any other location. However, an ultimate geek may not want to use... Read More . Want to run the command line on Android? Try Termux for the full functionality of the Linux terminal How to Use the Linux Command Line on Android With Termux How to Use the Linux Command Line on Android With Termux Replace tons of bulky Android apps with just one slim Linux command line app. Read More on Android operating systems.

What tips for mastering the command line do you suggest?

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Silverlokk
    November 24, 2017 at 3:48 am

    What, no file completion with the [Tab] key?

    E.g:

    cd /usr/home/user1/AndroidProjects

    While we're at it, the shortcut for the home directory is the tilde (~), so you can do

    cd ~/AndroidProjects

    And going back to file completion,

    cd ~/And[Tab]

    The Tab key will complete the filename for you so you get AndroidProjects.

    If you have more than one directory beginning with "And", the CLI will give you a list of those directories.

    IMHO, you need to know about shortcuts such as ~ and [Tab] file completion to "master" the command line

  2. Daniel
    November 17, 2017 at 3:53 pm

    If you run:
    sudo!!
    it will give an error.
    If you do, for example:
    ls
    sudo!!
    it will become: sudols
    for it to become sudo ls
    it mus be: sudo !!

  3. dragonmouth
    November 17, 2017 at 2:40 pm

    "A PPA is a personal package archive, or software repository not included in the default Linux OS system install"
    There is a very good reason for that. PPAs are repositories developed by third parties and are usable only by Ubuntu-based distros.. Ubuntu IS NOT the default Linux install and never will be. There are hundreds of other distros and most of them cannot use private repositories such as PPAs and AURs.

  4. Jim
    November 16, 2017 at 11:55 am

    I still prefer the GUI. I am a causal computer user and really don't want to learn and remember a bunch of commands if a GUI can do the same thing. No offense to those that do, I actually admire your commitment to the command line. Just not for me!

  5. mel
    November 15, 2017 at 3:36 pm

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

    and

    sudo apt-get update ; sudo apt-get upgrade

    are not the same command.on the first one, `sudo apt-get upgrade` part of the command gets executed, if and only if, the the first part of the command `sudo apt-get update` gets executed and finishes successfully. Whereas on the second line, both commands will run sequentially, regardless of the success or failure of the first command.

    Please do not mislead people.

    • Gazoo
      November 16, 2017 at 2:21 am

      Thank you, Mel. Was going to post the same thing. Basically:

      A && B -- B will run only if A succeeds

      A ; B -- run A followed by B, regardless of whether A succeeds or not.

      A || B -- runs B only if A failed

  6. Colin
    November 15, 2017 at 2:35 pm

    Can someone explain/give example of what /path/to/folder/ means? Have tried google, but can only find PATH which I think is different to path. Not quite sure what to replace 'path' with. Thank you.

    • mel
      November 15, 2017 at 3:39 pm

      by `/path/to/folder/`, the author says, you will replace it with the full path to your file. For instance, if you want to see the system logs, provided you have root privileges on your linux machine, you type,

      cat /var/log/messages

      your /path/to/folder/ string becomes /var/log/messages in this example. It is a figure of speech for the lack of a better term.

  7. ??nn??
    November 15, 2017 at 1:43 pm

    "&&" and ";" arent performing the same action.

    "&&" executes the next command only if the command before exited with error-code 0.
    ";" executes the next command anyway

    like this:

    $ ls
    foo

    $ mkdir foo && touch bar
    mkdir: foo: File exists

    $ ls
    foo

    $ mkdir foo ; touch bar
    mkdir: foo: File exists

    $ ls
    foo bar

  8. dragonmouth
    November 15, 2017 at 1:36 pm

    "For Linux users, the command line is an essentially, and ultra-powerful tool. "
    Command line may be a ultra-powerful tool but it is no way "essential" to the use of Linux. By saying that it is, you are feeding into the FUD, spread by Window Fans, that one must be a CLI expert to use Linux. This is not the 1990's. Many distros can be used perfectly well without having to resort to the use of CLI.

    • B.Mkubwa
      November 15, 2017 at 6:21 pm

      Hail Hydra to that!