Most commonly used Linux Commands and their descriptions

If you're new to Linux, it can be overwhelming to navigate through all the commands and tools available. However, mastering the basics can go a long way in making your Linux experience smooth and efficient. In this blog post, we'll go through some of the essential Linux commands and their usage.

Before we get started, it's essential to note that Linux is a command-line operating system. Unlike graphical interfaces such as Windows or macOS, Linux is entirely based on typed commands. As a result, it can seem daunting for those who are used to graphical interfaces, but it's nothing to worry about. In fact, many developers prefer the command-line interface because of its speed and versatility.

Here are some of the basic Linux commands that every Linux user should know:

CommandDescription
pwdPrint working directory
lsList directory contents
cdChange directory
mkdirMake directory
rmRemove files or directories
cpCopy files and directories
mvMove or rename files and directories
nanoSimple text editor
catPrint file contents
grepSearch file contents
chmodChange file or directory permissions

pwd - Print working directory

The pwd command is used to print the current working directory. It's a handy command when you're unsure of the directory you're currently in. To use it, simply type pwd and hit enter. The output will be the full path of the current working directory.

ls - List directory contents

The ls command lists the contents of the current directory. It's an essential command when navigating through the file system. Typing ls in the terminal will display a list of all the files and directories in the current directory.

cd - Change directory

The cd command is used to change the current directory. To use it, simply type cd followed by the directory name you want to change to. For example, cd Documents will change the current directory to the Documents folder.

mkdir - Make directory

The mkdir command is used to create a new directory. To use it, type mkdir followed by the name of the directory you want to create. For example, mkdir MyFolder will create a new directory named MyFolder.

rm - Remove files or directories

The rm command is used to remove files or directories. It's a powerful command, so make sure you're using it with caution. To remove a file, simply type rm followed by the file name. For example, rm myfile.txt will delete a file named myfile.txt. To remove a directory, you need to add the -r option, which stands for recursive. For example, rm -r MyFolder will delete the directory named MyFolder and all its contents.

cp - Copy files and directories

The cp command is used to copy files and directories. To use it, type cp followed by the source file or directory and the destination file or directory. For example, cp myfile.txt MyFolder will copy the file named myfile.txt to the directory named MyFolder.

mv - Move or rename files and directories

The mv command is used to move or rename files and directories. To use it, type mv followed by the source file or directory and the destination file or directory. For example, `mv myfile.txt

Now obviously, when working you are not going to take a look at these notes or online every time you need to copy or move. Also, at the same time you need to practice it first so that you can learn the usage by hand. That is why, I have created a shell script that will create multiple folders and files inside those folders. To use that, simply copy the code and save that in a file. Make sure the extension of the file is .sh so the file name would look like generator.sh. Then in that folder run the command ./generator.sh . The shell script will create 3 different folders and inside the folder, there will be some text files.

Here is the shell script. I will add some task below the shell script so that you can practise on your own.

#!/bin/bash

# Create Fruits, Animal, and Continent directories
mkdir Fruits
mkdir Animal
mkdir Continent

# Create 3 text files in the Fruits directory
echo "Creating text files in the Fruits directory..."
touch Fruits/mango.txt
echo "Mango is a juicy and sweet tropical fruit." > Fruits/mango.txt
touch Fruits/orange.txt
echo "Oranges are citrus fruits that are high in vitamin C." > Fruits/orange.txt
touch Fruits/banana.txt
echo "Bananas are a popular fruit that are rich in potassium." > Fruits/banana.txt

# Create 5 text files in the Animal directory
echo "Creating text files in the Animal directory..."
touch Animal/lion.txt
echo "Lions are large carnivorous cats that live in groups called prides." > Animal/lion.txt
touch Animal/elephant.txt
echo "Elephants are the largest land animals on Earth and have a remarkable memory." > Animal/elephant.txt
touch Animal/giraffe.txt
echo "Giraffes are the tallest mammals in the world, with long necks and legs." > Animal/giraffe.txt
touch Animal/zebra.txt
echo "Zebras are herbivorous animals with black and white stripes." > Animal/zebra.txt
touch Animal/hippo.txt
echo "Hippos are semi-aquatic mammals that are known for their aggressive behavior." > Animal/hippo.txt

# Create 7 text files in the Continent directory
echo "Creating text files in the Continent directory..."
touch Continent/asia.txt
echo "Asia is the largest continent in the world and is home to many diverse cultures." > Continent/asia.txt
touch Continent/africa.txt
echo "Africa is the second-largest continent in the world and is known for its wildlife and natural resources." > Continent/africa.txt
touch Continent/europe.txt
echo "Europe is a continent that is rich in history and has many famous landmarks." > Continent/europe.txt
touch Continent/north_america.txt
echo "North America is the third-largest continent in the world and is home to many different countries and cultures." > Continent/north_america.txt
touch Continent/south_america.txt
echo "South America is a continent that is known for its vibrant cultures, music, and food." > Continent/south_america.txt
touch Continent/australia.txt
echo "Australia is the smallest continent in the world and is known for its unique wildlife, such as kangaroos and koalas." > Continent/australia.txt
touch Continent/antarctica.txt
echo "Antarctica is the coldest continent in the world and is mostly covered in ice." > Continent/antarctica.txt

echo "Folders and files created successfully!"

Practice Questions

Level: Easy

  • Use cd to go into the folder fruits

  • Use pwd to print the directory

  • Show the list of files in that fruits folder (use ls)

  • Create a new folder inside the fruits folder called backup_files (use mkdir)

  • Copy banana.txt file inside the backup_files directory

  • Move the mango.txt file inside the backup_files directory

  • remove banana.txt file from the fruits directory.

Level: Intermediate

  • go to animal directory and list out all the files including their permission level

    • hint
      Use thels -a to see the permission level
  • Create a directory called backup and copy all the files in that directory

  • remove zebra.txt from the backup directory only

Level: hard

  • Go to continent directory and list out all the files including their permission level

  • create a folder called africa

  • move the africa.txt file inside the africa

  • copy the files elephant.txt hippo.txt and zebra.txt into the africa folder

  • create another folder asia inside the continent folder.

  • copy mango.txt and lion.txt to the asia folder.

That's it for today. I will talk about the nano cat grep and chmod in a separate post. If you are here till now, please like and share my post with others. Thank you.


This post was originally posted my my own site. Here is the original link.