-   Linux - Newbie (
-   -   Command Line Help: Bulk Moving from Sub-directories to directories (

vaneen 02-23-2016 05:54 PM

Command Line Help: Bulk Moving from Sub-directories to directories

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.

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:

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:

cd /path/to/top/directory
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.