LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2011, 08:01 PM   #1
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Rep: Reputation: 24
bash how mv */*.* /some/other/directory


I have a directory containing about 150 sub-directories, each of which contains only files of various types. I need to get all those files together in a single directory without any of the subdirectories. Can it be done with any simple approach like "mv */*.*", or do I need to get a list of all the individual filepaths and feed that to mv?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 08-03-2011, 08:29 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
find /src/dir -exec mv '{}' /some/other/dir +;
 
Old 08-03-2011, 08:36 PM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

try this:
Code:
find /path/to/dir -type f -exec mv -n '{}' /path/to/target \;
The -n option prevents mv to overwrite existing files in the target directory. If you still have files in one of the source directories then you will need a slightly more complicated approach and a naming convention for the files that have the same name.
 
2 members found this post helpful.
Old 08-03-2011, 10:51 PM   #4
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Original Poster
Rep: Reputation: 24
I thank both AlucardZero and crts for your help, but it seems that \; is the charm
Code:
g  find /home/g/x -exec mv '{}' /home/g/y +;
find: missing argument to `-exec'
g  find /home/g/x -type f -exec mv '{}' /home/g/y +;
find: missing argument to `-exec'
g  find /home/g/x -type f -exec mv '{}' /home/g/y \;
g
Many thanks.

Last edited by porphyry5; 08-04-2011 at 04:02 AM. Reason: Correction
 
Old 08-04-2011, 06:32 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by porphyry5 View Post
*.*
That won't work for getting only files and not directories.

Linux has no concept of file extensions, both files and directory names can freely contain dots (or not have any at all).
 
Old 08-04-2011, 08:55 AM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
oop. crts is right in that you want "-type f". And my syntax was slightly wrong, it should be \;.
 
Old 08-04-2011, 09:51 AM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by AlucardZero View Post
And my syntax was slightly wrong, it should be \;.
Hi AlucardZero,

your syntax is not wrong; at least the 'find' version (GNU 4.4.2) that I am using accepts it. Although the terminating ';' is not needed when you use '-exec' with a '+', it should not lead to an error if you use it anyway. At least not in bash. Bash will simply interpret it as a line terminator. So possible sources for the error messages can be a 'find' version that does not support '-exec ... +' or maybe executing 'find' in a non-bash terminal.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash directory BryDawg Linux - Newbie 8 03-10-2010 08:14 AM
Bash Directory Variables DrPoodle Programming 5 07-24-2008 08:23 PM
Bash scripting: "line [...]: [directory]: is a directory " ? serious Linux - Newbie 1 10-20-2007 12:08 PM
Bash script to strip a certain directory out of directories in a directory? rylan76 Linux - General 3 08-29-2006 11:35 AM
bash: cd: My: No such file or directory Doug.Gentry Fedora 2 12-05-2004 02:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration