I have thousands of html file in a directory. I wanna extract files that contain Chennai in the file name and put it into another folder. I am sure it is possible. I am not close enough to copy the files to another folder.
Asked
Active
Viewed 85 times
2 Answers
1
Use globbing:
mv *Chennai* target/
If the file names might start with a dot, use
mv .*Chennai* *Chennai* target/

choroba
- 231,213
- 25
- 204
- 289
-
`cp` makes copies, `mv` moves. In this case, you can use the one you like more with the same syntax. – choroba Sep 19 '13 at 07:05
1
Try:
find directory_with_htmls -type f -name "*Chennai*.html" -exec cp {} some_other_folder \;
This would copy html files in the directory_with_htmls
directory containing Chennai
in the name to the directory some_other_folder
.

devnull
- 118,548
- 33
- 236
- 227
-
-
1Yes. In order to make it case-insensitive, say `-iname` instead of `-name` in the above command line. – devnull Sep 19 '13 at 07:08
-
-
It quiet dint work. Only one file got copied out of thousand. File names are quiet improper. 3BHK_flats_inCoimbatore.html__201308260608_ , buy_land_incoimbatore.html__201308190443_, Residential_Land_inCoimbatore.html__201308040550_ and so on – Venkateshwaran Selvaraj Sep 19 '13 at 07:19
-
Your file names don't end in HTML which is contrary to what you'd said. Remove `.html` from the pattern in the command. Try `find directory_with_htmls -type f -iname "*Chennai*" -exec cp {} some_other_folder \;` – devnull Sep 19 '13 at 07:25
-
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/37632/discussion-between-venky-and-devnull) – Venkateshwaran Selvaraj Sep 19 '13 at 07:29