0% found this document useful (0 votes)
51 views

Linux Cmds

This document provides information about various Linux commands including wc, uname, and tty. It also covers pattern matching using wildcards, escaping special characters, quoting, and command substitution. Some key points include: - The wc command is used to count lines, words, and characters in a file. - The uname command displays information about the operating system. - The tty command displays the name of the terminal. - Wildcards like *, ?, [], {}, {pattern1,pattern2} are used for pattern matching files. - Escaping with \ or quoting avoids special meaning of meta characters. - Command substitution with ` ` executes a command and substitutes its output.
Copyright
© Attribution Non-Commercial (BY-NC)
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)
51 views

Linux Cmds

This document provides information about various Linux commands including wc, uname, and tty. It also covers pattern matching using wildcards, escaping special characters, quoting, and command substitution. Some key points include: - The wc command is used to count lines, words, and characters in a file. - The uname command displays information about the operating system. - The tty command displays the name of the terminal. - Wildcards like *, ?, [], {}, {pattern1,pattern2} are used for pattern matching files. - Escaping with \ or quoting avoids special meaning of meta characters. - Command substitution with ` ` executes a command and substitutes its output.
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 3

PAGE NO.

:
DATE: MAR. 10,2010

wc command
This command is used to count the no. of words, letters and lines etc.
Syntex:
$ wc filename 
( It displays no. of lines, words and characters with filename )
$ wc –l filename 
( Displays no. of lines with filename )
$ wc –w filename 
( Displays no. of words with filename )
$ wc –c filename 
( Displays no. of characters with filename )

uname command
This command is used to know about the operating system’s name, version etc.
Syntex:
$ uname 
( Displays name of O.S.)
$ uname –r 
( Displays version of O.S.)
$ uname –n 
( Displays hostname )

tty command
It displays the name of terminal with absolute path.
Syntex:
$ tty 

e.g. $ command >terminal name 


( It redirects the output of one terminal to another terminal )

Pattern matching with wildcard(Special meaning characters)

1. * ( Any no. of characters )


2. ? ( Single character )
3. [abc] ( Any one character among a,b and c )
4. [!abc] ( Any one character except a,b and c )
5. [0-9] ( Any numeric character )
6. [!0-9] ( Any non numeric character )
7. { pattern1, pattern2, ………..} ( All the patterns written in the brasis )
8. [a-z A-Z] ( All the pattern from a-z and A-Z )
Que. Write a command to search all ‘c’ and ‘java’ files.
Ans. 1. $ ls *.c 
$ ls *.java 
2. $ ls *.c *.java 
3. $ ls *.{c,java} 

Avoiding special meaning of meta characters

Escaping and Quoting are two techniques which are used to avoid the special
meaning of meta characters.
1. Escaping (\)
In this technique we place \ (back slash) before the meta character. It escapes the
effect of single character after it.
e.g. $ echo \* 
( In this case the output is * )

PAGE NO.:
DATE: MAR. 10,2010

2. Quoting
In this technique we use quoting to avoid special meaning of meta characters.
e.g. 1. $ echo kuldeep mittal 
( output is kuldeep mittal )
2. $ echo “kuldeep mittal” 
(In this case output is kuldeep mittal )
3. $ a=5 
$ echo “value of a is $a” 
( In this case output is value of a is 5 )
4. $ a=5 
$ echo ‘value of a is $a’ 
( In this case output is value of a is $a )

Command Substitution

` ( Back quote is used for command substitution )


e.g. 1. $ a=pwd 
$ echo $a 
( In this case output is pwd )
2. $ a=`pwd` 
$ echo $a 
( In this case the output is the path of present working directory )

Que1. Differentiate ls, ls * and echo *.


Ans. ls displays all the files and directories present in the current directory.
ls * displays all the files and directories which are present in current directory
and sub directory also.
echo * functions same as ls. Means it displays all the files and directories
present in the current directory.

Que2. Differentiate between ls *. and ls .* commands.


Ans. ls *. Commands displays all the files which name ends with dot(.)
While ls .* displays all the hidden files.

Que3. Create a file with name


(i) [A-Z]????*
(ii) *[0-9]*
(iii) *[!0-9]
(iv) *.[!s][!h]
Ans. (i) $ cat >\[A-Z]????* 
(ii) $ cat >\*[0-9]* 
(iii) $ cat >\*[!0-9] 
(iv) $ cat >\*.[!s][!h] 
Que4. Write a command to match all filenames that begin with dot (.) and
ending with .sap
Ans. $ ls .*.sap 
Que5. Write a command to match all filenames that containing 2004 as an
embedded string except beginning and end.
Ans. $ ls *?2004?* 

You might also like