I wanted to create a file named
test. Accidentally I run
mkdir test instead of
Is it possible to convert
test directory in a file named
What about converting a file named
test into a directory with the same name?
This isn't possible for any Unix or Linux I've ever touched.
Under some older Unixes, directories are files, specially marked, but still files. You used to be able to read a directory with
No there is no such command because there would be absolutely no point in it. Your question is like asking for a way to transform a box into a flat rectangle. What would you do with the things in the box (directory)? How would the rectangle correspond to the box it came from?
Files and directories serve completely different functions. While a directory is indeed a file in *nix systems, that only applies to the internals of the system and not to what you, the user, see. So, converting a file to a directory, or vice versa, will always involve deleting the file and creating the directory. The best you could hope for would be to use the same inode but again, not much point in that.
Create a function to do what you want. (
I deliberately use
You could put the function definition in your shell customisation file (
First, gain access to the terminal and execute
Restart the system and regain terminal access and execute:
REMEMBER: "file" should be replaced by file you want to convert back into an ACTUAL folder.
This is just an arbitrary way to solve this problem but it creates permission anomalies which you can either use
AGAIN, this is just a proven way to avoid having to delete the file that was previously a non-empty folder.
To those wondering why you'd want to do this, follow this thread:
Apparently a bug in the firmware flipped the bit in the directory entry for the file, making the OS think it's a folder instead of a file.
While I don't have the Linksys router in question, something changed all my .jpg files into empty folders. If there's someway to flip the bit (or whatever) that says an NTFS directory entry is a folder vs a file, I'd like to know about it.
One of the solutions in that 2-year long thread said if the hard drive containing the folders-that-used-to-be-files is connected to a Mac running OS/X, the Mac will see them as files again, and they can be copied to a folder on the Mac. I don't have a Mac to try that out, so if anyone knows a way to flip the bit...