0

I have a bunch of files that have just hashes as names and no file endings. (It's an iPhone backup to be precise.) I know there are SQLite databases amongst these files.

How do I find them?

2 Answers 2

3

As a starting point using the file command to identify the file type:

find . -print0 | xargs -0 file

Result:

./.X11-unix:                                                                sticky directory
./.Test-unix:                                                               sticky directory
./test.db:                                                                  SQLite 3.x database

Then add some grepping to filter out results.

4
  • 1
    Probably better to limit to files only. And you may as well tell find to run the file command, no need for xargs: find . -type f -exec file {} + | grep SQLite.
    – terdon
    Mar 22, 2020 at 13:09
  • This is a good point, but xargs and -exec are not exact equivalents - I understand that -exec could fail if the argument list is too long (too many files found). "When you use -exec to do the work you run a separate instance of the called program for each element of input. So if find comes up with 10,000 results, you run exec 10,000 times. With xargs, you build up the input into bundles and run them through the command as few times as possible, which is often just once." Source: xargs vs. exec {}
    – Kate
    Mar 22, 2020 at 14:13
  • 1
    @Anonymous, terdon terminated the -exec with +: "This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files." from man find. Or the man page from OSX: "Same as -exec, except that ``{}'' is replaced with as many pathnames as possible for each invocation of utility. This behaviour is similar to that of xargs(1)." Mar 22, 2020 at 14:17
  • What user4556274 said. Also, find will never fail if there are too many files. When using ; instead of +, the warning you quoted simply explains it will run as many processes as there are files, but it runs them sequentially and separately so there is no issue about the argument list ever being too long.
    – terdon
    Mar 23, 2020 at 11:32
1

The utility file identifies files based on their magic number and other identifying characteristics.

file <filename>

will output something like

<filename>: SQLite 3.x database

To obtain all sqlite3 database files in a directory, you could do something like

file * | grep SQLite

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .