Linux Basic Commands for Beginners

basic_linux_commandLinux Basic Commands and Examples of them

Commands: A instruction  for a computer or device to perform a specific task know as ‘Command’. It give through terminal as input (by user), so also we can say that command is an interpreter.

[gaurav@gauravx ~]$____

Command line:  A command line is a text-based interface which can be use to input instruction to a computer system. A Linux command line is provided by a program called “The Shell“.  So in previous post shell are covered, where or as all know there are many Shells have been developed.  So The default shell for users in Linux is the BASH Shell (Borne Again shell) and also it is in MAC OSx.

Instruction: Open terminal ( ctrl+shift t ) it displays a string like “ [user@hostname~]$ _ or  [root@hostname~]$#_” mean of this, it is waiting for a command from the user  ‘it is called Shell prompt’.

So command entered at the shell prompt have three basic parts

  • command : command(name of the program) to run
  • option :      it may be followed by one or more options, which adjust the behaviour of command what it will do and it will start with – 0r – – (hyfen)
  • Arguments :  which are typically targets of the command or indicate a target that the command should operate on.

[gaurav@gauravx ~]$ Command   Option(- or –)     Argument

here the ‘$‘ shows it log-in as “local user” and if it will show ‘# it mean log-in with “root”(super user). And ‘ [gaurav@gauravx ~] ‘ “gaurav” is username and after @ “gauravx” is host-name  and “~”(tilde)  show, user are in own home directory ,  so it mean the place of this sign are defined for showing the present working directory  or in which directory users are that time (User’s current directory).

Commands and examples

  •  date, command execute/used  for ‘ Get the current time and date od system/server’

[gaurav@gauravx ~]$ date

[gaurav@gauravx ~]$ date   +%X                                (show only time and here +%X is the option)

[gaurav@gauravx ~]$ date    +%x                                 (show only date)

[gaurav@gauravx ~]$ date    +%r                                 (show time with am/pm)

[gaurav@gauravx ~]$ date    +%R                               (show time without am/pm)

[gaurav@gauravx ~]$ timesystemctl restart  sshd.server  (show the processing time of system)

Note: If you want to change the date, you would have to switch to super user (root) because a local user can’t change the date and time. And also there are lot of option to be used according your requirement to get the time and date, month etc of your system/server.

[root@gauravx~]# timedatectl    set-time    hh:mm:ss                (Date format yy-mm-dd)

  •  File , command is used for know file types.

[gaurav@gauravx ~]$ file     /filename

[gaurav@gauravx ~]$ file    /bin/passwd

  • echo, command is used/execute  for displaying a message on terminal.

[gaurav@gauravx ~]$ echo ” Hello everyone , hope you are enjoying with is article

  • who, command is used for displaying the current user information

[gaurav@gauravx ~]$ who 

  •  Passwd , command used to change the password of current user and also with passing the argument as ‘user name’ we(root) can change the password of any user.

[gaurav@gauravx ~]$passwd                                                   Changing password for user gaurav

(current)UNIX password: old_password(must type)

New password: new_password(must type)

Retype New password: new_password

Passwd: All athuntication tokens updated successfully.

  • history, command used toshows the display a list of previously executedcommand prefixed with a command number.

[gaurav@gauravx ~]$ history

  • head, command used to display the first 10 command executed or from the top. Aslo we can use of it with pipe ‘|’, will discuss in later.

[gaurav@gauravx ~]$ head

[gaurav@gauravx ~]$ history  |  head

  • tail, command used to display the last 10 command executed or from bottom.

[gaurav@gauravx ~]$ tail

[gaurav@gauravx ~]$ history  |   tail

Also  head and tail command display the beginning and end of a file respectively. By default it show only 10 lines but they have option -n for displaying the more no of lines .

[gaurav@gauravx ~]$ head        /etc/passwd            ( it will show by default 10 Lines from top)

[gaurav@gauravx ~]$ head   -n  20     /etc/passwd        (now it will display 20 lines)

……………output omitted…………………..

  •  !, command , it is a meta character of shell is used to expand previous command without having to retype them. Its use with command executed line.

[gaurav@gauravx ~]$ !  24    (suppose on 4 no. the date command have been executed) o/p of it.

date
Thu Apr 14 20:21:55 IST 2016

  •  wc, command used to count the lines,words,characters in a file.It can take no. of option –l, -w, -c.

[gaurav@gauravx ~]$  wc      /etc/hosts

12 33 362 /etc/hosts  (word-33, lines-12, characters- 362)

[gaurav@gauravx ~]$  wc   -l    /etc/hosts

12  /etc/hosts

So, here above the most basic commands are covered and it is not end of commands, and example there are lot on commands and basic commands too like listing ‘ ls, ll’ , change directories location cd, create file and directory ‘ touch,  mkdir ‘ etc.

So these all commands and more in deep i will give you an intro and examples continuously in coming  posts related to LINUX_ADDA.  I hope you all liked it and enjoyed. 

Advertisements

One thought on “Linux Basic Commands for Beginners

  1. Gaurav Srivastava says:

    It is also one of my favorite posts, ! That was awesome experience. when i was learning these things. After sometime, I thought lets do a documentation for “basic Linux commands and how it works. it would be help for new / freshers to learn and execute them from here !!
    🙂 So well known ” u can’t open a book without learning something” so keep learning and learn something from here, after that go for deep study choose books.” 🙂
    Thank you !! !!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s