LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-23-2016, 05:54 PM   #1
vaneen
LQ Newbie
 
Registered: Feb 2016
Posts: 1

Rep: Reputation: Disabled
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
 
Old 02-23-2016, 07:41 PM   #2
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

Rep: Reputation: 1163Reputation: 1163Reputation: 1163Reputation: 1163Reputation: 1163Reputation: 1163Reputation: 1163Reputation: 1163Reputation: 1163
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/
 
Old 02-23-2016, 09:22 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,474

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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.

Last edited by rknichols; 02-23-2016 at 09:25 PM. Reason: add: And yes, ...
 
Old 02-24-2016, 05:11 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,814

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
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.
 
  


Reply


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
Configuring Shared Directories via the Command Line frankbell Linux - Server 3 11-30-2010 10:55 PM
[SOLVED] Command line: chown command recursively on invisible directories? JZL240I-U Linux - Software 9 10-29-2010 05:34 AM
Get Directories with Command Line FTP? BLazeD Linux - Newbie 2 09-09-2004 03:47 AM
share directories from command line tarheel92x Linux - Networking 1 09-07-2004 10:09 PM
How may I list only the directories in command line? geraldomanaus Linux - Newbie 5 03-20-2003 01:40 PM

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

All times are GMT -5. The time now is 12:04 PM.

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