4

I am trying to find all my .txt and .csv files in my backup (Apple's time machine).

The structure of the backup directories is like this:

/machine name/date/Macintosh HD/ 

The above contains all the files from my machine on that day. I have many of those directories as the backup drive contains stuff from multiple machines, last 3 years.

What I am interested in is to find my text and CSV files so for example file:

/mac1/2014-08-31-173253/Macintosh HD/Users/me/Documents/work/file1.txt

So I need to find all .txt files which have somewhere on their path /Users/me

4

You could use find, provided it's available:

$ find "/mac1/2014-08-31-173253/Macintosh HD" -wholename "*/Users/me/*.txt" -or -wholename "*/Users/me/*.csv"

This will search /mac1/2014-08-31-173253/Macintosh HD for files containing the pattern */Users/me/*.(txt|csv) in their paths.

  • 2
    ... \( -name '*.txt' -o -name '*.csv' \) -a -wholename '*/Users/me/*' should be more efficient. – Hauke Laging Dec 22 '14 at 16:45
-1

Probably you can just do:

set --
for d in /mac[123]/201[1-4]*'/Macintosh HD/Users/me/Documents/work/'
do  for g in .txt .csv
do  set -- "$d"*"$g"
    [ -e "$1" ] || shift
done

In that way you'd get an array of all of the file names in "$@" - but you'd need to glob the directory bit - which is what the /mac[123]/ is for, and I'm only guessing at the names of those directories.

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.