How do I get absolute path from using find unix command

How to get absolute path by using find command.
actually I am running the following script:-

find . -size +20M | while read a
     i=$(echo $a | sed 's:/: :g')
     echo $a;

but here variable $a showing path starting from ./Downloads/filename but I want absolute path from /.


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

Leave a Reply

Your email address will not be published. Required fields are marked *