Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for d in [0-9][0-9][0-9]
- do
- ( cd "$d" && your-command-here )
- done
- find . -maxdepth 1 -type d ( ! -name . ) -exec bash -c "cd '{}' && pwd" ;
- find . -type d -execdir realpath "{}" ';'
- find . -type d -execdir sh -c 'printf "%s/%sn" "$PWD" "$0"' {} ;
- find . -name .git -type d -execdir git pull -v ';'
- find . -type d -exec sh -c 'cd -P -- "{}" && pwd -P' ;
- find . -type d -print0 | xargs -0 -L1 sh -c 'cd "$0" && pwd && echo Do stuff'
- find . -type d -print0 | while IFS= read -r -d '' file; do
- # ...
- done
- dirs=($(find . -type d))
- for dir in "${dirs[@]}"; do
- cd "$dir"
- echo $PWD
- done
- mapfile -t -d '' dirs < <(find . -type d -print0)
- ls -d */ | awk '{print $NF}' | xargs -n1 sh -c 'cd $0 && pwd && echo Do stuff'
- for dir in `ls $YOUR_TOP_LEVEL_FOLDER`;
- do
- for subdir in `ls $YOUR_TOP_LEVEL_FOLDER/$dir`;
- do
- $(PLAY AS MUCH AS YOU WANT);
- done
- done
- for dir in PARENT/*
- do
- test -d "$dir" || continue
- # Do something with $dir...
- done
- #!/bin/bash
- #Use set -x if you want to echo each command while getting executed
- #set -x
- #Save current directory so we can restore it later
- cur=$PWD
- #Save command line arguments so functions can access it
- args=("$@")
- #Put your code in this function
- #To access command line arguments use syntax ${args[1]} etc
- function dir_command {
- #This example command implements doing git status for folder
- cd $1
- echo "$(tput setaf 2)$1$(tput sgr 0)"
- git tag -a ${args[0]} -m "${args[1]}"
- git push --tags
- cd ..
- }
- #This loop will go to each immediate child and execute dir_command
- find . -maxdepth 1 -type d ( ! -name . ) | while read dir; do
- dir_command "$dir/"
- done
- #This example loop only loops through give set of folders
- declare -a dirs=("dir1" "dir2" "dir3")
- for dir in "${dirs[@]}"; do
- dir_command "$dir/"
- done
- #Restore the folder
- cd "$cur"
- cd parent
- find . -type d | while read d; do
- ls $d/
- done
- find .
- find . | xargs 'command here'
- for p in [0-9][0-9][0-9];do
- (
- cd $p
- for f in [0-9][0-9][0-9][0-9]*.txt;do
- ls $f; # Your operands
- done
- )
- done
- ls -d */ | xargs -I {} bash -c "cd '{}' && pwd"
Add Comment
Please, Sign In to add comment