How do I execute a command where a file is found?
Consider I've an directory named
testdir that contains the following:
$ ls -R testdir/ testdir/: dir1 dir2 dir3 dir4 dir5 testdir/dir1: doc1.pdf testdir/dir2: file1.txt testdir/dir3: doc2.pdf testdir/dir4: file2.txt testdir/dir5: doc5.pdf
Now I want to perform an action (execute a command) where
find finds a certain file/file type. For example let me find
$ find . -name '*.pdf' ./testdir/dir3/doc2.pdf ./testdir/dir5/doc5.pdf ./testdir/dir1/doc1.pdf
Now suppose I want to execute a command (for example say
touch file) where the above command finds file(s). In other words, I want to create a file named
file in each directory where at least one
$ ls -R testdir/ testdir/: dir1 dir2 dir3 dir4 dir5 testdir/dir1: doc1.pdf file testdir/dir2: file1.txt testdir/dir3: doc2.pdf file testdir/dir4: file2.txt testdir/dir5: doc5.pdf file
How do I accomplish such a work?
May be for every time file found,
cd to where file exist and perform a command recursively.
I know that
find has awesome feature:
-exec but I can't get it to work.
This is only an example for getting an idea about what I want to do. Broadly: How to execute an command where file(s) are found (by