Search code examples
linuxfindcd

find: ‘/proc/5110’: No such file or directory


I modified a find and cd command I found on the internet, it works, it finds the folder and changes dir, but it puts out the error and it's bugging me.

Command (running as root):

cd "$(find / -type d -name "nkn-node")" > /dev/null 2>&1

Error output (sometimes more than one):

find: ‘/proc/5110’: No such file or directory

EDIT: Command (running as root), if you redirect both, "cd" doesn't work

cd "$(find / -type d -name "nkn-node" > /dev/null 2>&1)" > /dev/null 2>&1

Could somebody please help solve this please.

Thank you


Solution

  • cd "$(find / -type d -name "nkn-node" 2>/dev/null)"
    

    Should get rid of the "error" (which is just a warning).

    To address the question about a more granular search that you then posed in the comments:

    cd "$(find /dir1 /dir2 /dir3 /...  -type d -name "nkn-node" 2>/dev/null)"