Two things are true of the Linux command line: one, there are thousands of possible commands you can use at any given time, and two, you’ll only end up using a fraction of them. Despite the power offered, most of us just repeat the same commands over and over again.
So whether you’re just getting started or simply curious, here are the most common commands that will carry you through your entire time on Linux.
Terminal Navigation Commands
Before you can really make full use of the terminal, you’ll need to know how to navigate it. That’s why we consider these the most basic Linux commands: no amount of terminal knowledge will help you if you can’t change directories or get help on a command you don’t remember how to use.
- && — This one is so basic that it’s not even technically a command. If you ever want to run multiple commands in sequential order, just stick this in between each one. For example,
[command1] && [command2]will first run [command1] then immediately follow it with [command2]. You can chain as many commands as you want.
- ! — Repeats a recently used command. Best to use it in conjunction with the
historycommand. You can use
!nto repeat the n-th command in history. You can also use
!-nto repeat the command that happened n commands ago.
- cd — Changes the current terminal directory.
- clear — Clears the terminal screen.
- history — Displays a list of all recently used commands. You can also cycle through recently used commands by pressing the Up and Down arrow keys in the terminal.
- ls — Displays a list of all files in the current terminal directory. You can modify it with parameters to specify some other directory or to change the format of the list.
- man — Displays a help page (from the manual) based on your search query. Very useful for learning how to use a command you don’t recognize or when you forget the parameters for an infrequently used command. If you’re ever confused, turn to man.
- pwd — Displays the current terminal directory as an absolute path.
- whatis — Displays brief descriptions of command line programs. Think of it like a simplified version of
manwhen you aren’t sure what a command does but don’t need the full manual on how to use it.
File Management Commands
Most Linux distros come with a graphical desktop environment, and no matter which desktop environment you choose to use, you’ll be able to browse and manage files in the same way you would on Windows or Mac — but for complex tasks, it’s often easier and faster to use the command line.
- cat — When used on a single text file, it will display the contents of that file. When used on two or more text files, it will display all of their contents in sequential order. Use the redirection operator (“>“) to combine multiple text files into one text file.
- chmod/chown — The
chmodcommand changes the read, write, and execute permissions of a file while the
chowncommand changes the user and/or user group that owns a file.
- cp — Makes a copy of a file. By default, the copy appears in the current terminal directory, but you can also specify the destination directory as well.
- find — Searches a specific directory (or your entire system) to find files that match a given set of criteria. There are dozens of options, including filename, filetype, filesize, permissions, owners, date created, date modified, etc.
- grep — Searches a specific file or set of files to see if a given string of text exists, and if it does, tells you where the text exists in those files. This command is extremely flexible (e.g. use wildcards to search all files of a given type) and particularly useful for programmers (to find specific lines of code).
- locate — Searches the entire system for files or directories that match the search query, then outputs the absolute paths for each match. By default, it only searches in directories for which you have permissions. This is the simplest and fastest way to find a file.
- mkdir/rmdir — Creates or deletes a directory, by default in the current terminal directory but a target directory can be specified as well. When deleting, the directory must be completely empty.
- mv — Moves a file from one directory to another, and you can specify a different name for the file in the target directory. You can use this command to rename a file by moving it to the same directory but with a different filename.
- nano/emacs/vim — The three main terminal text editors that exist on nearly all Linux systems, ordered by increasing complexity. Newbies should stick to
vimare wildly complex (and wildly powerful).
- rename — Changes the name of a file or a set of files. Comes with a lot of interesting parameters, allowing you to automatically rename a bunch of files according to a pattern.
- rm — Removes files. With a certain parameter, it can be used to wipe the entire contents of a specified directory. It can also be used to delete several files that all match a certain filename pattern.
- touch — Changes the date accessed or date modified of the given file to right now.
- wget — Downloads the file or page at the given web URL.
- zip/gzip/tar — Various formats for compressing and decompressing file archives.
System Management Commands
Again, most Linux distros provide a graphical way to manage your system settings, but you may find it easier (and perhaps even more informative) to use these time-tested commands instead. Indeed, these commands tend to offer a lot more power in terms of what you can do.
- apt — While
aptisn’t a command in itself, there are three commands that you must know to make full use of APT:
add-apt-repository(for locating third-party packages),
apt-get(for actually installing packages), and
apt-cache(for searching your repositories).
- If your distro doesn’t use APT, it may use YUM, RPM, or some other alternative. Look into their equivalent commands.
- bg/fg — Sends a foreground job to run in the background or a background job to run in the foreground. For more on jobs, see the
- df — Displays how much space is used and free on your system.
- free — Displays how much RAM is used and free on your system.
- ip — Displays useful network details such as your IP address, network interfaces, bandwidth usage, and more. Can also be used to configure network-related settings.
- jobs — Displays all current jobs and their statuses. A job is just a representation of a running process or group of processes.
- kill/killall — You can use
killto end a process according to its process ID (often used in conjunction with the
pscommand) whereas you can use
killallto end all processes whose names match your query.
- mount/umount — Attaches and detaches a separate filesystem to your system’s main filesystem. Mostly used to make external devices, like hard drives or USB drives, interactable with your computer.
- ps — Displays a list of currently running processes. By default, it only lists processes started under your current user, but parameters exist to find and filter all kinds of processes.
- sudo/gksudo — Prepending
sudoallows you to run any command as superuser (e.g.
sudo [command1]). If you want to run a graphical program with superuser privileges, use
gksudofollowed by the executable file for the program.
- top — Displays a list of currently running processes, sorted by how much CPU each processes uses. Unlike
ps, this command regularly updates in real-time. Basically a terminal equivalent to Task Manager.
- uname — Displays core system information depending on the parameters you use, such as kernel name and version, machine hardware, and operating system.
- uptime — Displays time elapsed since last boot.
- whereis — Finds the location of the executable file for a given program.
- whoami — Displays the current user name. Comes in handy when you’re switching between users with the
sucommand and you lose track of who you are at the moment.
- Click to share on Twitter (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to share on Google+ (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to share on Pocket (Opens in new window)
- Click to share on WhatsApp (Opens in new window)