Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #podobno delo delajo programi tree in ls -lR $PWD/*
- #Ce prvi argument ni podan, ga nastavi na trenutni direktorij
- if [ -z $1 ]; then
- args0=$PWD
- else
- args0=$1
- fi
- #Ce drugi argument ni podan, ga nastavi na max globino 3
- if [ -z $2 ]; then
- args1=3
- else
- args1=$2
- fi
- #trenutna mapa
- echo -e "DIR \t "$PWD" ($( ls -ld | awk '{print $1}'))"
- #Kot prvi argument funkciji podamo direktorij
- #Kot drugi argument funkciji podamo maxGlobino
- #Kot tretji argument funckiji podamo trenutno
- function listDirectory {
- local ar1=$1
- local ar2=$2
- local ar3=$3
- echo $ar1, $ar2, $ar3
- #pripravi pomisljaje za graficno oznako globine
- crte=$(for (( i=0; i<$ar3; i++ )) do echo -ne "--"; done)
- #Zaustavitveni pogoj za rekurzijo
- while [ "$ar2" -gt "0" ]; do
- #beri vsebino mape
- cd $ar1
- ls -1 | while read f; do
- #checks
- if [ -d "$f" ]; then #if directory
- echo -n $crte
- echo -e "DIR \t "$f" ($( echo $f | sed 's/\ /\\\ /g' | xargs ls -ld | awk '{print $1}'))"
- let ar2--
- let ar3++
- #echo $f, $ar2, $ar3
- #relativno ime mape spremenimo v absolutno
- ar1=$PWD/$f
- listDirectory $ar1 $ar2 $ar3
- elif [ -f "$f" ]; then #if file
- echo -n $crte
- echo -e "FILE \t "$f" ($( echo $f | sed 's/\ /\\\ /g' | xargs ls -l | awk '{print $5}'))"
- elif [ test -b "$f" ]; then #if block
- echo -n $crte
- echo -e "BLOCK \t "$f
- elif [ test -c "$f" ]; then #if character
- echo -n $crte
- echo -e "CHAR \t "$f
- elif [ test -L "$f" ]; then #if link
- echo -n $crte
- echo -e "LINK \t "$f" $( echo $f | sed 's/\ /\\\ /g' | xargs ls -l | awk '{print $9, $10}')"
- elif [ test -p "$f" ]; then #if pipe
- echo -n $crte
- echo -e "PIPE \t "$f
- elif [ test -S "$f" ]; then #if socket
- echo -n $crte
- echo -e "SOCKET \t "$f
- else #fila se ne da prepoznati
- echo Kaj je to?
- exit 1
- fi
- # let ar2++
- # #samo files (odstrani 'h', če hoče samo byte):
- # ls -lh $ar1 | grep ^- | awk '{print $8, "("$5")"}' | xargs -I {} echo -e $crte"FILE \t {}"
- # #samo links:
- # ls -l $ar1 | grep ^l | awk '{print $8, $9, $10}' | xargs -I {} echo -e $crte"LINK \t {}"
- # cd ..
- done
- done
- }
- #poklicemo funkcijo
- listDirectory $args0 $args1 0
- exit 0
Add Comment
Please, Sign In to add comment