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.

  • I created it and was able to move it with $mv ' ' test Are you using Ubuntu? (I am). – Michael Durrant Mar 13 '13 at 11:37
  • I'm Fedora linux, but I don't think that's the issue. As I said, it's not actually a space. It's ` ' – Saeed Mar 13 '13 at 12:03
  • If it was a virus, don't rename the directory. Nuke the whole installation from orbit (i.e. do a full OS reinstall). – Gilles 'SO- stop being evil' Mar 13 '13 at 21:10
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.

  • 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>
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.

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
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.