0% found this document useful (0 votes)
12 views15 pages

Using The Shell

Uploaded by

kevinnbot19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views15 pages

Using The Shell

Uploaded by

kevinnbot19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 02

Using the Shell


What is a Command?

● A program executed on the command line.

● Sources of commands include:


○ Internal (built-in shell) commands
○ External commands stored in binary files
○ Aliases
○ Functions
○ Scripts
Aliases
● An alias can be used to map longer commands to shorter key sequences.

● To determine what aliases are set on the current shell use the alias
command.

● New aliases can be created using the following format:

alias name=command

● Aliases created this way only persist while the shell is open. Once the shell
is closed, the new aliases are lost.
Basic Command Syntax
● Command syntax:

command [options…] [arguments…]

● Commands, options and arguments are all case-sensitive.

● To execute a command, the first step is to type the name of the command.
sysadmin@localhost:~$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
Specifying Arguments
● Typically, arguments follow options.

command [options] [arguments]

● Arguments can be file or directory names.

● Some commands require arguments (i.e. the touch and cp commands).

● If an argument contains special (non-alphanumeric) characters, use single


quotes ‘ ’ around the argument.
Specifying Options
● Options can be used with commands to expand or modify the way a command
behaves.

command [options] [arguments]

● Short options are specified with a hyphen - followed by a single character (ie –a).

● Long options for commands are preceded by a double hyphen -- (i.e. --all).

● The lone double hyphen -- option can be used to indicate the end of all options for
the command.
● BSD style options do not use hyphens, just a single character (i.e. a)
Display System Information
● The uname command displays useful system information.

● There are many options available for the uname command. For example:

○ -a, --all – displays all information about the system

○ -s, --kernel-name – displays Kernel name

○ -n, --node-name – displays network node name

○ -r, --kernel-release – displays Kernel release

○ -v, --kernel-version – displays Kernel version


Current Directory
● The pwd command displays the current working directory.

sysadmin@localhost:~$ pwd
/home/sysadmin
sysadmin@localhost:~$ cd Documents/
sysadmin@localhost:~/Documents$ pwd
/home/sysadmin/Documents
Command Information
● The type command displays information about a command type.
sysadmin@localhost:~$ type -a ls
ls is aliased to `ls --color-auto’
ls is /bin/ls

● This command is helpful for getting information about commands,


the –a option will return all locations the files reside on the system.

● The which command searches for the location of a command in the system
by searching the PATH variable.
Command Completion

● The Bash shell provides the ability to complete commands and their
arguments automatically.

● Type a few characters of a command (or its file name argument) and then
press the Tab key twice, this will provide a list of files that match.

sysadmin@localhost:~$ ca
cal capsh cat cautious-launcher
calendar captoinfo catchsegv
caller case catman
Getting Help
● The man command will display documentation for commands:
sysadmin@localhost:~$ man pwd

● You can control the man page display by using movement commands such
as:
o Space bar = Go down one page
o b = Go up one page
o 1G = Go to beginning of man page
o G = Go to end of man page
o h = display help screen
o /term [Enter] = Search for term
Sections Within Man Pages

● The format of each man page is broken into sub-sections:


o NAME = Brief description.

o SYNOPSIS = How command is executed.

o DESCRIPTION = Provides a more detailed description of the command.

o OPTIONS = The options for the command.

o FILES = Which files are used for the command.

o AUTHOR= Provides the name of the person who created the man page and
(sometimes) how to contact the person.
Sections Within Man Pages

o REPORTING BUGS = Provides details on how to report problems with the


command.

o COPYRIGHT = Provides basic copyright information.

o SEE ALSO = Other resources for additional information.


LS(1) BSD General Commands Manual LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is speci-
fied.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..
Output Omitted...

AUTHOR
Written by Richard M. Stallman and David MacKenzie.

REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report ls translation bugs to http://translationproject.org/team/

COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
Full documentation at: <http://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'
Searching by Name or Keyword

● To return all man pages that match a name:


man –f name

sysadmin@localhost:~$ man –f passwd

● To return all man pages that match a keyword:

man –k keyword

sysadmin@localhost:~$ man –k password

You might also like