0

I'm SSH'ing into a machine to complete some work. In my home directory, I previously had a subdirectory, let's call it myDirectory which I could move to from within the home directory using cd as with any other directory (i.e. cd ./myDirectory).

Now, when I run the command, I get the error:

"myDirectory not a directory"

and when I run ls the myDirectory is color-coded differently than other directories, and differently than it had been previously. I can however, run mv someFile ./myDirectory, and recently moved a number of files (which I now need to access) in this way.

So, myDirectory obviously points to a directory, but is not at ~/myDirectory any longer. I believe I understand the problem, however I'm not sure what command to use to access the directory. How can I access this directory and/or determine its new location?

Running this command:

ls -ld myDirectory

Produces:

-rw-rw-r-- 1 myUsername myUsername 15029 Nov  2 17:57 myDirectory
Giacomo1968
  • 58,727
10GeV
  • 103
  • 3

1 Answers1

1

The first - in the output of ls -ld myDirectory indicates myDirectory is a regular file, not a directory.

I can only speculate how this happened. One possibility is you (or someone/something) renamed/moved/deleted the original directory myDirectory, so no entry named myDirectory was there; then you renamed some regular file someFile to myDirectory.

mv someFile ./myDirectory renames someFile to myDirectory. The old regular file named myDirectory (if existed) is lost. This means if you renamed more than one file this way, only the last one can be easily recovered; it's under the name myDirectory.

To avoid such mishaps add a trailing slash when you refer to what you think is a directory. If you did

mv someFile ./myDirectory/

and ./myDirectory was not a directory, the tool would complain without moving anything.

Up to this point we assumed someFile is a regular file. If it could be of the type directory (which is also a file) then (depending of what you want to do) it might be even better to append /. instead of /.