34 Basic Linux Commands Every User Should Know

When hearing about Linux, most people think of a complicated operating system that is only used by programmers. But it is not as scary as it seems, and to help you a bit, in this post we give you a summary with the basic Linux commands.

Linux is a complete family of open source Unix operating systems, which are based on the Linux kernel. This includes all popular Linux based systems like Ubuntu, Fedora, Mint, Debian and others. More accurately, they are called distributions or versions.

Since Linux was first released in 1991, has continued to gain popularity due to its open source nature. People can freely modify and redistribute it under their own name.

When operating a Linux operating system, you must use a shell, an interface that gives you access to the services of the operating system. Most Linux distributions use a graphical user interface (GUI) as a shell, mainly to provide ease of use for their users. It is common practice to use them when managing a .

That said, using a command line interface (CLI) is recommended because it is more powerful and effective. Tasks that require a multi-step process through the GUI can be accomplished in seconds by typing commands in the CLI.

So if you are considering using Linux, learning basic command lines will be of great help. In this article, you will learn 3. 4 basic Linux commands that will definitely help you navigate Linux.

Basic Linux commands

Before moving on to the Linux command summary, you must first open the command prompt. If you’re still not sure how to use the command line interface, check out this one.

Although the steps may differ depending on the distribution you are using, you can usually find the command line in the section Utilities.

Here is a list of basic Linux commands:

1. pwd command

Use the command pwd to find the path of the current working directory (folder) you are in. The command will return an absolute (full) path, which is basically a path of all directories starting with a forward slash (/) An example of an absolute path is /home/username.

2. cd command

To browse Linux files and directories, use the command CD. It will ask you for the full path or directory name, depending on the current working directory you are in.

Suppose you are in /home/username/Documents and you want to go to Photosa subdirectory of documents. To do so, simply type the following command: CD Photos.

Another scenario is if you want to go to a completely new directory, for example, /home/username/Movies. In this case, you should write CD followed by the absolute path of the directory: cd /home/username/Movies.

There are some shortcuts to help you navigate quickly:

  • cd .. (with a colon) to go up one directory
  • CD to go directly to the home folder
  • CD- (with a hyphen) to go to the previous directory
See also  When should you choose a VPS server (and how to start)

As a side note, the Linux shell is case sensitive. Therefore, you must type the directory name exactly.

3. ls command

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

If you want to see the contents of other directories, type ls and then the directory path. For example, enter ls/home/username/Documents to see the content of documents.

There are variations you can use with the command ls:

  • ls -R will also list all files in subdirectories
  • ls -a show hidden files
  • ls-al will list the files and directories with detailed information like permissions, size, owner, etc.

4. cat command

cat (short for concatenate) is one of the most used commands in Linux. It is used to list the contents of a file to standard output (sdout). To run this command, type cat followed by the file name and its extension. For example: cat file.txt.

Here are other ways to use the command cat:

  • cat > filename create a new file.
  • cat filename1 filename2>filename3 join two files (1 and 2) and store the output of them in a new file (3)
  • convert a file to uppercase or lowercase, cat filename | tr az AZ> output.txt

5. cp command

Use the command zip to copy files from the current directory to a different directory. For example, the command cp scenario.jpg /home/username/Images would create a copy of stage.jpg (from your current directory) in the directory of Images.

6. mv command

The main use of the command mv is to move files, although it can also be used to rename files.

The arguments to mv are similar to the cp command. You must write mv, the name of the file and the destination directory. For example: mv file.txt /home/username/Documents.

To rename files, the Linux command is mv oldname.ext newname.ext

7. mkdir command

Use the command mkdir to create a new directory: if you type mkdir Musicit will create a directory called Music.

There are also additional commands from mkdir:

  • To generate a new directory within another directory, use this basic Linux command mkdir Music/Newfile
  • Use the option p (parents) to create a directory between two existing directories. For example, mkdir -p Music/2020/Newfile will create the new file “2020”.

8. rmdir command

If you need to remove a directory, use the command rmdir. However, rmdir only allows you to remove empty directories.

9. rm command

The command rm is used to remove directories and the content within them. If you just want to remove the directory, as an alternative to rmdir, use rm -r.

Note: Be very careful with this command and check what directory you are in. This command removes everything and cannot be undone.

See also  Engineering Archives

10. touch command

The command touch allows you to create a new blank file via the Linux command line. As an example, enter touch /home/username/Documents/Web.html to create an HTML file titled Web In the address book documents.

11. locate command

You can use this command to to locate a file, just like the find command in Windows. Furthermore, the use of the argument -Yo together with this command will make it case insensitive, so you can search for a file even if you don’t remember its exact name.

To search for a file that contains two or more words, use an asterisk . For example, the command locate -i school*note

will search for any file that contains the word “school” and “note” in either uppercase or lowercase.

12. find command Similar to the commandlocate wearing find you also search for files and directories. The difference is that you use the command find

to locate files within a given directory. As an example, the find command /home/ -name notes.txt will look for a file called notes.txt

inside the home directory and its subdirectories. Other variations when using find

  • are: To find files in the current directory,
  • find . -name notes.txt To search for directories,

/ -type d -name notes.txt

13. grep command Another basic Linux command that is certainly useful for everyday use isgrep

. It allows you to search through all the text in a given file.To illustrate grep blue notepad.txt

will look for the blue word in the notepad file. The lines containing the searched word will be displayed.

14. sudo commandAbbreviation of “Super User Do

» (SuperUser does), this command allows you to perform tasks that require root or administrative permissions. However, it is not advisable to use this command for everyday use, as it could be easy for an error to occur if you do something wrong.

15. df command Use the command df for a report on system disk space usage, displayed in percentage and KB. If you want to see the report in megabytes, typedf -m

.

16. du command If you want to check how much space a file or directory takes up, the command du (Disk Usage) is the answer. However, the disk usage summary will display disk block numbers instead of the usual size format. If you want to see it in bytes, kilobytes, and megabytes, add the argument -h

to the command line.

17. head command The command head is used to view the first few lines of any text file. By default, it will display the first ten lines, but you can change this number to your liking. For example, if you only want to display the first five lines, typehead -n 5 filename.ext

See also  How to create a free web page? - Explanatory video

.

18. tail command This has a function similar to the head command, but instead of displaying the first few lines, the command tail will show the last ten lines of a text file. For example,tail -n filename.ext

.

19. diff command To make a difference, the command diff

compares the contents of two files line by line. After parsing the files, it outputs the lines that don’t match. Programmers often use this command when they need to make modifications to the program instead of rewriting the entire source code. The simplest way to use this command is

diff file1.ext file2.ext

20. tar command The command tar is the most used command to save multiple files to atarball

a common Linux archive format that is similar to the zip format, with optional compression.

This command is quite complex with a long list of functions like adding new files to an existing file, listing the contents of a file, extracting the contents of a file, and many more.

21. chmod command chmod

is another Linux command, used to change the read, write and execute permissions of files and directories. As this command is quite complicated, you can read the (in English) to execute it correctly.

22. chown command On Linux, all files are owned by a specific user. The command chown allows you to change or transfer ownership of a file to the specified username. For example, chown linuxuser2 file.ext will make that linuxuser2 be the owner offile.ext

.

23. jobs command The command jobs

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

24. kill command

If you have a program that is not responding, you can close it manually using the . It will send a certain signal to the program that is running badly and tells the application to terminate.

  • There are a total of sixty-four signs that you can use, but people generally only use two signs:SIGTERM (15)
  • : Requests a program to stop running and gives you some time to save all your progress. If you do not specify the signal when entering the kill command, this signal will be used.SIGKILL (9)

: Force programs to stop immediately. Unsaved progress will be lost.In addition to knowing the signals, you should also know the process identification number (PID) of the program you want to stop (kill

). If you don’t know the PID, just…

Loading Facebook Comments ...
Loading Disqus Comments ...