Examples of using regular expressions for file names

To list all files with a particular extension:

   ls *.fm

This will list all the files in the current directory that have the extension .fm.


To remove a range of files:

   rm prog.?

This removes all the files in the current directory with a single character extension to their name. Files foo.c and foo.o would be removed as would file foo.3.


To copy all the files containing the same pattern:

   cp [pP]art[0-9] ../book

This copies all files whose name contains a pattern that starts with either p or P followed by the letters art and ending in any number from 0 through to 9.

So the file part1 would be copied to the parent directory book as would the file Part7.


[Home] [Search] [Index] This site maintained by umk@astroa.physics.metu.edu.tr