1

The computer is running Yosemite. I was trying to move a couple documents from the download folder to documents via the command line using

find . -iname '*.pdf' -exec mv "{}" ./Documents \

The answer given answered a almost everything. I just an wondering now what happens to the files moved. Are they in the root users Documents folder?

4
  • 1) Why is there a space in *. pdf 2) Why does the command end in a line continuation (``)? You should probably include the next lines until the end of the command. Commented Sep 20, 2016 at 18:45
  • I typed it out from my phone so .pdf isn't supposed to have a space. I don't understand the second part of your question but if you mean the quotes (") that is not the same as (``). It was all one command. Commented Sep 20, 2016 at 18:59
  • I meant the backslash \ but I didn't escape it properly and it broke the code formatting. Commented Sep 20, 2016 at 19:01
  • Oh that. I didn't know what ` \ ` meant but I tried the command without it and that didn't work. I was asking about it in my post. Commented Sep 20, 2016 at 19:09

3 Answers 3

2

To move files you did not need to find them first. You could just do:

mv *.pdf ../Documents 

If you insist on using find:

find . -iname '*.pdf' -exec mv {} ../Documents \; 

Here, the last "\" is to escape characters like ";" so that shell works right.

1

The command might better have been as follows.

find ~/Downloads -iname "*.pdf" -exec mv '{}' ~/Documents \; 

Note the semi-colon after the backslash. Or, also better as follows.

find ~/Downloads -iname "*.pdf" -exec mv '{}' ~/Documents + 

Note the plus used instead.

Or even as follows.

find ~/Downloads -iname *.pdf -exec mv {} ~/Documents + 

The single quotes around {} are used to tell the shell not to interpret the characters within the quotes as any kind of shell punctuation. They are normally not needed, but using the single quotes is not a bad habit to have. As far as I know, it's only fish that expands {} to something else. The {} characters themselves basically represent the list of found files.

The double quotes around the iname parameter are also not needed, but also not a bad habit to use them.

The command in the question uses the continuation character, so pressing Enter after it should only have provided another line on which you could continue to type. So, what else was typed after that command, or did you just forget to type the semi-colon in the question? If the command was typed as a regular user, then the PDF files may still be in your home directory somewhere.

It would have been most useful to open Terminal and type man find. Then see the section, Examples, for usage notes that would have covered this scenario.

To find all PDF files on your system:

cd && find / -iname "*.pdf" 1>found.txt 

This will create a list, found.txt, of all PDF files that the regular user account has permission to list. I don't know if there is enough information to answer where the missing files have gone.

1
  • Thank you my question felt awful compared to some of the others on here Commented Sep 20, 2016 at 19:52
1

I assume you're using "find" because you have pdf files in sub-directories or you'd just use "mv *.pdf ../Documents". First I'd do the following, just to make sure the command is doing what I want.

find . -type f | grep dat$

Then I'd fill out the rest of the command with xargs

find . -type f | grep dat$ | xargs mv ../Documents

As a matter of habit I like putting "grep" and "xargs" on the ends of commands where I already know the output and what they're doing.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.