Posting this to learn and I know this violates UNIX best practice or even just normal common sense, but I guess that's what Macintosh computers do sometimes. I have a backup drive with backup directories that look like this:

>$ tmutil listbackups
/Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-01-18-143624
/Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-03-10-011602
/Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-03-13-014248
/Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-04-10-224116

From the command line, if I try to use ls to list the contents of one of these, I am running into trouble because of the '. Note that I tried suggestions found on other posts concerning copying and pasting the path to ensure it is using the same apostrophe, substituting *. and even tried \ escaping it. But I get directory unknown error every time. I also tried putting the whole path in double quotes and also just the folder in the path with the apostrophe in double quotes. Still no luck.

What is the correct syntax to get a listing of the directory given above? How about to use a wild-card in that ls command variant to list what is in all directories from 2018-03*?

On a final note: best solution would probably be to lose the apostrophe, but this is auto-created by Macintosh during backups. What was Apple thinking?

Updates: to add further confusion to this question

  • sudo tmutil delete "/Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-03-10-011602" works
  • ls does not

And yet I can verify this path exists and even view the contents through the Mac "finder" UI.

  • nope. Tried this too. But just tried again after reading your comment. Edited question to include tests with double quote but I think my edit crossed with your answer.
    – TMWP
    Apr 11 '18 at 15:55

Apologies to the user who posted about double-quotes. Further testing reveals this is not a UNIX issue but possibly a Mac issue. Somehow, copying and pasting the whole path into the command and wrapping it in double quotes produced something that looked identical to the original but I am now thinking that somehow it must have been different.

If I pasted the path in chunks and tested each chunk, building up to a path that matched the original, then the problem went away. Proper UNIX syntax to answer both questions (list the folder and use a wild card as in the question example), the answers would look like this:

  1. ls "Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-03-10-011602"
  2. ls "Volumes/My Backup Dr/Backups.backupdb/User’s MacBook Pro/2018-03-"*

The second example would list all contents from the march folders on my backup drive. Note that the * has to be outside the double-quoted directory pattern.

  • And you can often do other handy things, like: ls /V*/M*/*/*/2018_03*
    – jrw32982
    Aug 28 '18 at 19:39

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.