Skip to content

Instantly share code, notes, and snippets.

@median-man
Last active July 28, 2022 18:53
Show Gist options
  • Save median-man/fad1b0abb0d29a26812c47768334e90d to your computer and use it in GitHub Desktop.
Save median-man/fad1b0abb0d29a26812c47768334e90d to your computer and use it in GitHub Desktop.
A collection of useful command line snippets for managing the bootcamp repos.

Find Folders and Run a command from each folder

The following command searching for folders named client within the pwd traversing to a max depth of 2. Then it executes npm i react-scripts@latest in each found directory.

find . -maxdepth 2 -type d -name client -exec bash -c "cd '{}' && npm i react-scripts@latest" \;

Use the following command to print the directories before excuting a command with the following:

find . -maxdepth 2 -type d -name client -exec bash -c "cd '{}' && pwd" \;

Find and replace text in files recursively.

The following command finds all files ending in .md recursively. If @ 2021 is found, it is replaced with @ 2022.

find . -type f -name "*.md" -exec sed -i'' -e 's/© 2021/© 2022/g' {} +

Find and rename files

Finds all files in working directory and renames them.

find . -print0 | while read -d $'\0' file; do mv "$file" "${file/-es-LA}"; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment