Thursday, August 27, 2015

String search and matching pattern


Wildcard to match any character string
$ [cmd] ab*

Wildcard to match any single character
$ ls m?n

Wildcard to match any character in a set of characters
[chars]

Not wildcard
!

Wildcard to match any character not in a set of characters
[!chars]

Wildcard to match the alphanumeric character group
[:alnum:]

Wildcard to match the numerical character group
[:digit:]

Wildcard to match the uppercase alphanumeric character group
[:upper:]

Wildcard to match the lowercase alphanumeric character group
[:lower:]

Pathname expansion using echo command
To print output all filenames and directories in a directory
$ echo *

To output everything beginning with a and ending with z in a directory
$ echo a*z

To output everything beginning with a capitol letter in a directory $ echo [[:upper:]]*

To output all directories containg a subdirectory /tmp/ in the /usr/ directory
$ echo /usr/*/tmp/

Tilde expansion using echo command
T o output home directory of current user
$ echo ~

To output home director of [user] echo ~[user]

Arithmetic expansion of echo command
To output value of expression 5 + 5 = echo $((5+5))

The basic syntax echo $(([numeral] [operand] [numeral]))

To output value of expression (5 * 2) 3 = echo $(((5*2)3))

Arithmetic operand for
remainder %
squared **
divided /

Brace expansion of echo comand
To output " count_1 count_2 count_3 count_4 count_5 " echo count_{1..5}

To output " Z Y X W V U T S R " echo {Z..R}

To output " aA1b aA2b aB1b aB2b " echo a{A{1,2},B{1,2}}b

Brace expansion of mkdir command to output directorys for every month in 2011-2012 in the format of YYYY_MM mkdir {2011..2012}_0{1..9} {2011..2012}_{10..12}

No comments:

Post a Comment