Search code examples
bashfindcd

How to search with find above your directory?


A part of the script make this:

dir_year=2017
dir_archive=/home/user/Documents/0_@Archivo
bindir=/home/user/bin
filework=out.txt

find "$dir_archive/$dir_year/" -name *.md > ${bindir}/${filework}

But it gives me an error since find does not look in top directories. The script is in/home/user/Documents/0_ @ File/2017/script-directory.

For it to work I have to do:

cd "$dir_archive/$dir_year/"
find "$dir_archive/$dir_year/" -name *.md > ${bindir}/${filework}

Is there any way I do not need the cd command?

Thanks


Solution

  • It must be:

    -name '*.md'
    

    otherwise *.md would be expanded by the shell