LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command Line Help: Bulk Moving from Sub-directories to directories (https://www.linuxquestions.org/questions/linux-newbie-8/command-line-help-bulk-moving-from-sub-directories-to-directories-4175573049/)

vaneen 02-23-2016 05:54 PM

Command Line Help: Bulk Moving from Sub-directories to directories
 
URGENT HELP WITH COMMANDS

I was struggling to find a Linux command to do some pre-processing of data and was wondering if anyone can help me with that. Here is the situation I have:

There is a hierarchy of directories and sub-directories as follows:
>> I have a Directory with 78 sub-directories.
>> Each Sub-directory holds a file (along with many other files) with *.tab extension.
>> I want to collect all the *.tab files in one location.
>> Later, I want to append all the *.tab files data to one file called MasterTabFile.

Any help will be greatly appreciated.
Thanks

Ztcoracat 02-23-2016 07:41 PM

Hi & Welcome to Linux Questions.

Before you move all of those files you should consider performing a back up.:)

Take a look at this:
http://linoxide.com/linux-command/mv-command-linux/

http://linuxcommand.org/lc3_lts0050.php
http://www.computerhope.com/unix/umv.htm
http://unix.stackexchange.com/questi...r-in-2nd-and-3
http://www.cyberciti.biz/faq/unix-li...ext-to-a-file/

rknichols 02-23-2016 09:22 PM

I guess I'd make a lousy teacher because I don't know how to direct you toward working this out yourself, but please do study the manpages for find and mv to see why this works:
Code:

cd /path/to/top/directory
Top="$PWD"
find . -mindepth 2 -type f -name "*.tab" -exec mv --no-clobber --target-directory="$Top" {} +

With the "--no-clobber" it should be safe against losing anything, but it would still be wise to back up that wole tree in a tar archive first.

And yes, I know that directing newcomers to study the find manpage is really dropping them into the deep end of the pool.

chrism01 02-24-2016 05:11 AM

Following on from rknichols, because 'find' is such a useful cmd, there are millions of examples on the net.
As above, backups first, then create some temp dirs/files and play with find until you get it.


All times are GMT -5. The time now is 05:31 PM.