Skip to content

Instantly share code, notes, and snippets.

@tannerwelsh
Created September 4, 2012 22:25
Show Gist options
  • Select an option

  • Save tannerwelsh/3627406 to your computer and use it in GitHub Desktop.

Select an option

Save tannerwelsh/3627406 to your computer and use it in GitHub Desktop.
Touch a new file in a directory and all of its subdirectories
#!/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