Create File with Empty Name – How to Do It

filenamesfiles

I don't know how, but I created a file with an empty file name, I doubt there was a whitespace there (I'll explain why at the end):

chaouche@karabeela /mnt/ubuntu/storage $ ls
total 352K
drwx------  3 chaouche chaouche 4.0K Feb 12 11:00
drwxr-xr-x  4 chaouche chaouche 4.0K Apr 14 23:13 AUDIO
drwxr-xr-x  5 chaouche chaouche 4.0K Jul 20 22:25 BACKUPS
-rw-r--r--  1 chaouche chaouche 310K Jun 15 13:00 cv_yassine_chaouche_2012.pdf
drwxr-xr-x  2 chaouche chaouche 4.0K Jun 10 22:16 Mageia-3-i586-DVD
drwxr-xr-x  5 chaouche     1001 4.0K Oct 12  2012 MUSIQUE
drwxr-xr-x 15 chaouche chaouche 4.0K Oct 27  2012 PARISVIII
drwxr-xr-x  6 chaouche chaouche 4.0K Jun 12 18:33 SABAYON
drwxr-xr-x  5 chaouche chaouche 4.0K Jun 15 13:23 SIFTECH
drwxr-xr-x  5 chaouche chaouche 4.0K Feb  6 15:11 TOILES
drwxr-xr-x  4 chaouche chaouche 4.0K Jul 17 17:21 VIDEOS
chaouche@karabeela /mnt/ubuntu/storage $

I asked on #linux how to remove the file and a person suggested I moved all other files away then use the tab completion, which gave a very interesting behaviour :

# with tab completion
chaouche@karabeela /mnt/ubuntu/storage $ ls /
total 45M
-rwxr-xr-x  1 chaouche chaouche  34M Jan 16  2013 inkscape-0.48.4-1-win32.exe
-rwxr-xr-x  1 chaouche chaouche 8.6M Feb  4 11:42 mypaint-1.0.0-win32-installer.exe
-rwxr-xr-x  1 chaouche chaouche 2.7M Jan 17  2013 pdftkb_setup.exe

# without tab completion, wrote "/" by hand
chaouche@karabeela /mnt/ubuntu/storage $ ls /
total 212K
-rw-r--r--   1 root root    0 Apr 15  2012 1
drwxr-xr-x   2 root root 4.0K Dec  9  2012 bin
drwxr-xr-x   3 root root 4.0K Jun 15 12:10 boot
-rw-------   1 root root  74K Jul  1  2011 dead.letter
drwxr-xr-x  19 root root 4.2K Jul 20 20:14 dev
drwxr-xr-x 117 root root  12K Jul 20 21:30 etc
drwxr-xr-x   4 root root 4.0K Jun 12 18:40 home
drwxr-xr-x   2 root root 4.0K Jun  8  2011 initrd
drwxr-xr-x  20 root root  12K Dec  9  2012 lib
drwx------   2 root root  16K Jun  7  2011 lost+found
drwxr-xr-x   4 root root 4.0K Jul  3 01:56 media
drwxr-xr-x   9 root root 4.0K Apr 15 00:06 mnt
drwxr-xr-x   8 root root 4.0K Jun 30 23:19 opt
dr-xr-xr-x 198 root root    0 Jun 15 13:10 proc
drwxr-x---  28 root root 4.0K Jul 20 21:42 root
drwxr-xr-x   2 root root  12K Dec  9  2012 sbin
drwxr-xr-x   2 root root 4.0K Apr  3  2011 srv
drwxr-xr-x  12 root root    0 Jun 15 13:10 sys
-rw-r--r--   1 root root    0 Jun 12 18:40 thisismageia
drwxrwxrwt  69 root root  36K Jul 20 22:04 tmp
drwxr-xr-x  14 root root 4.0K Nov  6  2011 usr
drwxr-xr-x  18 root root 4.0K Jul  2  2011 var
chaouche@karabeela /mnt/ubuntu/storage $

If there was a whitespace in the filename it would have been replaced by \" " when I hit the tab key, but it didn't.

Best Answer

It is not possible to have a file with an empty name. What you have is a file whose name entirely consists of blank or non-printable characters.

To see exactly what the file name is, run LC_CTYPE=C ls -b. This replaces all blank or non-printable characters by octal escapes. For example, a file whose name is a single zero-width space would be listed as \342\200\213.

You can isolate this file with a glob that excludes files with a nice name. For example, you could try listing the files whose name doesn't begin with a letter.

chaouche@karabeela /mnt/ubuntu/storage $ ls -d [^A-Za-z]*

Don't forget the option -d, so that ls lists the directory itself and not its contents.

You should rename the file to have a reasonable name. You can rely on your shell's completion, or use a glob that matches only this file.

mv [^A-Za-z]* windows-programs
Related Question