0

So, I have a Windows virtual machine running this certain program. The details are as follows:

  1. The program has no recursive search functionality.
  2. I have lots of free disk space.
  3. I have excess junk in my pictures folder. (I just want to copy the pictures, assume I have pictures ranging every known picture file extension (excluding archives))
  4. I want to use the command line to scan for every picture in my home directory recursively, and copy all of them to the current directory WITHOUT creating sub folders that match my pictures folder. (Ex: ~/cyndaquil.png is copied to ./cyndaquil.png, while ~/foo/bar/quilava.png is copies to ./quilava.png. Also, my home directory is a mess.)

So, is there any command I can use to do this?

2
  • 1
    What about ` ~/cyndaquil.png` and ~/foo/bar/cyndaquil.png?
    – waltinator
    Apr 7, 2015 at 22:47
  • @waltinator that was an example I used on how the files should be copied, similar to a recursive copy, except it doesn't make directories in the destination and just copies everything to the root of the directory.
    – user245115
    Apr 7, 2015 at 22:50

2 Answers 2

2

This will copy (will, echo) all the files that the file command thinks is some kind of image:

for i in $(find . -type f -print0 | xargs -0 file | grep " image " | cut -d: -f1 ) ; do echo cp "$i" $PWD; done
1

If you do not care about name collisions (foo/bar/name1 vs foo/other/name1 (but see man cp for --backup=numbered), you could read man find to see what this does:

find $HOME -type f -iname '*.png' -exec cp --backup=numbered {} $PWD \;
4
  • Not only png files, I need: .jpg, .jpeg, .gif, .bmp etc...
    – user245115
    Apr 7, 2015 at 22:57
  • 1
    Again read man find. find $HOME -type f \( -iname '*.png' -o \( -iname '*.jpg' -o -iname '*.jpeg' \) \) .... Replace the cp with echo cp until you are happy with the output.
    – waltinator
    Apr 7, 2015 at 23:07
  • Any idea how to make a command that executes with a set of arguments so you don't have to retype it? (I think it was echo {"a","b"} to make it as if it executed "echo a" then "echo b")
    – user245115
    Apr 7, 2015 at 23:35
  • Yes, but that is a new (and harder) question. I do not understand what you mean by " a command that executes with a set of arguments so you don't have to retype it". This is part of which shell scripts are for.
    – waltinator
    Apr 7, 2015 at 23:45

You must log in to answer this question.

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