LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-05-2017, 03:43 PM   #1
anraf4
LQ Newbie
 
Registered: Sep 2016
Posts: 3

Rep: Reputation: Disabled
Copy files from many subdirectories into a unique directory


I have many subdirectories, which all contains 2 files, and I would like every file to be all in one directory.

What I have:

ls /Folder1/
file11.txt
file12.txt

ls /Folder2/
file21.txt
file22.txt

ls /Folder3/
file31.txt
file32.txt
...

What I want:

ls /NewFolder/
file11.txt
file12.txt
file21.txt
file22.txt
file31.txt
file32.txt
...

Thanks for your help!!
 
Old 09-05-2017, 03:59 PM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,765

Rep: Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797
Is this homework/coursework?
 
Old 09-05-2017, 09:29 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,354
Blog Entries: 13

Rep: Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411
Quote:
Originally Posted by MadeInGermany View Post
Is this homework/coursework?
Also, what have you, anraf4, tried.

Please review LQs FAQ and update your question with some additional background.
 
Old 09-06-2017, 03:40 AM   #4
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 553

Rep: Reputation: 277Reputation: 277Reputation: 277
Hi anraf4,

I think the philosophy of the Linux community is one of sharing and mutual help. But we also expect you at least try to help yourself first.

I'll give you a lead. Basically, mv works like this:
Code:
mv SOURCE DESTINATION
The source can be any file(s) anywhere and the destination can be any directory anywhere. So, I think you should give it a try and see.
Also, read the man pages for more info.

If you're not sure, use the copy command cp for a start; in case of mistake you won't be losing the source files.

Last edited by aragorn2101; 09-06-2017 at 03:42 AM.
 
Old 09-06-2017, 04:43 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,873

Rep: Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600
You might also find the 'find' cmd useful
 
Old 09-06-2017, 08:06 AM   #6
anraf4
LQ Newbie
 
Registered: Sep 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
(1) No, this is not a homework.

(2) Every of my files contains a fastq.gz extension, so I type this command and it worked.
mv ./*/*fastq.gz ./NewFolder

Thanks everyone!
 
Old 09-06-2017, 08:16 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,354
Blog Entries: 13

Rep: Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411
Quote:
Originally Posted by anraf4 View Post
(1) No, this is not a homework.

(2) Every of my files contains a fastq.gz extension, so I type this command and it worked.
mv ./*/*fastq.gz ./NewFolder

Thanks everyone!
Well have you considered a "find -exec" command type? Are you aware of that option? And are there other .gz files which could be found?

Because you can type something attune to:
Code:
find . -name "*fastq.gz" -exec mv {} ./NewFolder \;
The command you do type, is it a new point you've reached which does work, or is it what you've been typing and you're looking for a new way?
 
Old 09-07-2017, 10:48 AM   #8
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,765

Rep: Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797
./ means located in the current directory.
This can be used for clarification, but is not needed.
Like you simply do
Code:
cd NewFolder
cd ..
that works like
Code:
cd ./NewFolder
cd ./..
you can simply do
Code:
mv */*fastq.gz NewFolder
 
  


Reply

Tags
linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Help: Rsync options/switches to copy directory tree - unique files only? LouArnold Linux - Software 8 06-24-2016 03:56 PM
[SOLVED] Need to copy all .jpg images in subdirectories to a specific directory sikanders Linux - Newbie 5 08-06-2010 07:15 AM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 09:18 PM
Copying all files from subdirectories into one directory Hegemon Linux - General 3 01-17-2005 11:25 AM
How to know the property a directory include the files and subdirectories? Xiangbuilder Linux - Newbie 3 08-31-2003 05:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:37 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