Basic Linux Command

Basic Linux Command

Introduction

What is Linux ?

Basic commands

Introduction:-

Everybody has at least one friend who is this pro “Linux” guy, who often looks down on Windows and Mac users. If you are frustrated about your “Linux” friend’s rants and wanted to see what all the fuss about Linux is or you just wanted to try a Linux flavor out of curiosity, then you might have come across the term “Linux Commands”.

In this Beginner's Linux Commands, we will try to help you understand a little bit about Linux in general and how to get started with an ocean of Linux Commands. It just means that there are a lot of commands. So, let’s get started.

what is Linux ?

Linux is an operating system’s kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, which means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “Distros”.

Some of the common Linux Distributions are Debian, Kali Linux, Ubuntu, Fedora, Red Hat Enterprise Linux, CentOS, openSUSE, Arch Linux, Manjaro Linux, Gentoo etc.

Basic Commands:-

pwd command-

Thepwdis short for Present Working Directory. It's a command-line utility tool that returns the path to the directory you're in at that moment. The output contains the full system path of the current working directory. By default,pwdignores the symbolic links but with a proper option, you can look at the full physical path of the current working directory.

$ cd /home/dd/Pictures
$ pwd
/home/dd/Pictures

cd command-

Thecdcommand stands for “change directory,” and it allows you to navigate from one directory to another. To navigate to a particular folder withcdcommand, pass the folder path as the parameter, like so

$ cd /home/dd/Documents
$ pwd
/home/dd/Documents

With no options, thecdcommand changes the working directory to the user’s home directory.

$ cd
$ pwd
/home/dd

Another way of doing the same i.e to navigate to the home directory quickly is to use the~switch.

$ cd ~
$ pwd
/home/dd

You may want to navigate to the previous working directory without typing the entire folder path again.cd -does exactly that.

$ cd /home/dd/Documents
$ pwd
/home/dd/Documents
$ cd -
$ pwd
/home/dd

mv Command-

Themvcommand is a utility command thatmoves files and folders from one location to another. Themvcommand can move a single file, multiple files, and directories. To move a single file usingmv, pass the name of the file that needs to be moved as a first parameter and the new file name as a second parameter. In this casemvcommandsrenamesthe filename.

$ mv a.txt b.txt
// renames the file a.txt to b.txt
$ mv some_directory new_directory
// renames the folder some_directory to new_directory

To move a group of files to a folder, pass the name of the files followed by the destination folder name withcdcommand.

$ mv a.txt b.txt c.txt some_directory
          OR
$ mv *.txt some_directory

By default themvcommand overwrites the destination file. To prompt before overwriting the destination file, use the-ioption.

$ mv -i a.txt b.txt
mv: overwrite 'b.txt' ?

rm Command-

Thermcommand is short for "remove." It's used to delete files and directories.Be cautious when you use thermcommand because once a file or directory is deleted, you cannot recover it later.To delete a single file, just pass the name of the file along with thermcommand.

$ rm file.txt

It is also possible to delete multiple files at one go.

$ rm file1.txt file2.txt image.png

To delete a directory, use the-rswitch, which means to delete all files and folders recursively.

$ rm -r some_directory

To perform deletion safely and interactively, use the-iswitch, which prompts before each delete action is performed.

$ rm -i file.txt
rm: remove regular file ‘file.txt’? y

mkdir command-

mkdircommand is "make a directory." To create a directory, pass the name of the directory along withmkdircommand.

$ mkdir test_directory

Sometimes, you need to create a nested directory structure. Rather than creating directories one by one, use the-poption to create an entire directory structure.

$ mkdir -p dir1/dir2/dir3
$ tree dir1
dir1
└── dir2
    └── dir3

If you wantmkdirto give details of what operation it is performing in the process of creating directories, use the-vswitch.

$ mkdir -v -p dir_1/dir_2/dir_3
mkdir: created directory 'dir_1'
mkdir: created directory 'dir_1/dir_2'
mkdir: created directory 'dir_1/dir_2/dir_3'

ls-Listing commands

ls option_flag arguments --> list the sub directories and files avaiable in the present directory

ls option_flag arguments
  • ls -l--> list the files and directories in long list format with extra information

  • ls -a --> list all including hidden files and directory

  • ls *.sh --> list all the files having .sh extension.

  • ls -i --> list the files and directories with index numbers inodes

  • ls -d */ --> list only directories.(we can also specify a pattern)