1

I want find duplicate files using my find, i cant seem to to make it echo "bububu" since it keeps echoing "blablabla" even if my path and name are wrong and there is no such file in that directory. Im trying to do this, if there is an existing file with the exact same name in the destination, create a log file to keep track of that. So now im trying to find if there is an existing file with the exact same name in the destination.

echo "Enter path for pre-configured settings"

read Path

echo "Enter file name for pre-configured settings"

read Name

if [ -n $(find "$Path" -type f -iname "$Name") ]
then 
    echo "blablabla"
else 
    echo "bububu"
5
  • 1
    You could use fdupes to find duplicate files. Commented May 12, 2019 at 11:36
  • If you copy/pasted the code, then you have a typo, you are closing the bracket [ with a brace }. In bash it is better to use [[ (bash test operator) than [ which is an alias for the test command.
    – xenoid
    Commented May 12, 2019 at 11:50
  • In your code, it seems as if you're just wanting to find files of a certain name under some search path. It does not seem to have anything to do with finding duplicated files. Can you describe a bit more about what you mean with "duplication" here?
    – Kusalananda
    Commented May 12, 2019 at 12:04
  • If there is an existing file with the exact same name in the destination, create a log file to keep track of that. So now im trying to find if there is an existing file with the exact same name in the destination
    – Sama
    Commented May 12, 2019 at 12:09
  • If you have "blablabla", then the find command is outputting something. Add a line to execute the find command outside of the test. This will print its output on the console and you will likely see why the output isn't an empty string.
    – xenoid
    Commented May 12, 2019 at 12:33

1 Answer 1

1

With proper bracket balancing, your code works.

But since you have a closing '}' instead of a ], the } is part of the -n test and the tested string is never empty. Executing with set -x you can see this being executed:

+ '[' -n '}'

PS: Your code may have problems if your find returns more than one file. Put quotes around the "$(find ...)".

3
  • tried putting quotes but im still not able to get the echo "bububu" even though there is no files in the directory
    – Sama
    Commented May 12, 2019 at 12:20
  • Your immediate problem is not the quote but the closing brace instead of a closing bracket.
    – xenoid
    Commented May 12, 2019 at 12:21
  • that was a typo so it wasnt the problem, thanks for the help tho
    – Sama
    Commented May 12, 2019 at 12:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .