Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find folders and cd into them

Tags:

find

bash

shell

I wanted to write a short script with the following structure:

 find the right folders
 cd into them
 replace an item

So my problem is that I get the right folders from findbut I don't know how to do the action for every line findis giving me. I tried it with a for loop like this:

for item in $(find command)
  do magic for item
done

but the problem is that this command will print the relative pathnames, and if there is a space within my path it will split the path at this point.

I hope you understood my problem and can give me a hint.

like image 916
hGen Avatar asked Sep 03 '25 04:09

hGen


1 Answers

You can run commands with -exec option of find directly:

find . -name some_name -exec your_command {} \;
like image 111
gurel_kaynak Avatar answered Sep 04 '25 23:09

gurel_kaynak