LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 03-09-2020, 06:08 AM   #1
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Rep: Reputation: 0
Linux command - move all files from parent folders.


Hello.

I would really grateful for some help with a command that help with the following:

I have a single folder called "Movies"(/mnt/Movies).

About half of my movies are in this directory as single files.

However, the other half are in their own directory with the same name as the file e.g. /mnt/Movies/Rocky_(1976)/Rocky_(1976).ts

I want to get rid of these parent folders for the movies.

Is there a command for taking the files out of the parent folders and putting them directly into the Movie folder?

Is there also a command to then remove all the empty parent folders?
 
Old 03-09-2020, 06:22 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by elsmandino View Post
Hello.

I would really grateful for some help with a command that help with the following:

I have a single folder called "Movies"(/mnt/Movies).

About half of my movies are in this directory as single files.

However, the other half are in their own directory with the same name as the file e.g. /mnt/Movies/Rocky_(1976)/Rocky_(1976).ts

I want to get rid of these parent folders for the movies.

Is there a command for taking the files out of the parent folders and putting them directly into the Movie folder?

Is there also a command to then remove all the empty parent folders?
Yes.

My favorite, magical command known as find(1)

Along with the wonderful options for it:

-type
-exec
-mindepth (applies)
-maxdepth (opposite I feel)

Each instantiation of find for something like this is new, so I shan't hazard a direct guess.

Recommendation #1 is to "stage it" and do not execute a move or remove until you've confirmed things.

Use the -mindepth to skip your top level. Find all the files you care about that are of -type f (file), or "*.<extension>".
Once you've verified you "found" all desired, then add the -exec to mv the files up to the top, or instead of mv, use cp so that you do not munch that first try.
Then use it again to find just -type d (directory), validate it finds just the sub-directory names, and then remove those, AFTER you've confirmed that you already have all the movie files at the top level, per your desire.
 
Old 03-09-2020, 07:35 AM   #3
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by elsmandino View Post
I want to get rid of these parent folders for the movies.
Note that some movies then won't play anymore in your mediaplayer as DVD images om disk need the PARENT folder as argument (and will use ALL of the files in them) instead of the filename. This is especially true for movies with .vob (Video OBject) and .ifo (Information File Object) extensions.
See this page under the heading Directory and File structure:
http://en.wikipedia.org/wiki/DVD-Vid...file_structure
 
  


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
Create 5 processes from a common parent and ensure that the parent terminates after c pro_learner Linux - Newbie 1 03-06-2013 09:25 AM
Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders unix_72427 Programming 8 08-08-2012 02:51 PM
[SOLVED] move all ".txt" files, adding parent directory to filename mostofmonty Linux - Newbie 9 09-15-2009 08:39 AM
File descriptors shared between child and parent causing parent to hang. bharadiaam Linux - Newbie 1 03-02-2009 01:01 AM

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

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