Advertisement
nocturnalmk

recursively ls home folder

Jun 18th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. src=$PWD
  4.  
  5. listaj() {
  6.  
  7.         dir=$1
  8.         cd "$dir"
  9.  
  10.         for file in *
  11.         do
  12.                 level=$2
  13.                 l=0;
  14.                 space=''
  15.                 while [ $l -lt $level ]
  16.                 do
  17.                         space="${space}\t"
  18.                         l=$(( $l + 1 ))
  19.                 done
  20.  
  21.                 echo "${space}${file}" >> $src/tree.txt
  22.  
  23.                 if [ -d "$file" ]
  24.                 then
  25.                         listaj "$file" $(( $level + 1 ))
  26.                         cd ..
  27.                 fi
  28.         done
  29.  
  30. }
  31.  
  32. listaj ~/ 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement