In linux how can I create a folder from a file?

Posted on

Problem :

I ran the following command to find all epubs and move them to a directory:

find . -iname "*.epub" -exec mv {} /data/EPUB ;

That created a super file with all the epubs concatenated together. Is there any way to break them apart again? Is there a command to change the super file into a folder?

Solution :

If you did not create the directory /data/EPUB first then effectively what you did was rename each file, one at a time, to a file named /data/EPUB – overwriting the previous one each time.

What you have now is not a “superfile”, rather /data/EPUB is the final .epub file that was moved, and all other .epub files have been lost (as they were overwritten by subsequent moves).

There is no straightforward way to retrieve them.

I suggest unmounting the device immediately (if possible) and performing no further writes, then using a program such as TestDisk to attempt to recover the overwritten files (also detailed instructions here).

In the future I recommend using mv -i which will prompt for overwrite, thus catching any mistakes such as this one.

I also suggest making a habit of placing a trailing / after directory names, which will also catch such errors by failing if the directory does not exist (rather than assuming it is a file), e.g.:

find . -iname "*.epub" -exec mv -i {} /data/EPUB/ ;

Leave a Reply

Your email address will not be published. Required fields are marked *