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 (