Free Shipping

Secure Payment

easy returns

24/7 support

  • Home
  • Blog
  • Basic Linux Commands You Must Know

Basic Linux Commands You Must Know

 July 14  | 0 Comments

In this Blog we are going to discuss all the necessary and basic commands which  every IT professional working on linux platform should know.
Computer-savvy individuals consider Linux as the best operating system owing its feature of getting customized more easily than its popular counterparts.
To learn better there are screenshot attached with every commands to practice and refer for understanding.

All the files present in the current directory are shown once the ls command was typed in the terminal.
     b) Syntax :-  ls -ltr filename

command is used to list one file with name mentioned in command.

Here you can see the command gives full detail about the file acadgild.
     
     c)Syntax: – ls –ltr

 -l long listing

-t time

-r recursive

Command is used to lists in the order of their creation time . list of files and directories contains permissions, links, ownership, group, date, time and file-name .
 Snapshot:-Here you can see the list of all files present in the directory arranged  in order of creation . Different columns indicate permissions, links, ownership, group, date, time and file-name. For every file all these content are stored in computer by default .
     
     d) Syntax:- ls –lc filename

Here you can see the listing of file in alphabetical order.
     
e)Syntax:– ls -la

To display all hidden files. All Hidden files are start with DOT(.)

Snapshot:-

Here you can see all the hidden files present in the current directory. We can notice all file is prefixed with .(dot) which indicates all file are system files, hidden from users.
 2.touch

     a)Syntax:- touch <filename>

To create an empty file. Size of file is 0 bytes.

Snapshot :-

Here file will be generated with name acadgild and will be present in same location until user modifies/deletes it.

     b)Syntax: touch f1 f2 f3 f4
Snapshot:-

Here the command will create 4 files named f1,f2,f3 and f4 at same location in the system.

3.mkdir

     a)Syntax:- mkdir directoryname

To create a new directory

Snapshot:-

Here you can see a directory named acadgild is created by the user.

     b)Syntax:- mkdir -p d1/d2/d3/d4/…………

-p parent directory

To create a directories & subdirectories recursively

Snapshot:-

Here you can see several directories and subdirectories are created and given parent permission at a time.

4.rm
     a)Syntax:- rm filename

It is used for to remove a file/files

Snapshot:-

Here you can see the file f1 is being deleted.

     b)Syntax:- rm -rf  < filename/directoryname >

-r recursively

                   -f         forcefully

To remove files, directories and subdirectories Recursively or Forcefully

Snapshot:-

Here you can see the the directory which contain data inside will also get deleted by using this -rf along with rm.
     c)Syntax:– rmdir < directoryname >

To remove an empty directory

Snapshot:-

Here you can see directory named sasi is being deleted.
5.echo
     a)Syntax:– echo

It reflects back the content ,whatever written after echo command.

Snapshot:-

Here you can see the comment written just after the command echo is printed again i.e anything following the echo command is displayed on the terminal.

     b)Syntax:- echo “some content” > filename

To insert text inside a file and will delete all previous data of the file.

Snapshot:-

Here you can see the statement is redirected to the file acadgild as content and later the content can be printed by cat command.

     c)Syntax:- echo “some content” >> filename

Snapshot:-

Here you can see the statement is redirected to the file acadgild along with the previous data as content and later the content is printed by cat command.

6.cat
Syntax:- cat filename

To read a file

Snapshot:-

Here you can see the cat command is used to through all the contents of file to the terminal.

7.more

Syntax:- more filename

To read a file page-by-page,

use SPACE-BAR to move for NEXT PAGE

Snapshot:-

Here you can see the data of /etc/profile is shown page by page. It is used to read long file, with lots of data.

8.inode

Syntax:- ls –i filename

Snapshot:-

Each inode stores the attributes and disk block location(s) of the filesystem object’s data
Here you can see for a file(acadgild) one inode will be created and that inode will be associated to file(acadgild).

9.who

     a)Syntax:- who

It shows the information about the users who are logged into the system currently.

Snapshot:-

Here you can see two user logged in named root and pranu with detail of what date, time and IP they used to log IN.
     b)Syntax: who –b

          -b  indicates the time and date of the last reboot.

To see when the server/system was started.

Snapshot:-

Here you can see the last time when system started/booted was 29/12 at 12.06 pm.
     c)Syntax:- who -r

-r indicates the current run level of the init process

A run level is a state of init and the whole system that defines what system services are operating.

Snapshot:-

Here you can see the run level is 3
     d)Syntax:- who -a

-a lists processes, variables, users, run-levels

Snapshot:-

Here you can see all the who commands summary at glance.
10.cd

Can be used in two ways, either way will result change in directory

     a)Syntax:- cd <directory name>

Here you can see we entered inside acadgild directory.

     b)Syntax:- cd ..

This command is used to exit from a directory.

Snapshot:-

Here you can see the command brings us one directory prior to where we was.

11.pwd

Syntax:- pwd

To display the present Working Directry

Snapshot:-

Here you can see the path of the current working directory. It is very useful while working on terminal.
12.date

Syntax:- date

To display the current date and time of the system.

Snapshot:-

Here you can see the current day,month,date and time followed by timing zone and year.

13.cal
      a)Syntax:- cal

It shows the present month calendar

Snapshot:-

Here you can see directories named big data, frontend and hadoop is copied when the parent directory is copied
     
     c) Syntax:-cp -f :

-f     Unlink. If a file descriptor for  a  destination  file

          cannot be obtained, this option attempts to unlink the

          destination file and proceed.

     d)Syntax:-cp -i :

                   -i         Interactive. cp prompts for confirmation whenever  the

          copy  would  overwrite  an existing target.

     e) Syntax:-cp -p :

-p preserve

 

it is use to (keep the same detail record of original file)preserve the permission, time, date of source file to target file

     

f)Syntax:- cp –rpfi <sourcefile> <destinationfile>

Snapshot:-

Here you can see the the contents of p1 is forcefully pushed into p2 by deleting all the previous data of p2.

16.df
     a)Syntax:- df -k

-k prints the allocation in Kilobytes

To display/read the free DISK FILES.
It lists file system name, allocated size, used size, available size, used size in %, mounted on.

Snapshot:-

Here you can see list of all the mounted disk path with actual disk utilization status in detail.
 
     b)Syntax: df -h

-h prints the allocation in  human readable format. scaling is done by repetitively dividing by 1024.

 
To display/read the DISK FILES in format

Snapshot:-

Here you can see the output is same as previous command but with only one difference the size are displayed in GB and MB which is more comfortable for humans to understand, as storage constraint is negligible in today’s era.

17.man
Syntax:- man <command-name>

It displays the full information about the command. Any command detail can be found inside man.

Snapshot:-

Here you can see the description of a command cat.

18.which

Syntax:- which <command-name>

It display  where the command is residing

Snapshot:-

Here you can see cat location is shown as output i.e, cat is being used from /usr/bin/cat .

19.uptime
Syntax:- uptime

To find out since how long the server is up & running

Snapshot:-

Here you can see the server is in running state science 2:14pm for 2 hours and 8 minutes.

20.id

      a)Syntax:- id

To display the present logged in user-id and group-id with username and groupname.

Snapshot:-

Here you can see the root user is sitting idle for 2 hours  and 7 minutes.

22.write

The write utility reads lines from the user’s standard input and  writes them to the terminal of another user. When first invoked, it writes the message:

    Message from sender-login-id (sending-terminal) [date]…

    to user. When it has successfully completed the  connection,

    the sender’s terminal will be alerted twice to indicate that

    what  the  sender  is  typing  is  being  written   to   the

    recipient’s terminal.

To send a message to the user who is using the same system

23.whoami

Syntax:- whoami

To see which username you logged in

Snapshot:-

Here you can see the IP of the server is 192.168.56.24

      b)Syntax:- ipconfig

In windows we use the command in cmd prompt for the same.

28.PERMISSIONS:

The full permission of a file/directory is 7 -7 -7 = rwx -rwx -rwx = ownership -group -other group

r-Read =4

w-Write =2

x-Execution = 1

so total rwx =7

The maximum permissions for a file is 6 -6 -6 = -rw- -rw- -rw-(- prefixed in owner  represents the type; file)

When we create a file the default permissions will 6 – 4 – 4. it Is obtained by reducing umask value to maximum permissions . i.e 666 – 022 = 644 (d prefixed in owner represent the type; directory)

Snapshot:-

Note: the umask value is 022 by using the below command we can see the command Syntax:- cat /etc/profile

The maximum permissions for a directory is 7 – 7 -7. it is obtained by reducing umask value to maximum permissions. i.e 777-022 = 755.

Snapshot:-

 

 

 

 

 

>