Important Linux commands for beginners (basic).
By: Abdeali Stationwala
Tags: Linux, Ubuntu, Beginner, Automation, Linux Commands

Linux

What is Linux?

Linux is an open-source operating system same as Windows, macOS, etc. Linux has been around since the mid-1990s. It’s in your phone, Refrigerator, television, etc. From cars to supercomputers, from small to big organizations, the Linux OS is everywhere.

Distros in Linux

For a while Linux has grown its community to a larger level, spreading its wings to the greater communities.

Some of the famous distros of Linux are:

· Debian

· Ubuntu

· Gentoo

· Linux Mint

· Red Hat Enterprise

· CentOS

· Pop OS

· Kali Linux

· Fedora

· Arch Linux

Linux Distros

Linux Terminal Commands

Now we will see all the important commands of the Linux terminal that at least one should know. I will use the Ubuntu distro for the same because it is most popular for beginners. You can use any distro terminal. In ubuntu shortcut to open the terminal is ctrl + alt + t.

Updating and upgrading packages (Ubuntu):

For update:

sudo apt-get update

or

sudo apt update

The update command will show how many packages need to be updated and the upgrade commands install the packages.

For upgrade:

sudo apt-get dist-upgrade

or

sudo apt upgrade

Installing other packages

sudo apt install package_name

for eg., we will download pip for python in Ubuntu:

sudo apt install python3-pip

where sudo => “Super User Do” &

package_name => python3-pip

Inbuilt editor of Linux terminal

Nano is the inbuilt default editor of Linux. To open nano for a file use:

nano filename.ext

And then the editor will open in the terminal that looks like the below image.

nano editor

Note: To save the file press ctrl + o and enter, then press ctrl + x to exit.

Base directory

To know your base directory just use:

echo $HOME

Output: /home/username

Here, the $HOME variable is a path variable that stores the base directory of your system.

Current working directory

To know about your current working directory just use:

pwd

output: /home/username/PythonProjects/JupyterNotebooks

where pwd => Print Working Directory

pwd helps us to show the full path from the base to the current project or work.

working of commands

Going back to the base directory direct

To go back to the root directory from any current directory just use:

cd $HOME

Now run pwd and check you will see that you are currently standing on the root.

output: /home/username

Moving up and down one folder from terminal

I. To move to the parent folder use command:

cd ..

II. To move inside a folder use:

cd folder_name

where folder_name => your folder present in the current directory.

working of commands

list of all files in the current directory

To see all files and folders present in the current directory use these three commands:

I. For only the list of names of the files use the command:

ls

II. For listing the names with details like date and time etc.

ls -l

III. For a list of all files including hidden files and folders with details use:

ls -la

working of commands

Manipulating files and folders

In this, we will see some commands to create delete, and move folders and files.

I. creating a folder

mkdir folder_name

Here mkdir => Make directory

Note: This command will create a folder in the current directory.

II. Removing a folder

rmdir folder_name

Here rmdir => Remove directory

Note: This command will only delete the folder that is present in the current directory and should also empty or else throw an error.

III. Creating a file

touch file_name.ext

Here touch => will create an empty file in the current directory.

IV. Removing or deleting a file

rm file_name.ext

Here rm => remove or use ‘*’ instead of file_name for all files to be removed.

Note: This command will only delete the file that is present in the current directory or else throw an error.

V. Moving one file to another directory

mv file_name.ext directory_path

For example:

mv test.txt ../test_folder

Here, mv => Move

test.txt => file_name or use ‘*’ for all files,

../ => to parent directory of the current directory,

test_folder => folder present in parent directory.

Note: If the file is not present or the folder is not present at their given position this command will throw an error.

“No such file or directory.”

You can also use $HOME/test_folder if the folder is present in the base directory.

VI. Moving one file content to another file or Renaming file.

mv file1.ext file2.ext

here file1 is the existing file and file2 is the rename of the file1.

Note: This command will delete the file1 and only file2 will exist with the same data.

VII. Copying one file to another file.

cp file1.ext file2.ext

where cp => Copy

**file1 should be present in the current directory and file2 will be created automatically.

Note: Comparing to the mv command, the cp command will not delete file1 from the current directory.