Command | Options | Description |
* | Matches any number of character including NONE. * does not match all files beginning with dot <.>. | |
ls -l chap* | Matches all the files which starts with chap. | |
ls -x chap* | Matches all the files which starts with chap and prints in multi column way. | |
| ||
? | Matches single character. | |
ls -l chap? | Matches all the files with only 5 character name and should start with chap. | |
| ||
[ ijk ] | Matches single character either i or j or k. | |
[ !ijk ] | Matches single character that is not i or j or k | |
[ x - z ] | Matches single character that is not within the ASCII range of character x and z. | |
[ ! x - z ] | Matches single character that is not within the ASCII range of character x and z | |
ls -l chap0[1 - 4] | Range specification is also available. | |
ls -l [ a – z A-Z] | Matches all file names beginning with alphabet irrespective of case. | |
ls -l chap[!0 - 9] | Matches all file names beginning with alphabet chap and not ending with any number. | |
ls *.ist | Print all the files which end with ist extensions. | |
cp chap?? abc | Copy all files starts with chap to abc directory. | |
cmp chap[12] | Compares file chap1 and chap2. | |
mv * ../bin | Moves all the files to bin directory. | |
cat chap[!0 - 9] | Concatenates all the files beginning with chap and not ending with number. | |
ls -l * | * does not match all files beginning with dot <.>. | |
ls -l .???* | The above problem can be solved with specifying first few character using meta character <?> explicitly. | |
Escaping Backslash ( \ ) | Playing with file names which uses meta character in their file name. | |
ls - l chap* | Print all files whose names start with chap but not the one whose name is chap*. | |
ls - l chap\* | The above problem can be solved by escaping the special character. | |
Pipe | | To pass the standard output of one command as the standard input to another. | |
who | wc -l | Output of who command <three users> passed as input to wc which count the number of lines present. | |
| ||
Tee | who | tee users list | Tee saves the output of who command in user list as well as display it also. |
| ||
Shell Variable | Shell variables are initialized to null value < by default > so it returns null. All words starts with $ are considered as variable unless single quoted or escaped. | |
a=ab, b=cd, z=$a$b. echo $z | shell concatenate two variable. | |
echo '$10' eg: $10 | All words starts with $ are considered as variable unless single quoted or escaped. | |
echo "$10" eg: 0 | Shell is looking for $1 variable which is undefined so passes null for this. $1 is part of positional parameter. |
Friday
Pattern Matching
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment