0

I cannot for the life of me workout where I am going wrong here and why my find | grep is not outputting the file.

What I am actually trying to do is catch all files that match this regex "\(multidoge\|wallet\)[.]\(dat\|wallet\)" I will be adding more ORs later for the different wallets I need to find on my old filesystem.

ls -l --quote-name /
lrwxrwxrwx   1 root root           7 Dec 30 21:52 "bin" -> "usr/bin"
drwxr-xr-x   4 root root        4096 Feb 13 00:30 "boot"
drwxr-xr-x   2 root root        4096 Dec 30 21:53 "cdrom"
drwxr-xr-x  21 root root        5520 Mar 15 00:34 "dev"
drwxr-xr-x 165 root root       12288 Mar 12 16:13 "etc"
drwxr-xr-x   3 root root        4096 Jan  4 16:07 "home"
lrwxrwxrwx   1 root root           7 Dec 30 21:52 "lib" -> "usr/lib"
lrwxrwxrwx   1 root root           9 Dec 30 21:52 "lib32" -> "usr/lib32"
lrwxrwxrwx   1 root root           9 Dec 30 21:52 "lib64" -> "usr/lib64"
lrwxrwxrwx   1 root root          10 Dec 30 21:52 "libx32" -> "usr/libx32"
drwx------   2 root root       16384 Dec 30 21:52 "lost+found"
drwxr-xr-x   3 root root        4096 Dec 30 21:57 "media"
drwxr-xr-x   7 root root        4096 Dec 31 16:53 "mnt"
-rw-r--r--   1 root root           0 Mar 14 23:15 "multidoge.wallet"
drwxr-xr-x   8 root root        4096 Mar  5 17:00 "opt"
dr-xr-xr-x 604 root root           0 Mar 12 14:18 "proc"
drwx------  12 root root        4096 Mar 14 20:32 "root"
drwxr-xr-x  42 root root        1440 Mar 13 09:58 "run"
lrwxrwxrwx   1 root root           8 Dec 30 21:52 "sbin" -> "usr/sbin"
drwxr-xr-x   6 root root        4096 Jan 13 10:21 "snap"
drwxr-xr-x   2 root root        4096 Dec 13 12:23 "srv"
-rw-------   1 root root 15032385536 Jan  4 15:24 "swapfile"
dr-xr-xr-x  13 root root           0 Mar 12 14:18 "sys"
drwxrwxrwt  34 root root       24576 Mar 15 00:40 "tmp"
-rw-r--r--   1 root root           8 Dec 31 10:29 "tmpjcef-p79454_scheme.tmp"
drwxr-xr-x  14 root root        4096 Dec 13 12:23 "usr"
drwxr-xr-x  13 root root        4096 Jan 13 10:18 "var"
-rw-r--r--   1 root root           0 Mar 14 23:15 "wallet.dat"

hutber@hutber:/$ sudo find / -print | grep -i "multidoge.wallet"

hutber@hutber:/$ sudo find / -print | grep -i "wallet.dat"
/wallet.dat

Edit

find without grep returns the files, however only when using -maxdepth 1:

hutber@hutber:/$ sudo find / -name "*wallet*"
/wallet.dat
/media/hutber/E036A40336A3D934/cygwin64/bin/kwallet-query.exe
/media/hutber/E036A40336A3D934/cygwin64/bin/cygkwalletbackend-1.dll
/media/hutber/E036A40336A3D934/cygwin64/bin/cygkwalletbackend5-5.dll
/media/hutber/E036A40336A3D934/cygwin64/bin/cygkwalletclient-1.dll
^C
hutber@hutber:/$ find / -maxdepth 1 -name "*wallet*"
/wallet.dat
/multidoge.wallet
1
  • Comments are not for extended discussion; this conversation has been moved to chat. – terdon Mar 17 at 10:29
3

From comments to the question, it seems as if the user grew impatient and interrupted the find command after some time.

They noticed that they got the wanted results if they used find with -maxdepth 1, which is not surprising since that drastically decreases the size of the search tree when using / as the top-level search path.

So, the issue of not getting any output from the command would be resolved by adding a bit more patience, alternatively by being a bit more selective when it comes to picking search paths and choosing a subtree of / instead.

A secondary issue was to match the filenames against a particular regular expression,

\(multidoge\|wallet\)[.]\(dat\|wallet\)

If we rewrite this as a POSIX extended regular expression that matches the full path of a file, we get

.*/(multidoge|wallet)\.(dat|wallet)

This could be slotted into GNU find like thus:

find / -regextype posix-extended -regex '.*/(multidoge|wallet)\.(dat|wallet)'
3
  • Thanks for the answer, its very nice to have it rounded up. However, I cannot use -maxdepth, as stated. I need to search my entire file system. But again, you are completely correct that I ended the search early, thus not returning all the data. This is due to not understanding that find does not search files THEN folders, that it indeed searches in no organised order (I am sure this is incorrect, but I cannot find where it is documented) – Jamie Hutber Mar 16 at 11:27
  • @JamieHutber I'm not suggesting you use -maxdepth. I'm completely away that you need to search the entire system. What is it in my answer that says otherwise? – Kusalananda Mar 16 at 11:29
  • Indeed, that is why I was thankful for the answer!! Because it resolves my soltuion – Jamie Hutber Mar 16 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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