Linux Basic Commands Every User Should Know

Linux can seem complicated at first, but it’s not as bad as many people think. For starters, it’s not just for programmers.

Linux is an entire family of open-source Unix operating systems, which includes all of the most popular Linux-based distributions like Ubuntu, Fedora, Mint, Debian, and many more.

Linux has been showing up more and more in recent years. The main reason for Linux’s popularity is because it follows an open-source ideology, giving users the freedom to modify and distribute the operating system themselves under their own name.

Linux is an operating system that interacts with users through a terminal or shell. The graphical user interface (GUI) is used to make it easier for Linux users to use their OS.

CLI is more powerful and effective than GUI (graphical user interface). It allows you to do tasks like creating a directory or downloading files effortlessly.

Consider learning some basic Linux commands if you’ve never used them before. Knowing these 25 outputs will help newbies navigate the system successfully.

Linux Basic Commands

Before we go on with the list of commands, first you need to open the command line. Or if you’re not yet convinced about the usefulness of a CLI, check out this tutorial first.

Although the steps may differ depending on what distribution you’re using, you can usually locate the command line in the utility section.

Below is a list of the most basic Linux commands:

1. PWD command

Use the PWD command to find out where you are in your directory. If you give it a path it will return an absolute path, which is the full path of all directories starting with a forward slash.

root@mdb:~# pwd
/root
root@mdb:~#

2. cd command

To navigate within the Linux directory, use the cd command. You can either use the full path or name of a directory, depending on your current working directory.

If you want to navigate to Photos, which is a subdirectory of Documents, you can type the following command: cd ~/Documents/Photos

If you want to switch directories from one place to another, for example from /home/username/Movies, and go directly to /home/username/Movies, you need to type: cd /home/username/.

By using the shortcuts, you can quickly navigate to the desired destination.

  • cd .. (with two dots) to move one directory up

  • cd to go straight to the home folder

  • cd- (with a hyphen) to move to your previous directory

The Linux shell is case-sensitive. Make sure to type the name of the directory in lowercase when you access it, or you will only see nothing in return.

root@mdb:/home/username/Movies# cd /home/username/
root@mdb:/home/username# cd

root@mdb:/home/username# cd
root@mdb:~#

3. ls command

The ls command is used to view the contents of a directory. By default, this command will only display the contents of your current working directory

To view the contents of other directories, enter ls and then the directory’s path. For example, type ls /home/username/Documents to check out Documents.

The ls command is versatile and can be used in a number of different ways:

  • ls -R will list the files in the entire folder

  • ls -a will show the hidden files

  • ls -al will list detailed information about files and directories like owner, size, permissions.

root@mdb:/home/username# ls -R
.:
Movies

./Movies:
root@mdb:/home/username# ls -a
. .. Movies
root@mdb:/home/username# ls -al
total 12
drwxr-xr-x 3 root root 4096 Oct 25 19:24 .
drwxr-xr-x+ 5 root root 4096 Oct 25 19:24 ..
drwxr-xr-x 2 root root 4096 Oct 25 19:24 Movies
root@mdb:/home/username#

4. cat command

One of the most widely used Linux commands is a cat (short for concatenate). It’s used to list the contents of a file on the output (stdout). To run this command, type cat followed by the file’s name and its extension. For example cat file.txt.

These are just some of the ways you can use CAT:

  • cat > filename creates a new file

  • cat filename1 filename2>filename3 joins two files (1 and 2) and stores the output of them in a new file (3)

  • to convert a file to upper or lower case use, cat filename | tr a-z A-Z >output.txt

root@mdb:/home/username# cat >test2
hello everyone, how do you do?

root@mdb:/home/username# cat test2
hello everyone, how do you do?

5. cp command

To copy files from your current directory to a different location, you can use the cp command. For example, cp scenery.jpg /home/username/Pictures would create a copy of scenery.jpg (from your current directory) into the Pictures directory

root@mdb:/home/username# cp file.txt /backup
root@mdb:/home/username# cp file.txt /backup/new_file.txt
root@mdb:/home/username# cp -v file.txt file_backup.txt
'file.txt' -> 'file_backup.txt'
root@mdb:/home/username#

6. mv command

mv stands for Move. And it is primarily used to move files around. However, it can also be used to rename files.

The arguments in mv are similar to the cp command. You need to type mv, the file’s name, and the destination folder. For example: mv file.txt /home/username/Documents

To rename files in Linux, the command is mv old name.ext newname.ext

root@mdb:/home/username# ls
Movies file.txt file_backup.txt test2
root@mdb:/home/username# mv file.txt geek.txt
root@mdb:/home/username# ls
Movies file_backup.txt geek.txt test2
root@mdb:/home/username#

7. mkdir command

Creating a directory is very easy if you use the mkdir command. If you type “mkdir Music,” it will create a directory called Music.

There are extra mkdir commands as well:

  • To create a new directory inside another using Linux, you can use the basic mkdir command to make it happen. For example, Music/New file.

  • use the `p` option to create an intermediate directory. In this example, mkdir -p Music/2020/New file will create a new “2020” directory which is nested within the “Music” directory.

8. rmdir command

When you want to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.

9. rm command

The program rm is used to delete directories & files within them. As an alternative to the program rmdir, you may want to use rm -r.

Warning: it is critically important that you make sure you are in the right directory before using this command. It will delete everything and there is no undo.

10. touch command

The touch command is useful for conveniently creating blank files on the Linux command line. For example, enter touch /home/username/Documents/Web.html to create an HTML file entitled Web under your user directory Documents

11. locate command

You can use this command to locate a file. It’s like the Windows search command, but it’ll be case-insensitive.

To search for a file that contains two or more words, type an asterisk (*). For example, locate -i school note command will search for any file that contains the word “school” and “note”, whether it is uppercase or lowercase

12. find command

Similar to the locate command, the find command also searches for files and directories. The difference is, you use find when you want to search within a certain directory.

As an example, find /home/ -name note.txt command will search for a note.txt file within the home directory and its subdirectories

Find can also be written using other variations, such as:

  • To find files using the command line, type find . -name ‘notes.txt’

  • To find directories on linux use, / -type d -name notes. txt

13. grep command

grep is a comprehensive Linux command that’s quite handy when it comes to searching for information in text files. To show you how it works, let’s say I want to search for the word blue in my notepad file. If I use grep blue notepad.txt, it will find all lines that contain the word blue in my notepad file.

14. sudo command

Short for “super-user do”, this command makes it possible to perform tasks that require administrator or root permissions. However, it’s not advisable to use this command on a daily basis since mistakes might occur if you misuse the console prompt.

15. df command

To see the percentage of storage space left on your hard drive, type the df command after opening a terminal window. Alternatively, if you want to see how much data (in megabytes) is used up by each folder, type the command with df-M at the end. df -m

16. du command

The du (Disk Usage) command is the answer for this. However, it will show you in blocks rather than KBs.If you want to see it in bytes, kilobytes, and megabytes, add the -h argument to the command line. du -h

17. head command

The head command can be used to list the first few lines in a text file. If you want to show more than ten lines in a file, just add -n option and the number of desired lines. For example, head -25 filename.ext will bring up the first 25 lines in that file.

18. tail command

The tail command acts like the head command but displays the last ten lines instead of the first. For example, if you type in “tail -n filename.ext” it will display filename.ext starting from line 10 and ending at line 20.

19. diff command

Diff stands for “difference” and it’s a nifty utility that compares two files. It displays any line differences and can be used by programmers when they need to modify a program.

The simplest form of this command is diff file1.ext file2.ext

20. tar command

Remember the tar command is the most popular way to create archives. It’s an archiving utility with features similar to zip format. Compression is optional, but typically done for smaller file sizes

This command is quite complex and performs a lot of tasks such as adding new files to an archive, listing the archive contents, or extracting content.

21. chmod command

There’s another Linux command called chmod that can change or alter the permissions of files and folders.

22. chown command

Linux files are typically assigned to a specific user name. Use the chown command to change or transfer the ownership of a file. For example, if you wanted linuxuser2 to own a file, you would type in chown linuxuser2 file.ext

23. jobs command

The `jobs` command will display all current jobs along with their statuses. A job is basically a process that is started by the shell.

24. kill command

If you’re having trouble with an unresponsive application, you can terminate it manually by using the kill command. This will send the appropriate signal to the hangup program and allow it to quit itself.

There are sixty-four signals you can use, but people usually only use two (pace and gesture).

  • SIGTERM (15) — The kill command can be used to request that a program stop running. This way, when the process has finished, it won’t continue to consume valuable system resources. If you don’t specify a different signal when entering the command, the SIGTERM signal will be used..

  • SIGKILL (9) — forces programs to stop immediately. If progress was not saved, it will be lost;

In order to kill a process, you usually need to know the process identification number (PID). If you don’t know the PID, you can use ps ux

After knowing what signal you want to use and the PID of the program, enter the following syntax:

kill [signal option] PID.

25. ping command

You can use ping to see how well or badly you have a connection with a server. For instance, by opening up the command prompt and typing ping google.com, you’ll get real-time data about whether your computer can get through to Google – and how quickly it takes to do so.

26. wget command

The Linux Command Line is very useful when it comes to downloading files. For example, the wget command is quite handy in this regard. To download with wget, type `wget followed by the download link`

27. uname command

The uname command prints detailed information about your Linux system, including the machine name, operating system, kernel, and more

28. top command

The ‘top’ command is a Linux equivalent to Task Manager in Windows and will show which processes are running, how much CPU they use, and more. It’s useful for monitoring system resource usage and you can kill misbehaving processes easier with top. You can also press ‘q’ to quit the program after choosing what you want to do.

29. history command

If you use Linux for a long enough time, you’ll come to rely on it in everyday things. The command history can be very beneficial if you’re looking to find out older commands that might have been used previously.

30. man command

Confused about the purpose of some Linux commands? Don’t worry, you can learn how to use them from the shell with the man command. For instance, entering man tail will display instructions about how to use this tool.

To Sum Up

Basic Linux commands help execute tasks more quickly and effectively. It might take some practice to remember all of them, but nothing is impossible with a lot of effort. In the end, mastering these basic Linux commands will make you more efficient.

Leave a Comment