Guest User

Untitled

a guest
Jul 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # go into dir with a specific file in the subdirectory
  2. function cdf() {
  3. f=$(dirname $(find . -iname "*$1*" -type f -print -quit 2>/dev/null | head -1) 2>/dev/null)
  4. if [ -z "$f" ]; then
  5. echo #'not found'
  6. else
  7. #echo "found in:" $f
  8. cd $f
  9. fi
  10. }
  11.  
  12. # go into a specific dir anywhere below this
  13. function cdd() {
  14. d=$(find . -iname "*$1*" -type d -print -quit 2>/dev/null | head -1)
  15. if [ -z "$d" ]; then
  16. echo #'not found'
  17. else
  18. cd $d
  19. fi
  20. }
  21.  
  22. # go into dir with a specific file in the subdirectory. Uses regex and substitues . with .*
  23. function cdfr() {
  24. pat=$1
  25. pat=${pat//./.*}
  26. f=$(dirname $(find . -regex ".*$pat.*" -type f -print -quit 2>/dev/null | head -1) 2>/dev/null)
  27. if [ -z "$f" ]; then
  28. echo #'not found'
  29. else
  30. #echo "found in:" $f
  31. cd $f
  32. fi
  33. }
  34.  
  35. # go into a specific dir anywhere below this. Uses regex and substitues . with .*
  36. function cddr() {
  37. #replace in between "."s with .*
  38. pat=$1
  39. pat=${pat//./.*}
  40. #echo $pat
  41. d=$(find . -regex ".*$pat.*" -type d -print -quit 2>/dev/null | head -1)
  42. if [ -z "$d" ]; then
  43. echo #'not found'
  44. else
  45. cd $d
  46. fi
  47. }
Add Comment
Please, Sign In to add comment