Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 /.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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
share|improve this answer
    
But i donot have path, I only have . as current directory then? –  Devavrata Apr 21 at 9:38
    
Don't start with ., use $(pwd) instead, that will give you a full path. –  bdowning Apr 21 at 9:40

You can use the pwd command or print out the file realpath:

$ find "$(pwd)" -size +20M
$ find . -size +20M -exec realpath {} +

Both commands real give you the absolute path to the files.

share|improve this answer
    
But 2nd one is giving find: `realpath': No such file or directory –  Devavrata Apr 21 at 9:57
    
Hum. Maybe you don't have it installed although it is provided by the coreutils package. Try to locate it with which realpath. –  Spack Apr 21 at 10:02
    
It is locating nothing.. –  Devavrata Apr 21 at 10:03
    
Which system are you using? –  Spack Apr 21 at 10:18
    
Linux BANE 3.7-trunk-amd64 #1 SMP Debian 3.7.2-0+kali8 x86_64 GNU/Linux –  Devavrata Apr 21 at 10:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.