Basic Linux Commands


Are you looking for the basic Linux commands? You’re in the right place. Linux is an open-source operating system and there are many advantages of using Linux. Linux is pretty lightweight and fast compared to Windows. Besides, most applications that you will use on your Linux operating system are available as open source. Further, you can largely customize a Linux operating system. Hence, switching over to Linux is a great decision for any computer user.

Linux can be mainly of two types: Debian and Arch. Both use almost the same commands except for a few package-related commands. However, in this post, we will concentrate on Debian’s commands to keep things simple for the readers.

There are many Linux distros available for free. These distros are mostly either based on Debian or Arch Linux. Some of the most popular distros are Ubuntu, Linux Mint, Manjaro, Xubuntu, Kali, and Fedora. Ubuntu and Linux Mint are based on Debian.

Manjaro is based on Arch. Xubuntu is a flavor of Ubuntu with XFCE desktop environment while Ubuntu uses Gnome desktop environment. Kali is based on Debian Testing Branch, and Fedora is based on Red Hat Enterprise Linux.

If you just entering the Linux world, I recommend using either Linux Mint or Ubuntu. Linux users mostly prefer doing things based on the terminal. However, you can use applications in GUI versions as well.

Basic Linux Commands for Beginners

As you open the Linux terminal, you will be on the Home directory. The next best thing you can do after opening the terminal is hit the ls command to list the directories in the Home directory.

ls (Listing the Directories)

When you type the ls command, it will display all directories and files in the Home directory. Some of the directories that you will find in the Home directory are Desktop, Documents, Music, Videos, and Downloads. The next thing that you may like to do is try to get into a directory.

cd (Getting into a Directory)

To get into a directory, we use the cd command. For example, to get to the Desktop, you can type the command cd Desktop and hit enter. However, you don’t have to type the entire spelling for Desktop. You can type just Des and hit tab and this will autocomplete the word for you. So, now we are in the Desktop directory. To move out of the Directory, you can type cd …. To move to the Home Directory anytime, you can type cd ~. Next, we will see how to find the Directory path.

pwd (Finding the Directory Path)

Using this command, you can check your directory path anytime. Simply type pwd and hit enter. This will display the directory path.

So far, we have learned how to list the directories, get into a directory and check the directory path. It’s time to see how we can create subdirectories and files in Linux. Let’s use the Desktop directory for this. Next, we are going to create a subdirectory in the Desktop folder.

mkdir (Creating a Directory/Sub Directory)

To create a folder simply type mkdir followed by the folder name. For creating a folder called test, you will need to type the command, mkdir test. Next, we will see how to create a file inside the test folder.

touch (Creating a File)

We are inside the test folder and now, we want to create a text file called file.txt. To do this, you will have to type touch file.txt. Next, we will like to add some text to it and for that, we can open the file in nano editor. Nano comes preinstalled in almost all Linux distros.

Editing a File in the Nano Editor

To open the file in nano, simply type nano followed by the file name, and to open the file that we just created in nano, we can type nano file.txt. This will open the file in Nano and you can start entering your text and after you finish, press ctrl+o and hit enter to save the changes. To exit, you will need to press ctrl+X. You can edit the file as many times as you want by opening the file in Nano, editing it, and saving the changes.

Here are a few more useful nano keybindings:

  • Alt+: Get to the beginning of the content
  • Alt+/: Get to the end of the content
  • Alt+a: Set a Marker
  • Alt+6: copy
  • Ctrl+6:select & unselect
  • Ctrl+o & Enter: save
  • Ctrl+x: exit
  • Ctrl+u paste
  • Ctrl+k: cut/delete
  • Alt+u: undo
  • Alt+e: redo
  • Ctrl+w:find
  • Ctrl+: search and replace

mv (Moving a file)

We are in the test subdirectory that we created inside the Desktop directory. Now, we want to move the file called file.txt to Desktop and for that, you have to type mv file.txt /home/username/Desktop.

mv is also used for renaming files in Linux. Right now, our file.txt is in the Desktop directory. We will first need to get to the Desktop directory using cd.

After that, type mv file.txt file2.txt and hit enter. This should rename file.txt to file2.txt and if you open the file in Nano, you will see it contains all the previous content that you added to the file.txt file. Next, we’ll look into how you can remove a file.

rm (Removing a File)

rm stands for remove and we use rm to remove files. We are in the Desktop Directory and what we have in here is a file2.txt and an empty subdirectory, test. To remove the file, file2.txt, you can type rm file2.txt and hit enter. This should remove the file.

rmdir (Removing an Empty Directory)

rmdir stands for remove directory. However, the command can be used only to remove the empty directory. To remove the subdirectory test, you can type rmdir test and this will remove the empty subdirectory.

To remove a directory or a subdirectory with files or subdirectories in it, you need to type rm -rf followed by the directory name and hit enter.

Updating & Upgrading

To update your system, you can type sudo apt-get update and hit enter. In case there are any packages that need to be upgraded, you could use the command sudo apt-get upgrade.

Installing and Removing Packages

The term, “Package” stands for Application or Software in Linux. It’s time to see how you can install and remove packages in Linux. To install a package, you need to type sudo apt install followed by the package name. For example, you want to install xsel. Xsel is used to clean the clipboard (command – xsel bc). You can do install the package by typing sudo apt-get install xsel and hitting enter.

To remove a package with its dependencies, you can type sudo apt-get purge –auto-remove followed by the package name. For example, you want to remove the package xsel and for that, you can type sudo apt-get purge –auto-remove xsel. After that, you can type the command sudo apt-get autoremove to remove orphaned or unnecessary dependencies.

Wrapping it Up

This is pretty much it to get you started with the Linux terminal. These commands aren’t difficult to learn and all you have to do is practice them for a day or two and you will find yourself using these commands almost every day just as other Linux users do. I am sure you have found this post useful.

Leave a Comment

%d bloggers like this: