I’m not even sure if this is easily possible, but I would like to list the files that were recently deleted from a directory, recursively if possible.
I’m looking for a solution that does not require the creation of a temporary file containing a snapshot of the original directory structure against which to compare, because write access might not always be available. Edit: If it’s possible to achieve the same result by storing the snapshot in a shell variable instead of a file, that would solve my problem.
Something like:
find /some/directory -type f -mmin -10 -deletedFilesOnly
Edit: OS: I’m using Ubuntu 14.04 LTS, but the command(s) would most likely be running in a variety of Linux boxes or Docker containers, most or all of which should be using ext4
, and to which I would most likely not have access to make modifications.
Advertisement
Answer
You can use the debugfs
utility,
debugfs is a simple to use RAM-based file system specially designed for debugging purposes
First, run debugfs /dev/hda13
in your terminal (replacing /dev/hda13
with your own disk/partition).
(NOTE: You can find the name of your disk by running df /
in the terminal).
Once in debug mode, you can use the command lsdel
to list inodes corresponding with deleted files.
When files are removed in linux they are only un-linked but their inodes (addresses in the disk where the file is actually present) are not removed
To get paths of these deleted files you can use debugfs -R "ncheck 320236"
replacing the number with your particular inode.
Inode Pathname 320236 /path/to/file
From here you can also inspect the contents of deleted files with cat
. (NOTE: You can also recover from here if necessary).
Great post about this here.