How to get absolute path by using find command.
actually I am running the following script:-
find . -size +20M | while read a do i=$(echo $a | sed 's:/: :g') echo $a; j=($i) fileName=${j[${#j[@]}-1]} userName=${j[${#j[@]}-3]} done
but here variable $a
showing path starting from ./Downloads/filename
but I want absolute path from /
.
Answer
Use find with an absolute path.
find /path/ -size +20M
It will print the whole path.
If you do not know the working directory then use command substitution for pwd
like this:
find "`pwd`" -size +20M #or like this: find "$(pwd)" -size +20M
To get your working directory
Anyway, it seems that Bash man now advise to use $()
over ``
so you should use the second form. You can also probably refer directly to the $PWD
variable that contains the working directory of your script and it would be probably faster if you have to use in a loop.
find "$PWD" -size +20M