I wanted to copy a file from one location to multiple folders. We'll have to copy multiple times if we do it manally. Lets see how to use shell script to copy to every folder in one go using shell scripting.
main parts we need to do.
1. get all directories.
find . -maxdepth 1 -type d
2. loop through every directory name, returned from 1, and copy file to each folder.
using foreach loop in s shell (.csh)
> foreach dir ( ` find . -maxdepth 1 -type d` )
> foreach? cp ~/Scripts/convert.py $dir
> foreach? end
using for loop in bash shell (.sh)
Other commands to get all directory names
- ls -d */
- ls -l | grep `^d'
No comments:
Post a Comment