0% found this document useful (0 votes)
44 views5 pages

Q1 Concept of Shells

The document provides answers to questions about various Linux commands and concepts. It discusses shells as the interface between the user and kernel, the ls command and its options for listing files, using the > and >> operators to redirect command output to files, using the cat command to display or concatenate file contents, piping commands together using the | operator, and various other commands like date, man, help, and printf. It also covers escape sequences, shell variables, and ways to sign off from Linux.

Uploaded by

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

Q1 Concept of Shells

The document provides answers to questions about various Linux commands and concepts. It discusses shells as the interface between the user and kernel, the ls command and its options for listing files, using the > and >> operators to redirect command output to files, using the cat command to display or concatenate file contents, piping commands together using the | operator, and various other commands like date, man, help, and printf. It also covers escape sequences, shell variables, and ways to sign off from Linux.

Uploaded by

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

Q1 Concept of Shells

Ans: - A Shell provides you with an interface to the Unix system. It is an interface between user
and kernel. It gathers input from you and executes programs based on that input. When a
program finishes executing, it displays that program's output.
Shell is an environment in which we can run our commands, programs

Q2. Types of shells


Ans: - In Unix, there are two major types of shells −
 Bourne shell − If you are using a Bourne-type shell, the $ character is the default
prompt.
 C shell − If you are using a C-type shell, the % character is the default prompt.
Q3 ls Command and its options
Ans: - The Ls command is used to get a list of files and directories. Options can be used to get
additional information about the files.
options:
 ls -a: list all files including hidden files. These are files that start with “.”.
 ls -l: shows list in long list format.
 ls -R: list all files recursively, descending down the directory tree from the given path.
 ls -s: list the files along with their size.
 ls -t: sort the list by time of modification, with the newest at the top.
 ls -S: sort the list by size, with the largest at the top.

Q4 > option for directing the output of a command.


Ans: - If the notation > file is appended to any command that normally writes its output to
standard output; the output of that command will be written to file instead of your terminal.
If a command has its output redirected to a file and the file already contains some data, that
data will be lost. Consider the following example −
$ echo line 1 > file
$ cat file
line 1
$
We can use >> operator to append the output in an existing file as follows −
$ echo line 2 >> file
$ cat file
line 1
line 2
$

Q5 introduction and option for Cat command


Ans: - It can be used to display the content of a file, copy content from one file to another,
concatenate the contents of multiple files.
Option
-b Starting at 1, number non-blank output lines.
-n Starting at 1, number all output lines.
cat > file1 - creates new file

Q6 Feeding output of one command to another by pipeline


Ans: - Pipes help you mash-up two or more commands at the same time and run them
consecutively.
you can pipe the output of the 'cat' command to 'less' which will show you only one scroll
length of content at a time.
cat filename | less
ls | wc -l
This will count the lines in the output of ls

Q7 Ways of signing off from Linux


Ans CTRL+D
$ logout
$exit
Q8 Locating commands
Ans: -

Q9 Path and Shell variables


Ans
Q10 Combining the commands
Ans mkdir MyFolder && cd MyFolder
ls ; pwd

Q11 echo and echo -e


Ans: - echo command in linux is used to display line of text/string that are passed as an
argument 
echo * : this command will print all files/folders, similar to ls command 
-n : after output of this command the new command can be entered on the same line
Example :
echo -n "Geeks for Geeks"
The ‘-e‘ option in Linux acts as interpretation of escaped characters that are backslashed.
Using option ‘\n‘ – New line with backspace interpretor ‘-e‘ treats new line from where it is
used.
$ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds"
Tecmint
is
a
community
of
Linux
Nerds
Q12 Cal and Date command with its different options
Ans: - By default, cal command shows current month calendar as output.
cal : Shows current month calendar on the terminal.
cal 2018 : Shows the whole calendar of the year.
cal 08 2000 : Shows calendar of selected month and 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 – shows current date


Date and time of 2 years ago.
Command:
$date --date="2 year ago"
Output:
Sat Aug 10 23:42:15 IST 2020

Q13 man and help commands


Ans: - 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
$ man printf
-w option: This option returns the location in which the manual page of a given command is
present.
Example:
$ man -w ls
Help command
help echo
Display a brief description of the built-in shell command echo.
Q14 Using escape sequence
Ans: - Certain characters are significant to the shell; we have seen, for example, that the use of
double quotes (") characters affect how spaces and TAB characters are treated, for example:
$ echo Hello World
Hello World
$ echo "Hello World"
Hello World
So to display: Hello    "World" ?

$ echo "Hello \"World\""


The first and last " characters wrap the whole string into one parameter passed to echo so that
the spacing between the two words is kept as it is. But the code:
$ echo "Hello " World ""
would be interpreted as three parameters:
1. "Hello   "
2. World
3. ""
So the output would be
Hello World
we lose the quotes. This is because the first and second quotes mark off the Hello and following
spaces; the second argument is an unquoted "World" and the third argument is the empty
string; "".

Q15 Printf in linux


Ans “printf” command in Linux is used to display the given string, number or any other format
specifier on the terminal window.
%s specifier: It is basically a string specifier for string output.
$printf "%s\n" "Hello, World!"
%d specifier: It is an integer specifier for showing the integral values.
$printf "%d\n" "213" "109"

You might also like