Basic Linux Commands You Should Know

Linux is a powerful, stable, open-source OS that’s almost endlessly customisable. But it can also come with a steep learning curve for new users. 

Whether you’re brand new to Linux or just need a refresher course, check out these 13 basic Linux commands to make your Linux experience easier!

1. Ls

This important command should be one of the first ones you learn. You can use the “Ls” command to list directories and files within a system. 

To see the contents of a directory, simply type Ls followed by the path you want to look at. To see files in your Photos folder, type Ls/home/user/Photos. If you run Ls without any parameters or flags, you’ll see the contents of the current directory.

You can also try:

  • Ls -a to see all files, including hidden ones, in a folder
  • Ls -R to list files in subdirectories
  • Ls -h to show file sizes in GB or MB instead of bytes.

2. Exit

All good Linux sessions must come to an end. Type “exit” to close a terminal window, log yourself out of a remote session, or end a shell script execution.

3. Alias

The “alias” command allows you to rename a command or a sequence of commands. This can be useful if you move back and forth between Windows and Linux terminals or if you just want to save a few keystrokes.

Typing “alias L=Ls” allows you to rename the Ls command to just L. However, the alias will only last until the end of the terminal session. To make them permanent, just add them to the .bash_aliases file.

You can also use “alias” to rename a sequence of commands. This can help save time if you need to perform the same series of commands on multiple files. That’s what makes alias one of the most useful basic Linux commands.

4. Whoami

“Whoami” will let you see who’s currently logged into the open terminal. Great for displaying your name or for figuring out who has a terminal open.

5. Df

If you need a quick overview of what’s taking up space on your computer, just type “df” to show the total size, used space, and available space on all mounted drives.

  • Df -h will show you the information in TB, GB, and MB instead of bytes.
  • Df -x allows you to exclude a particular file system that you’re not interested in.

6. Find

For those times when you can’t remember where the file you need is, there’s the “find” command. You need to give “find” two parameters: what it’s looking for and where it’s looking.

Use “.” to search the current folder. You can also use wildcards in your search- “*” represents a string of characters, and “?” represents a single letter. If you want to perform a case-insensitive search, type -iname after “find.”

7. Gzip

“Gzip” allows you to compress a file. By default, the system will delete the original file and just leave the compressed version. If you’d like to keep both versions, use the -k option.

8. Kill

If a program freezes up, you may need to end it with the command line. That’s what the “kill” command is for. You will, however, need the PID (process ID), which you can get by using the ps command.

Simply type “kill” followed by the PID. Don’t make this the normal way you close down programs, though. If you kill a process that other processes or programs need, you risk making your system unstable.

9. History

If you come back to a terminal after a break, you may not remember what commands you’ve already given. That’s where the “history” command comes in. It will display a numbered list of your previous Linux commands during this session.

If you want to repeat a command, simply type “!” followed by the list number of the command. !201 will perform the 201st command on the list. Typing !! will perform the most recent command.

10. Less

There are times when you may want to take a peek into a file. For instance, you may be trying to figure out what code file is the current version. 

Simply type “less” followed by the file name to see it. You can use the arrow keys and the PgDn and PgUp keys to read through the whole document. Because you aren’t viewing the file through an editor, there’s no risk of changing anything.

11. Ping

“Ping” is a great command if you’re trying to troubleshoot a network issue. It allows you to see if you have a connection with another device on the network.

Ping requires you to put in either the IP address or the device’s machine name. Your system will keep pinging until you hit Ctrl+C. You’ll be able to see a readout of the ping attempts and whether the other machine is sending back a signal.

12. Shutdown

When you need to shut down your system, turn to this aptly named command. You can do a few things with it, depending on the parameters you give.

“Shutdown” with no parameters will shut down your system in one minute. Adding the parameter “now” will shut down the system immediately. You can also schedule a restart by using either + and the number of minutes or a system time like 22:00.

When scheduling a shutdown, you can also add a brief text message that will display to other users on the same system. If you’re closing the system at the end of the workday, you might type “Shutdown +20 Shutdown in 20 minutes at 5 PM! Save your work!

13. SSH

“SSH” allows you to make a connection to a Linux computer remotely -for instance, if you need to sign into your work account while at home. You will need to provide your username and IP address, like “SSH me@” The system should then prompt you for your password.

Learning Linux

Linux can be complicated, but with a handful of basic Linux commands, it’s easy to get started. Try out the ones in this article on your own system and let us know how you go! If you have any questions about Linux, contact us here and we’ll get back to you as soon as we can!