3

How can I move a directory whose name is just a space?

ls -lah
drwx------  4 user1 user1 8.0K Mar 13 14:16 .
drwxr-xr-x  3 root  root    60 Mar 13 13:48 ..
drwx------ 18 user1 user1 4.0K Mar 13 11:18  

It's the work of a virus, And I would like to undo it.

Update: I can't know for sure what is that character. As I try to move it like a space, and it doesn't work

$mv ' ' test
mv: cannot stat ` ': No such file or directory

Update: This is not a duplicate of delete a file with no name, although directory and file behave very similar in this case.

Saeed
  • 205

5 Answers5

4

One possible approach is to find the inode number for the directory, and use that to mv it. You don't tell us what platform you are using, so you might need to modify these suggestions to fit the tools available to you (I'm on FreeBSD).

Use your ls utility to get the inode number - the -i switch does that on FreeBSD:

$ ls -i
106739 test

(test is an empty directory I just created to illustrate this solution)

Now, you can use the find utility to find the directory with the inode number:

$ find . -inum 106739
./test

And to move the troublesome directory:

$ find . -inum 106739 -exec mv {} fixed \;
find: ./test: No such file or directory

Don't worry about the error message - it happens because the directory index changes during execution of the command, so find gets a bit confused; the directory has been renamed to fixed:

$ find . -inum 106739
./fixed

As I said, you may need to consult your local documentation to get the right switches, but this approach should work.

D_Bye
  • 13,977
  • 3
  • 44
  • 31
  • Fixed. Thanks for the hack. I was possible by files explorer through graphical interface. I just wanted to do it in CLI – Saeed Mar 13 '13 at 12:22
2

You can use:

mv ' ' <where you want to move>
favadi
  • 1,123
0

You need to find out what it is called, perhaps by something like

ls | od -c

Other thing to try is something like mv ? somewhere (if the name is one character), mv ?? somewhere (if it has two), ... The above od(1) command should tell the length, or from ls -b output.

If the name really is ' ' (one space), mv ' ' somewhere will work.

vonbrand
  • 18,253
0

You can do this by running these commands:

$ mv " "  ..target..

$ ls -al
-rw-r--r--  1 yupadhya Domain Users..0 Mar 13.. 19:28
drwxr-xr-x+ 1 yupadhya Domain Users     0 Mar 13 19:28 .
drwxrwxrwt+ 1 yupadhya Domain Users     0 Mar 12 10:19 ..
-rwxr-xr-x  1 yupadhya Domain Users  1494 Mar 12 10:16 .bash_profile
-rwxr-xr-x  1 yupadhya Domain Users  6054 Mar 12 10:16 .bashrc

$ mv /home

$ ls -al
total 8
-rw-r--r--  1 yupadhya Domain Users 0 Mar 13 19:28
drwxrwxrwt+ 1 yupadhya Domain Users 0 Mar 13 19:29 .
drwxr-xr-x+ 1 yupadhya Domain Users 0 Mar 12 13:14 ..

$ pwd
/home
Aditya
  • 964
Yogesh
  • 248
0

Use the dollar symbol to prevent the space character from being parsed, i.e

mv $' ' /path/to/folder

Otherwise it would not be treated as a parameter.

daisy
  • 54,555