DEV Community

Cover image for 5 Command Line Tips and Tricks

Posted on

5 Command Line Tips and Tricks

You're a Linux sysadmin or developer, it's your job to get things done. The command line is the best way to perform some tasks, such as copying or moving files. You can even use it to manipulate strings of text and other data.

Linux has a long history and a lot of great features, such as multiple command line options for each executable, shell aliases, built-in help, and powerful pipes. Unfortunately, all of these features become useless if you don't know how to use them properly.

Here are 5 tips that could make you more productive at the shell prompt.

Listing files 📋

When entering commands in Linux, you may skip some of the parameters that are included in them. For example, if you want to view all files inside a directory, you may enter ls by itself instead of ls -a. Both of these commands will list all files inside of this directory.

It is also important to note that Linux command lines are case sensitive, so make sure to pay attention to how you type them. For example, "ls" and "LS" are two different commands.

Memorize commands 💻

There are many commands for Linux: bash, tmux, vim, gpg, git, grep and many others. It would be a waste of time to look up every command all the time.

A better way is to memorize them, you can use this site to memorize Linux commands.

Get to know your command line history

Did you know that Linux has a built-in command line history?

Just press the up arrow key to go back in your command line history. If you press it again, you can cycle through your previous commands.

This may not sound like much, but it sure beats having to retype a complex command or the output of a previous command.

Kill programs if they hang

Use the kill command to send a signal to a program and kill it. You can use pkill to send signals to processes by name. For example, you can use the following command to send the kill signal to all Firefox processes:

sudo pkill -9 -f firefox
Enter fullscreen mode Exit fullscreen mode

cat on linux  bash

Redirect outputs of one command to a file

You can store the command line output by using the > character. This saves all of the command output to a file. For example the command below stores the files in a file:

ls -l > output.txt
Enter fullscreen mode Exit fullscreen mode


The command alias lets you save commands. This saves you a lot of typing. You can store them in your .bashrc file to reopen every start.

You can set different aliases:

alias c="clear"
alias cl="c; ls"
alias ca="c; la"
alias x="exit"
Enter fullscreen mode Exit fullscreen mode

That way you can type c to clear the screen, x to exit etc. You can save any command you want.

linux alias

Top comments (0)