Redirect find output to file on TrueNAS Core

CJRoss

Contributor
Joined
Aug 7, 2017
Messages
139
First, let me admit that this is an XY problem. I'm trying to find some files in my snapshots that were deleted at some point. I don't recall when they were added nor know when they were deleted so I'm trying to search through all of the snapshots.

Inside the .zfs/snapshot directory, I can run a find command and it starts outputting results to the terminal. However, it's too much data for me to sort through so I'm trying to log it to a file. I'd also like to be able to background the task so I don't need to stay logged in as it's going to take a long time to go through all of the files in the snapshots.

When I add > or | tee to the find command nothing gets output to the terminal or the file. I've tried adding 2>&1 but that doesn't help either. If I just run echo blah > file.txt then that works.

Redirecting the find output to a file works on my linux box so I'm not sure why it won't work in Core. Any ideas what I'm missing?

Thanks.
 
Joined
Oct 22, 2019
Messages
3,641
Where are you trying to redirect the file to? You can't redirect it in the current directory if you are currently in .zfs/snapshot or even just .zfs

Did you try redirecting it to a writable directory that you user (or "root") has permission?

TrueNAS Core ships with "tmux", so you can create a new tmux session, start the command, and then use CTRL + B then D to exit the session without aborting the task. To kill the session, re-enter it with "tmux attach" and then use CTRL + D to end it.
 

CJRoss

Contributor
Joined
Aug 7, 2017
Messages
139
Where are you trying to redirect the file to? You can't redirect it in the current directory if you are currently in .zfs/snapshot or even just .zfs

Did you try redirecting it to a writable directory that you user (or "root") has permission?

TrueNAS Core ships with "tmux", so you can create a new tmux session, start the command, and then use CTRL + B then D to exit the session without aborting the task. To kill the session, re-enter it with "tmux attach" and then use CTRL + D to end it.

The whole time I've been redirecting the file to someplace I can write. As I mentioned, I can echo things to the file with no problem so it's not a permissions issue.

I just tested it to the snapshot folder and I get "zsh: operation not supported"
 

CJRoss

Contributor
Joined
Aug 7, 2017
Messages
139
I still have no idea why find won't redirect, but since echo will I got it to work by adding -exec echo {}.

Code:
sudo find . -iname "*filename*" -exec echo {} \; > path/file.log
 
Joined
Oct 22, 2019
Messages
3,641
This worked for me over an SSH connection.

find /mnt/mypool/backups -iname "*keyword*" > /mnt/mypool/home/username/findresults.txt

Maybe it's because I SSH'd into the TrueNAS Core server?

I didn't need to use "echo" or "print".


EDIT: Just confirmed that it works over SSH if I use my normal user, "sudo", or even as the root user.

EDIT 2: Just confirmed it works in the GUI using the "Shell" menu.

So now I'm really not sure why it won't write your results to an output file...
 

CJRoss

Contributor
Joined
Aug 7, 2017
Messages
139
Try doing it from inside the .zfs/snapshot dir

I was ssh'd into the server but I never tried it from a base dir instead of just using . as the starting search in the snapshot dir.

Anyways, echo worked so I stopped looking at it after that.
 
Joined
Oct 22, 2019
Messages
3,641
Try doing it from inside the .zfs/snapshot dir
Just tried it. Same result. The redirected output .txt file contains all the results.

Basically I did:
Code:
cd /mnt/mypool/backups/.zfs/snapshot

find . -iname "*keyword*" > /mnt/mypool/home/username/findresults.txt
 
Last edited:

CJRoss

Contributor
Joined
Aug 7, 2017
Messages
139
Just tried it. Same result. The redirected output .txt file contains all the results.

Basically I did:
Code:
cd /mnt/mypool/backups/.zfs/snapshot

find . -iname "*keyword*" > /mnt/mypool/home/username/findresults.txt

Weird. That's exactly what I did but it didn't work. I tried it both with sudo and as root.
 
Joined
Oct 22, 2019
Messages
3,641
I'm on TrueNAS Core 13.0-U2, if that means anything.
 
Top