Wildcards in Linux

By | October 25, 2018

Wildcards in Linux

Wild Cards in Linux:

When entering Linux commands or running programs you sometimes want to specify a
range of filenames, that the commands should act upon. An example would be “List
all the files whose name begins with b”. This is done by using “wildcard” characters
in the filenames specified to the command.Each wildcard character matches many alternatives
characters.
* (Steric) Mathes any string of characters.
? (Question Mark) Matches any single character.

 

 

these characters are used in combination with normal characters. So to list all files
whose name begins with “b”.
The following command is used:

 

 

ls b*

what should actually happen when you enter a wildcard filename is that the shell
itself expands the wildcard, turning it into a list of matching filenames, and passes the
whole list to the command. If our directory contained two files beginning with “b”. such as
“bigFile.txt” and “betal.dat”, the above command would be invisibly changed to

ls betal.dat bigfile.txt

 

 

So the ls command shows just those two files. Sine the wildcard expansion is done by the shell, we
can use it for any commands we want to that will handle a list of files. We don’t need
to worry about whether the command itself will understand the wildcard notation.

 

 

For example:

To copy all files from the /home/johnsmith directory into the /home/download


directory, enter the following command:

cp /home/johnsmith/* /home/download

 

This works because the cp command accepts a list of files on the command line and
expects the last one to be a directory name in which to put them.

 

Leave a Reply

Your email address will not be published.