Guest User

Untitled

a guest
Jan 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. for d in [0-9][0-9][0-9]
  2. do
  3. ( cd "$d" && your-command-here )
  4. done
  5.  
  6. find . -maxdepth 1 -type d ( ! -name . ) -exec bash -c "cd '{}' && pwd" ;
  7.  
  8. find . -type d -execdir realpath "{}" ';'
  9.  
  10. find . -type d -execdir sh -c 'printf "%s/%sn" "$PWD" "$0"' {} ;
  11.  
  12. find . -name .git -type d -execdir git pull -v ';'
  13.  
  14. find . -type d -exec sh -c 'cd -P -- "{}" && pwd -P' ;
  15.  
  16. find . -type d -print0 | xargs -0 -L1 sh -c 'cd "$0" && pwd && echo Do stuff'
  17.  
  18. find . -type d -print0 | while IFS= read -r -d '' file; do
  19. # ...
  20. done
  21.  
  22. dirs=($(find . -type d))
  23. for dir in "${dirs[@]}"; do
  24. cd "$dir"
  25. echo $PWD
  26. done
  27.  
  28. mapfile -t -d '' dirs < <(find . -type d -print0)
  29.  
  30. ls -d */ | awk '{print $NF}' | xargs -n1 sh -c 'cd $0 && pwd && echo Do stuff'
  31.  
  32. for dir in `ls $YOUR_TOP_LEVEL_FOLDER`;
  33. do
  34. for subdir in `ls $YOUR_TOP_LEVEL_FOLDER/$dir`;
  35. do
  36. $(PLAY AS MUCH AS YOU WANT);
  37. done
  38. done
  39.  
  40. for dir in PARENT/*
  41. do
  42. test -d "$dir" || continue
  43. # Do something with $dir...
  44. done
  45.  
  46. #!/bin/bash
  47.  
  48. #Use set -x if you want to echo each command while getting executed
  49. #set -x
  50.  
  51. #Save current directory so we can restore it later
  52. cur=$PWD
  53. #Save command line arguments so functions can access it
  54. args=("$@")
  55.  
  56. #Put your code in this function
  57. #To access command line arguments use syntax ${args[1]} etc
  58. function dir_command {
  59. #This example command implements doing git status for folder
  60. cd $1
  61. echo "$(tput setaf 2)$1$(tput sgr 0)"
  62. git tag -a ${args[0]} -m "${args[1]}"
  63. git push --tags
  64. cd ..
  65. }
  66.  
  67. #This loop will go to each immediate child and execute dir_command
  68. find . -maxdepth 1 -type d ( ! -name . ) | while read dir; do
  69. dir_command "$dir/"
  70. done
  71.  
  72. #This example loop only loops through give set of folders
  73. declare -a dirs=("dir1" "dir2" "dir3")
  74. for dir in "${dirs[@]}"; do
  75. dir_command "$dir/"
  76. done
  77.  
  78. #Restore the folder
  79. cd "$cur"
  80.  
  81. cd parent
  82. find . -type d | while read d; do
  83. ls $d/
  84. done
  85.  
  86. find .
  87.  
  88. find . | xargs 'command here'
  89.  
  90. for p in [0-9][0-9][0-9];do
  91. (
  92. cd $p
  93. for f in [0-9][0-9][0-9][0-9]*.txt;do
  94. ls $f; # Your operands
  95. done
  96. )
  97. done
  98.  
  99. ls -d */ | xargs -I {} bash -c "cd '{}' && pwd"
Add Comment
Please, Sign In to add comment