user-avatar
Today is Friday
May 3, 2024

July 4, 2010

Shell script to search for a type of file in a directory recursively and copy it in a destination

by viggy — Categories: shell — Tags: , , Leave a comment

I had used wget and downloaded all the java videos from the java tutorial site( and also all the other files on the website). There were around 20 of them. The problem was that the lectures were each present in a separate folder and I had to traverse to each of them to watch them. So I thought of writing a script which would search the main directory recursively for the lectures and then copy it in a specific folder. Luckily in my case each of the lecture were named differently and hence I didnt have to rename them and there were no issues of file name getting clashed. Below is my shell program:

#!/bin/sh

list=$`find . -type f | grep ".mp4"`
cp $list ./lectures

This would search all the files which had .mp4 in their name and copy them into the folder lectures.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>