Become a Linux Command Line Master With These Tips and Tricks
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
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.
Changing directories is pretty simple. In a terminal, enter:
For instance, to navigate into a specific folder like the Downloads folder on your harddrive, merely enter the path to your desired directory:
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.
In addition to switching folders, the command line allows for folder creation. You can make a directory by running the command:
Therefore, to make a folder called Apps, you would enter:
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:
If there aren’t folders for the full path, running this command creates directories for all of the folders in the path.
An oft-used command when handling files and folders is copy:
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]
Like copying files and folders, you can move items with the terminal. That command is:
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.
Want to remove files or folders? Just run:
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]
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.
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:
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:
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:
From here, you may begin to search for commands.
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.
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
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
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:
Alternatively, pressing Ctrl + P shows the previously run command. Then, hit enter to execute it.
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:
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?
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.