Guest User

Untitled

a guest
Jul 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.23 KB | None | 0 0
  1. #!/bin/bash
  2. #podobno delo delajo programi tree in ls -lR $PWD/*
  3.  
  4. #Ce prvi argument ni podan, ga nastavi na trenutni direktorij
  5. if [ -z $1 ]; then
  6.     args0=$PWD
  7. else
  8.     args0=$1
  9. fi
  10.  
  11. #Ce drugi argument ni podan, ga nastavi na max globino 3
  12. if [ -z $2 ]; then
  13.     args1=3
  14. else
  15.     args1=$2
  16. fi
  17.  
  18. #trenutna mapa
  19. echo -e "DIR \t "$PWD" ($( ls -ld | awk '{print $1}'))"
  20.  
  21. #Kot prvi argument funkciji podamo direktorij
  22. #Kot drugi argument funkciji podamo maxGlobino
  23. #Kot tretji argument funckiji podamo trenutno
  24. function listDirectory {
  25.     local ar1=$1
  26.     local ar2=$2
  27.     local ar3=$3
  28.     echo $ar1, $ar2, $ar3
  29.     #pripravi pomisljaje za graficno oznako globine
  30.     crte=$(for (( i=0; i<$ar3; i++ )) do echo -ne "--"; done)
  31.     #Zaustavitveni pogoj za rekurzijo
  32.     while [ "$ar2" -gt "0" ]; do
  33.         #beri vsebino mape
  34.         cd $ar1
  35.         ls -1 | while read f; do
  36.         #checks
  37.             if [ -d "$f" ]; then #if directory
  38.                 echo -n $crte
  39.                 echo -e "DIR \t "$f" ($( echo $f | sed 's/\ /\\\ /g' | xargs  ls -ld | awk '{print $1}'))"
  40.                 let ar2--
  41.                 let ar3++
  42.                 #echo $f, $ar2, $ar3
  43.                 #relativno ime mape spremenimo v absolutno
  44.                 ar1=$PWD/$f
  45.                 listDirectory $ar1 $ar2 $ar3
  46.             elif [ -f "$f" ]; then #if file
  47.                 echo -n $crte
  48.                 echo -e "FILE \t "$f" ($( echo $f | sed 's/\ /\\\ /g' | xargs ls -l | awk '{print $5}'))"
  49.             elif [ test -b "$f" ]; then #if block
  50.                 echo -n $crte
  51.                 echo -e "BLOCK \t "$f
  52.             elif [ test -c "$f" ]; then #if character
  53.                 echo -n $crte
  54.                 echo -e "CHAR \t "$f
  55.             elif [ test -L "$f" ]; then #if link
  56.                 echo -n $crte
  57.                 echo -e "LINK \t "$f" $( echo $f | sed 's/\ /\\\ /g' | xargs ls -l | awk '{print $9, $10}')"
  58.             elif [ test -p "$f" ]; then #if pipe
  59.                 echo -n $crte
  60.                 echo -e "PIPE \t "$f
  61.             elif [ test -S "$f" ]; then #if socket
  62.                 echo -n $crte
  63.                 echo -e "SOCKET \t "$f
  64.             else  #fila se ne da prepoznati
  65.                 echo Kaj je to?
  66.                 exit 1
  67.             fi
  68. #               let ar2++
  69. #               #samo files (odstrani 'h', če hoče samo byte):
  70. #               ls -lh $ar1 | grep ^- | awk '{print $8, "("$5")"}' | xargs -I {} echo -e $crte"FILE \t {}"
  71. #               #samo links:
  72. #               ls -l $ar1 | grep ^l | awk '{print $8, $9, $10}' | xargs -I {} echo -e $crte"LINK \t {}"
  73. #               cd ..
  74.         done
  75.     done
  76. }
  77.  
  78. #poklicemo funkcijo
  79. listDirectory $args0 $args1 0
  80. exit 0
Add Comment
Please, Sign In to add comment