find ./dir -type f -iname "*.t[argz]*[bz2]" -print | xargs mv --target-directory=dir
seems to fail on file that has spaces in the name.
how to improve it? or alternative?
thanks for answer below: my mv doesn't support --null or -0, I'm using cygwin:
$ mv --help Usage: mv [OPTION]... [-T] SOURCE DEST or: mv [OPTION]... SOURCE... DIRECTORY or: mv [OPTION]... -t DIRECTORY SOURCE... Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. Mandatory arguments t .
The mv (move) command is used to move one or more files or directories from one directory to another directory using terminal in the Linux/Unix operating system. After using the mv command file is copied from source to destination and source file is removed. The mv command is also used to rename the file.
1 Answer. To recursively move files, combine find with mv. To rename your files when you move them it's trickier. One way is to have the loop that passes the file name through tr / _, which converts slashes into your underscores.
After you have selected each file (Figure 2), you can either right-click one of the selected files and then choose the Move To option, or just drag and drop them into a new location. The selected files (in this case, folders) will each be highlighted. Moving files on the Linux desktop is incredibly easy.
In that sense, mv already provides the recursive property, i.e. the "renaming" of all entries in the renamed directory, e.g. from a/1 to b/1 .
Use -print0
instead of -print
on the find
command, and the xargs -0
(or --null
) option - then NULs will be used as separators rather than newlines and spaces.
find ./dir -type f -iname "*.t[argz]*[bz2]" -print0 | xargs --null mv --target-directory=dir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With