Created
September 4, 2012 22:25
-
-
Save tannerwelsh/3627406 to your computer and use it in GitHub Desktop.
Touch a new file in a directory and all of its subdirectories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # UPDATE: This is a waste of code. This script can | |
| # be executed in a single line: | |
| # find * -type d -exec touch '{}/.gitkeep' \; | |
| # Execution takes two arguments: | |
| # 1: Name of directory to traverse | |
| # 2: Name of file to create in each subdirectory | |
| # | |
| # Example usage: | |
| # $ bash recursive_touch.sh MyProject .gitkeep | |
| SOURCE_DIR=$1 | |
| FILE=$2 | |
| recursive_touch() { | |
| for dir in * | |
| do | |
| if [ -d $dir ] | |
| then | |
| cd $dir; recursive_touch | |
| fi | |
| touch $FILE | |
| done | |
| } | |
| cd $SOURCE_DIR; recursive_touch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment