Sei sulla pagina 1di 6

SHELL: Its a program used to interpret and manage commands.

In another word.The shell is a command language interpreter.

What does shell do:

Create executable script files

Run programs

Work with file system

Compile computer code

Mange computer

Note: BASH(Bourne Again Shell) derived from Bourne shell(Stephen Bourne).

Few other shells: ksh--korn shell in unix

Csh--C shell

Tcsh ----improved csh

Ash--- bourne shell look-alike.

3 ways to get to a Shell Interface:

1. SHELL prompt

2. Terminal Window

3. Virtual Console.

Know about Shell:

>> “who am i” commands returns user name,terminal name with System boot time.

[ahmad@localhost ~]$ who am i

ahmad pts/0 2018-02-18 18:04 (:0)

>>whoami :returns username only

[ahmad@localhost ~]$ whoami

ahmad
>>who : Gives info about users who are currently logged in.

[ahmad@localhost ~]$ who

ahmad :0 2018-02-18 17:16 (:0)

ahmad pts/0 2018-02-18 18:04 (:0)

ahmad tty2 2018-02-18 18:16

>> who -uH : -u adds info about idle time pid, -h is for header.

[ahmad@localhost ~]$ who -uH

NAME LINE TIME IDLE PID COMMENT

ahmad :0 2018-02-18 17:16 ? 1870 (:0)

ahmad pts/0 2018-02-18 18:39 old 7455 (:0)

ahmad tty2 2018-02-18 18:16 old 6524

>> grep username /etc/passwd : It shows definition of user account in /etc/passwd file.

[ahmad@localhost ~]$ grep ahmad /etc/passwd

ahmad:x:1000:1000: ahmad:/home/ahmad:/bin/bash

/bin/bash :It refers BASH is your default shell.

>>exit “ This command is used to exit feom shell.

>> man bash : If you want to read more about this shell.

Run few Commands:

>> date

[ahmad@localhost ~]$ date

Sun Feb 18 18:24:44 IST 2018

>>pwd :return current working directory.

[ahmad@localhost Pictures]$ pwd

/home/ahmad/Pictures

>>hostname : returns computer name.


[ahmad@localhost Pictures]$ hostname

Localhost.localdomain

>>ls

[ahmad@localhost ~]$ ls

Desktop Downloads epel-release-latest-7.noarch.rpm Pictures Templates


Documents Dropbox Music Public Videos

Command Syntax:

>> command [option] [argument]

Eg. [ahmad@localhost Desktop]$ ls -a

. .. a.out Storage

Note: single letter options can be grouped together with Hyphen(-).

>>ls -lat : long listing -l, show hidden dot files -a,list by times -t.

[ahmad@localhost Desktop]$ ls -lat

total 24

drwx------. 28 ahmad ahmad 4096 Feb 18 18:27 ..

drwxr-xr-x. 3 ahmad ahmad 34 Feb 16 13:12 .

drwxrwxr-x. 10 ahmad ahmad 4096 Feb 16 13:12 Storage

-rwxrwxr-x. 1 ahmad ahmad 14136 Feb 11 17:13 a.out

>>to tell command to use whole word as an option use --(double hyphen)

Eg. ls --help

>>arguments are extra piece of info.

Eg. File,directory,username etc

>> eg of “ Command Option Argument”


[ahmad@localhost ~]$ ls --hide=Desktop

Documents Dropbox Music Public Videos

Downloads epel-release-latest-7.noarch.rpm Pictures Templates

>>eg of single letter options followed by an argument.

[ahmad@localhost ~]$ tar -cvf Backup.tar /home/ahmad/Pictures/

Create :c File :f verbose message: v

>>To navigate in terminal.

[ahmad@localhost ~]$ less /home/ahmad/Pictures/

>> in this command we took output of “locate ls “ as input of “less “ by using Pipe[|].

[ahmad@localhost ~]$ locate ls | less

>>It shows type of system we are running.

[ahmad@localhost ~]$ uname

Linux

>>uname -a : //read manual, uname --help

[ahmad@localhost ~]$ uname -a

Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64
x86_64 x86_64 GNU/Linux

>>date command with various options.

[ahmad@localhost ~]$ date +'%A,%B %d, %Y'

Sunday,February 18, 2018

[ahmad@localhost ~]$ date +'%d/%m/%y'

18/02/18
>> id command is used to get info about identity details.

[ahmad@localhost ~]$ id

uid=1000(ahmad) gid=1000(ahmad) groups=1000(ahmad),10(wheel)


context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

Locating Commands:

>>to run command by typing full path.

[ahmad@localhost ~]$ /bin/date

Sun Feb 18 19:41:01 IST 2018

Or add the the commands directories in SHELL’s PATH environment variable to run directly.

>>to see current shell path: echo $PATH

[ahmad@localhost ~]$ echo $PATH

/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/ahmad/.local/bin:/home/ahm
ad/bin

NOTE:Directories in PATH list is separated by COLON(:).

NOTE: Most user commands are stored in the

/bin, /usr/bin, or /usr/local/bin directories. The /sbin and /usr/sbin directories

contain administrative commands.

TIP:

If you want to add your own commands or shell scripts, place them in the bin directory in
your home directory (such

as /home/ahmad/bin for the user named ahmad). This directory is automatically added to your
path in some Linux systems, although you may need to create that directory or add it to your
PATH on other Linux systems. So, as long as you add the command to your bin with execute
permission, you can begin using it by simply typing the command name at your shell prompt. To
make commands available to all users, add them to /usr/local/bin.

Note:
The path directory order is important. Directories are checked from left to right. So, in this
example, if there is a command called foo located in both the /bin and /usr/bin directories, the
one in /bin is executed. To have the other foo command run, you either type the full path to the
command or change your PATH variable. (Changing your PATH and adding directories to it are
described later in this chapter.)

>> Order in which the shell checks for the commands you type:

1. Aliases: Used to define short name for a long command.

2.Shell Reserved word: like, do,while,case,else etc.

3. Function :

Potrebbero piacerti anche