I use find to search for files in a directory or its subdirectories.
find . -iname '*.csv'
, and it gives me the following output
./2012/t1.csv
./2012/t2.csv
./2013/t1.csv
Now, I want to check in a script whether the file t1.csv
is in the current folder or in one of the subdirectories. If it's in a subdirectory, my script should descend to that directory.
How can I do that?
dirname ./2012/t1.csv
will give you ./2012. you cannot cd into that folder – Ubuntuser Sep 06 '13 at 04:53#!/bin/bash
for file in
find . -iname *.csv`do` `echo $file` `if [[ ! -f $file ]];then` `echo "Not in this directory, changing directory" `pwd
cd $(dirname $file)
– Ubuntuser Sep 06 '13 at 05:39fi
done
This doesnt change directory