Anil Kumar Nelakuditi Anil Kumar Nelakuditi - 19 days ago 7
Bash Question

How read paths in text file and get the file count under that paths

I have a text file which contains multiple paths like below

$ cat directory.txt
/aaaa/bbbbb/ccccc/
/aaaa/bbbbb/eeeee/
/aaaa/bbbbb/ddddd/


I need to change directory to each path in text file and need to get count of files under that paths.Below is the code i used, But it is not working.

i=
cat /aaaa/bbbbb/directory.txt

while read $i ;do
cd $i
ls |wc -l
done < /aaaa/bbbbb/count.txt

Answer
#!/bin/bash

 for i in `cat /aaaa/bbbbb/directory.txt`
  do
   cd $i
   ls | wc -l >>/aaaa/bbbbb/count.txt
  done

cat the filename in special single quote. that is in tilde sign. It will be solved.

Comments