> ----> Directs output to a file or device (override if the file exists) < ----> Directs Input from the file or device. >> ----> Appends output or text to a file (creates if the file doesn’t exist) | ----> pipes the output of one command to another. && ----> combines commands . STDIN -- File Description (FD) -- 0 STDOUT -- File Description (FD) -- 1 STDERR -- File Description (FD) -- 2 Examples: 1) $cat file > backup $cat backup ---> To verify 2) $cat > test2 < test2 ---> Input from the test1 $cat test2 ---> To verify 3) $cat test1 test2 test3 2> Error ---> File not exist $ cat Error ---> To verify 4) $cat sample test test3 > out –file 2>> error ---> File not exist $ cat out- file & $ cat Error ----> To verify
EX: $echo “this is some sample text”
$echo “this is some sample text” > file_example $cat file_example To verify
Syn: cut [option] file --- d Specifies a delimiter --- f displays a particular field --- c displays a character.
$cut –d “” -f3 file_example
$cut f3,4 file_example
$cut - c 1-5 file_example
$ paste states capitals AP HYD MP BOPAL KN BANGLORE
$ paste - d “ : ”States capitals AP : HYD MP : Bopal KN : Bangalore $Paste --d “ : ” states capitals > example
Syn: WC [options] file --- l lines --- w words --- c characters $WC Example Displays lines words and characters $WC - l Example only lines $WC - w Example only words.
$diff file1 file2
$ cmp file1 file2 Note: If files are same it doesn’t return any output otherwise it displays line numbers and character position
$tr “aeiou” “AEIOU” <sample $tr “a-z” “A-Z” <sample Translate lower to upper. $ tr “A-Z” “a-z” < sample Upper to lower $tr - s “ “ <sample Squeeze $tr -d “aeiou” <sample To delete aeiou $tr “,” “\t” < sample Replaced with tab space.
$a spell check sample $a spell check test
$ head sample $ head -5 sample Top 5 lines
$ tail sample $ tail -5 sample last 5 lines $tail - f sample file is open continuously
$ ls - l/ wc – l $cat example / cut –d “ “ - f3 file _ example $ cat example / head -20
$ echo “ this is text file” > file_example && cut –f3 example $ cat file_example To verify $ echo “ My original text: >> file _example && cat file_example
$ more example
$ Less example Options: f ----> forward direction B ----> Backward direction V ----> vi editor mode q ----> To quit à Tee: It is used to write the data into the files as well as on the screen. $cat sample / tee file1 file2 file3 $cat file1 To verify $cat file 2
Syn: Sort [options} FILE --- R ----> sorts in reverse order --- B ----> Ignores leading blanks --- n ----> compares according to numerical storing value
|
$ sort example $ sort –r example Reverse order $ sort –n example Display numeric $ sort –u example unique lines $ sort --f Example Ignores case
Inclined to build a profession as Linux Developer? Then here is the blog post on Linux Training Online.
$ uniq example $ Uniq –u Example Displays non duplicated lines $ Uniq –d Example Displays only duplicated lines $ Uniq file_ Example > uniq_file && cat uniq – file
Syn: sed “s/old string name/new string name/g” <filename> S ---> substitution G à global occurrence in every line. $sed “s/unix/linux/g” sample $sed “s/unix/linux/gi” sample Ignore case $sed “s/unix/linux/” sample $sed “s/˄unix/linux/gi sample $sed “s/unix//gi sample Delete a word from a file $sed –e “s/unix/sas/gi” -e “s/linux/dba/gi” sample $sed –n “2p” sample To print 2nd row $sed –n “3,5p” sample To print 3rd, 4th, 5th rows $sed –n “IP >$p” sample point 1st and last rows $ sed ‘3d’ sample Delete 3rd row $sed ‘2,5d’ sample Delete 2 to 5 lines $ sed ‘2,5 w file’ sample It copies 2nd to 5th rows from sample file to file $ sed ‘=’ sample To get line numbers.
Syn: grep [options] PATTERN FILE (S) $ grep root sample $ grep root sample example backup $grep root * search all files in a current directory $grep --i root sample Ignore case $grep --c root sample COUNTS NO. OF LINES $grep –n root sample print the lines along with line no’s $grep –l root sample list file names only he given pattern $grep –r root * search the pattern recursively $grep –v root sample prints non matching lines $grep –o root sample prints only the given pattern. $grep root sample -- color displays output in color $grep “it technology” sample $grep “exam*” sample Prints start with exam pattern. $grep “b[aeiou] ll” sample o/p: ball bell bill boll $grep “b..d” sample o/p: band book ba#d bad-d Note: “.” & “*” are wild card characters, it matcher any single character. $grep c[on] example $grep [0-9] example Word pattern: \< /> Þ word boundary \< Þ starting of the word \< Þ Ending of the word $grep “/<root/>” sample $grep “\,root” sample o/p: rootP Root 123O $grep “root/>” sample o/p: rootP root123P xroot123O $ grep “\<[0-9][0-9][0-9][0-9]>” sample 1025P 112O 1356P
You liked the article?
Like : 0
Vote for difficulty
Current difficulty (Avg): Medium
1/15
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.
Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox