From new user to power user, here are 20 Linux commands that will make your life easier.
Typing commands into a darkened terminal window might seem puzzling, but for many computer users, it's the most efficient, most accessible and clearest way to accomplish nearly any task on a computer. These days, thanks to all the projects that bring open source commands to non-open platforms like macOS and Windows, and with containers running everywhere, terminal commands are relevant to everybody.
Here are the top 20 commands a modern computer user might find themselves using:
Change directory (cd)
Outside of a terminal, you click on icons to move from one folder to another, but in the terminal, you use cd
. The cd
command, which stands for change directory, is how you move through a Linux system. It's the fastest and most direct route from one place to another.
For instance, on the desktop, when you want to move from your home directory (the place you keep all of your folders) to a folder called presentations
, then you might first have to open your Documents
folder, then open a folder called work
, then a projects
folder, and then the conference
folder, and finally the presentations
folder, which contains your exciting LibreOffice Impress slideshow. That's a lot of double-clicking. It may also be a lot of moving around on the screen, depending on where new windows appear, and a lot of waypoints for your brain to track. Many people circumvent this seemingly minor task by keeping everything on their desktop.
Terminal users avoid this issue by just typing:
$ cd ~/Documents/work/projects/conference/presentations
Experienced terminal users don't even bother typing all of that. They use the tab key to autocomplete the words for them. And sometimes, you don't even have to resort to autocompletion. You can use wildcards instead:
$ cd ~/Doc*/work/*/conf*/p*
Print working directory (pwd)
After you've clicked into a few folders on a desktop, it's easy to forget how you got to where you are. It's no different in the terminal. It only takes a few cd
commands to become dizzyingly disoriented. When that happens, use the pwd
command.
The pwd
stands for print working directory, and that's exactly what it does. The --physical
(or just -P
in some implementations) shows your location with any shortcuts (also called an "alias" or "symlink") resolved.
$ pwd
/home/tux/presentation
$ pwd --physical
/home/tux/Documents/work/projects/conference/presentations
Get filetype (file)
Use the file
command when you need to know what type of data a file contains:
$ file example.foo
example.foo: RIFF (little-endian) data, Web/P image [...]
$ file example.bar
example.bar: ELF 64-bit LSB executable, x86-64 [...]
The file
command isn't magic, of course. It only reports based on how a file identifies itself, and files can be wrong, corrupted or disguised. A rigorous inspection with hexdump provides more certainty, but for casual use, the file
command is convenient.
Get URL (curl)
The curl
command is a non-interactive web browser for your terminal. It's a development tool for web and API developers. It's a complex command for its flexibility, but it's worth learning if you want to interact with network services from your terminal smoothly.
Download our free curl cheat sheet, so you can internalize its many options.
View file contents (cat)
The cat command is short for concatenate, and it was very useful once for joining files that had been split (with a command intuitively called split
) into several small files due to size limitations. Today, cat
is mostly used as a way to dump the contents of a text file into your terminal for quick reference, unless you use head
, tail
, more
, or less
for that.
Despite its almost deprecated original purpose, and despite that several other commands also perform its secondary function, cat
is still a useful utility. For instance, it can be a stand-in for the copy (cp
) command:
$ cat myfile.ogg > /backups/myfile.ogg
It can reveal inconvenient invisible characters in files. The tab character, which breaks YAML, shows up as ^I
with the --show-tabs
option:
$ cat --show-tabs my.yaml
---
- hosts: all
tasks:
- name: Make sure the current version of 'sysstat' is installed.
dnf:
name:
^I- sysstat
^I- httpd
^I- mariadb-server
state: latest
It can show non-printing characters with --show-nonprinting
, mark the ends of lines with --show-ends
, provide line numbers with --number
, and more.
Find a file (find)
The find
command helps you find files, but thanks to its many options, it can help you find files with a variety of filters and parameters. Learn the basics from my introductory article.
And in case you've been wondering why the most fundamental command of all, the humble ls command, isn't on this list, it's because of the flexibility of find
. Not only can find list files:
$ find .
./bar.txt
./baz.xml
./foo.txt
[...]
It can also provide long listings:
$ find . -ls
3014803 464 -rw-rw-r-- 1 tux users 473385 Jul 26 07:25 ./foo.txt
3014837 900 -rwxrwxr-x 1 tux users 918217 Nov 6 2019 ./baz.xml
3026891 452 -rw-rw-r-- 1 tux users 461354 Aug 10 13:41 ./foo.txt
[...]
It's a technicality, but a neat trick to know.
Archive (tar)
The tar
file format, combined with a compression tool (such as gzip
), is a common way to produce a compressed archive similar to the way the ZIP tool works. To unarchive a tar
file:
$ tar --extract --file example.tar.gz
You can create your own tar file:
$ tar --create --gzip --file example.tar.gz example
Archive (zip)
Much of the world uses the ZIP format for compression. You can zip and unzip archives from the terminal, or even just browse an archive without unzipping.
To list the files in an archive without unzipping it, use the -l (for "list") option with the unzip
command:
$ unzip -l example.zip
To unzip an archive, just use the unzip
command:
$ unzip example.zip
To create your own archive, you must specify what you want the name of your archive to be, and then use the -r
option (for "recursive") to tell the terminal what folder you want it to compress:
$ zip example.zip -r example
View contents of a file (more, less, and most)
A pager is like the cat
command, except it pauses the output of a file at the bottom of your screen until you scroll down for more. It's a simple application, but there's nuance to each implementation. Do you scroll with arrow keys or the spacebar? Do you have to quit manually, or does the pager exit at the end of the file it's displaying? What's your preferred search behavior?
Try more
, less
, and most
commands and see which one is your favourite.
Open a secure shell (ssh)
OpenSSH not only helps secure connections to remote systems (including virtual machines), it also enables other commands. For instance, for many users, it's their .ssh
directory that makes it possible for them to interact smoothly with Git repositories, post updates to a website or log in to their cloud's control plane.
Using SSH directly is simple. You provide your username as it appears on the remote system, and the IP address (or fully-qualified domain name) of that system, and you have a secure connection.
$ ssh tux@10.0.0.33
Setting up secret SSH keys for services like GitHub and GitLab uses a related command, ssh-keygen
. This prompts you for some preferences (it's safe to accept the defaults), and then generates a key for you. You must never share your secret key, but what you do with the public key (the file ending in .pub
) depends on the Git host you're using. Generally, you just copy the contents of the public key file and paste it into a configuration panel of the Git host. You already know the command to view the contents of your public SSH key. It's the cat
command:
$ cat ~/.ssh/id_rsa.pub
Move and rename a file (mv)
The mv
command does double-duty: It both moves files and it renames files. It has several available safeguards, including --interactive
and --no-clobber
options to avoid clobbering an existing file, a --backup
command to preserve until it is verified at its new location, and the --update
option to ensure that an older version doesn't replace a newer file.
Elevate permissions (sudo)
When you have a single user with a known user name and all the privileges on a system, that user quickly becomes the target of attacks. By eliminating the need for a literal root
user, the sudo
command elegantly removes important information about your system from general knowledge. That's not all it does, though. With sudo
, you can easily manage privileges down to individual commands, users, and groups. You can enable password-less execution of select commands, record user sessions, verify commands with digest validation, and more.
Install software (dnf)
On Red Hat Enterprise Linux (RHEL), the dnf
command installs software and can update all software on the system. For desktop applications, you can also use the Software application, but dnf
is essential for installing commands with no graphical component.
To search for a command by name, use the search
keyword. For example, to search for tcpdump
:
$ sudo dnf search tcpdump
To install:
$ sudo dnf install tcpdump
Create a command alias (alias)
Turn long commands into easy-to-remember shortcuts by using the alias
command:
$ alias ls='ls --classify --almost-all --ignore-backups --color'
Clear screen (clear)
Sometimes your terminal gets cluttered. There's nothing like a nice, fresh screen after typing clear
(or pressing Ctrl+L in some shells).
Search the contents of a file (grep)
The grep
command is so ubiquitous that it's often used as a verb ("I'll grep
through some files") and a gerund ("grepping
some output"). It's a key component when parsing text in your shell, whether you're looking through log files or parsing the output of some other command. It's a way for the busy user to focus on specific information.
To search for a word in a text file using grep
:
$ grep Linux example.txt
To see the line number of where the word occurs, use the --line-number
option:
$ grep --line-number Linux example.txt
Search for a process ID (pgrep)
Managing your system's resources is mostly up to the kernel. However, when you prefer or require a manual approach, there's the pgrep
command. Using pgrep
, you can get the process ID of a running application or command:
$ pgrep firefox
Create an Access Control List (setfacl)
Traditionally, POSIX file permissions were determined by chown
and chmod
. Systems have become more complex, though, so there's a command to provide a little more flexibility. The setfacl
command lets you create an Access Control List (ACL), granting permissions to arbitrary users and setting default permissions for folders and the contents created within them.
Network tests (netcat)
Not every user needs netcat (nc
), but few who use it ever want to give it up. The nc
command is an all-purpose network connection tool.
It can connect to a port, similar to telnet
:
$ nc -u 192.168.0.12 80
It can ping a port, similar to ping
:
$ nc -zvn 192.168.0.12 25
It can probe for open ports, similar to nmap
:
$ nc -zv 192.168.0.12 25-80
And that's just a small sample.
You
The Linux terminal is, in part, about creative problem-solving. When you learn commands, you're also learning building blocks you can use to create your own commands. Many of the commands in my shell history are shell scripts I've written myself. The result is that my workflow is customized to how I want to work. Essential commands in your shell can also be the ones you design for your own efficacy and comfort. Spend some time getting to know some great commands, and then build your own. And when you hit upon something really good, make it open source so you can share your ideas with others!
training
Getting Started with Linux Fundamentals
About the author
Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).
More like this
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit