0% found this document useful (0 votes)
7 views34 pages

Linux Commands

Uploaded by

Abhishek Bhalla
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)
7 views34 pages

Linux Commands

Uploaded by

Abhishek Bhalla
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

LINUX

BASIC COMMANDS
man
◦ man command in Linux is used to display the user manual of any command that we
can run on the terminal.
◦ It provides a detailed view of the command which includes –
NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES,
VERSIONS, EXAMPLES, AUTHORS and SEE ALSO.
info
◦ Info command reads documentation in the info format. It will give detailed
information for a command when compared with the man page. The pages
are made using the texinfo tools because of which it can link with other pages,
create menus and easy navigation.
help
◦ The help command provides information on built-in commands. Built-in commands
are any programs bundled with your version of the bash shell. For a complete list of
the built-in commands available to you, simply enter 'help' at the terminal prompt.

◦ The pattern specified in the syntax above refers to the command about which you
would like to know and if it is matched with any shell built-in command then help give
details about it and if it is not matched then help prints the list of help topics for your
convenience. And the d, m and s here are options that you can use with
the help command
◦ Options for help command
-d option : It is used when you just want to get an overview about any shell built-in
command i.e it only gives short description.
-m option : It displays usage in pseudo-manpage format.
-s option : It just displays only a short usage synopsis for each topic matching.
whatis
◦ whatis command in Linux is used to get a one-line manual page description. In Linux,
each manual page has some sort of description within it. So, this command search for
the manual pages names and show the manual page description of the specified
filename or argument.

◦ [option] = replace it with the desired option of yours.


◦ [command_name] = replace it with the desired command you want.
apropos
◦ Linux/Unix comes with a huge number of commands and thus it become quite difficult
sometimes to remember each and every command. apropos command becomes
useful in such cases. apropos command helps the user when they don’t remember the
exact command but knows a few keywords related to the command that define its
uses or functionality. It searches the Linux man page with the help of the keyword
provided by the user to find the command and its functions.
◦ Example 1: Suppose you don’t know how to compress a file then you could type the
following command in terminal and it will show all the related command and its short
description or functionality.

◦ After executing the above command you will observe a bunch of commands is listed on
the terminal that deals with not only how to compress a file but also how to expand a
compressed file, search a compressed file, comparing a compressed file etc.

◦ NOTE: apropos also support multiple keywords if given as an argument i.e. we can also
provide more than one keyword for a better search. Thus, if two keywords are provided
the apropos command will display all the command’s list which contains either the first
keyword in its man page description or the second keyword.
whoami
◦ It displays the username of the current user when this command is invoked.
◦ SYNTAX: $ whoami
◦ 1. –help Option :
It gives the help message and exit.
Syntax : $whoami –-help
◦ 2. –version Option :
It gives the version information and exit.
Syntax: $whoami -- version
who
◦ who command is used to find out the following information :
1. Time of last system boot
2. Current run level of the system
3. List of logged in users and more.
◦ Description : The who command is used to get information about currently logged
in user on to system.
SYNTAX: $ who
◦ The who command displays the following information for each user currently
logged in to the system if no option is provided :
◦ Login name of the users
◦ Terminal line numbers
◦ Login time of the users in to system
◦ Remote host name of the user
uname
◦ It displays certain features of the operating system running on your machine.
◦ By default it simply displays the name of the operating system /system information.
◦ SYNTAX: $ uname
◦ Options:
◦ -r command-It displays the version of the operating system.
◦ -n command- It displays the hostname operating system running on machine.
tty(teletype)
◦ It prints the filename of the terminal connected to standard input.
◦ SYNTAX: $ tty
/dev/pts/10
Here, the terminal filename is 10(a file named 10) resident in pts directory.This directory in
turn is under the /dev directory.
hostname
◦ show or set the system's host name
◦ hostname command in Linux is used to obtain the DNS (Domain Name System) name and set
the system’s hostname or NIS (Network Information System) domain name. A hostname is a
name given to a computer and attached to the network. Its main purpose is to uniquely
identify over a network.
Syntax:
hostname -[option] [file]
`-a` Option in `hostname` command in Linux
Display all aliases of the host.
Syntax:
$ hostname -a
`-i` Option in `hostname` command in Linux
Display the IP address of the host
Syntax:
$ hostname -i
-I` Option in `hostname` command in Linux
This option is used to get all IP (network) addresses. The option doesn’t depend on
resolvability of hostname.
Syntax:
$ hostname -I
 How to set hostname in Linux
Set the hostname of the system temporarily.
Syntax:
$ sudo hostname NEW_HOSTNAME
Replace NEW_HOSTNAME with the new hostname you want to set.
cal-The Calender
◦ cal command is a calendar command in Linux which is used to see the calendar of a
specific month or a whole year.
◦ Syntax:
$cal [ [ month ] year]
◦ The rectangular bracket means it is optional, so if used without an option, it will display a
calendar of the current month and year.
◦ cal : Shows current month calendar on the terminal with the current date highlighted.
◦ cal -y : Shows the calendar of the complete current year with the current date
highlighted.
◦ cal 08 2000 : Shows calendar of selected month and year.
◦ cal 2018 : Shows the whole calendar of the year.
◦ cal 2018 | more : But year may not be visible in the same screen use more with cal use
spacebar to scroll down.
◦ cal -3 : Shows calendar of previous, current and next month
date
◦ Displays current date and time.
◦ date command is used to display the system date and time. date command is also used
to set date and time of the system. By default the date command displays the date in
the time zone on which unix/linux operating system is configured. You must be the super-
user (root) to change the date and time.
◦ Syntax: $date
◦ $date +%m (to print month)
◦ $date +%h (to print month name)
◦ $date +”%h %m” (to combine)
◦ d-Day of the month(1-31)
◦ y-the last two digits of the year
◦ H,M and S-The hour, minute and second respectively
◦ D-the date in the format mm/dd/yy.
◦ T-the time in the format hh:mm:ss
echo
The echo command in Linux is a built-in command that allows users to
display lines of text or strings that are passed as arguments. It is commonly
used in shell scripts and batch files to output status text to the screen or a
file.
Syntax :
$ echo [option] [string]

Here,
[options] = The various options available for modifying the behavior of the
`echo` command
[string] = It is the string that we want to display.
EXAMPLE
$ echo “hello world”
hello world
◦ $ echo “enter filename: \c”
Enter filename: $_ (prompt and cursor in same line)

This is how echo is used in a shell script to accept input from the terminal.
\t- A tab which pushes text to the right by eight character position.
\n-A newline which creates the effect of pressing[Enter].
]

printf
◦ “printf” command in Linux is used to display the given string, number or any other
format specifier on the terminal window.
◦ It works the same way as “printf” works in programming languages like C.
◦ Use printf to generate formatted output.
◦ Printf does not provide a newline unless \n is used explicitly.
◦ The command in its simplest form can be used in the same way as echo:
◦ $ printf [-v var] format [arguments]
◦ Note: printf can have format specifiers, escape sequences or ordinary characters.
◦ Format Specifiers: The most commonly used printf specifiers are %s, %b, %d, %x and %f.
◦ EXAMPLES:
◦ %s specifier: It is basically a string specifier for string output.
◦ %b specifier: It is same as string specifier but it allows us to interpret escape
sequences with an argument.
◦ %d specifier: It is an integer specifier for showing the integral values.
◦ %f specifier: It is used for output of floating point values.
◦ %x specifier: It is used for output of lowercase hexadecimal values for integers and
for padding the output.
bc: The Calculator
◦ bc command is used for command line calculator.
◦ It is similar to basic calculator by using which we can do basic mathematical
calculations.
$ bc
12 + 5
17
[Ctrl+d]
$_

$ bc
12*12 ;2+32
144
34

9/5
1 (decimal portion truncated)
scale=2
17/7
2.42

ibase=2
101
5

obase=2
5
101
pwd
◦ pwd stands for Print Working Directory.
◦ It prints the path of the working directory, starting from the root.(Absolute Pathname)
$ pwd
/home/abc
cd
◦ Changing the current directory
$ pwd
/home/abc
$ cd program1
$ pwd
/home/abc/program1
cd command with no arguments
$ pwd
/home/abc/program1
$ cd
$ pwd
/home/abc
◦ ~` this argument is used in `cd` command to change the directory to the home
directory from any location in Linux System.
$ pwd
/home/abc/program1/p1
$ cd ~
$ pwd
/home/abc
◦ `..` this as an argument in `cd` command which is used to move to the parent directory of
current directory, or the directory one level up from the current directory. “..” represents
parent directory.
$ pwd
/home/abc/program1/p1
$ cd ..
$ pwd
/home/abc/program1
◦ NOTE: For more information refer book :Sumitabha Das,
“Unix Concepts and Application”, TMH

You might also like