2

I am going through a hard time trying to delete three empty directories that were created after an aborted process of "wiping free disk space" of bleachbit, I've used every suggested method and none seem to work, I tried shredding them with bleachbit and deleting using commands like rm -d, rm -f, rm -r, I tried renaming them, moving them, I even replaced Ubuntu 16.04 with 17.04 on the off chance that what's wrong will be fixed, but they're still there.

The directories are in separate partition and not in the home directory. Their names are as follows:

  1. -9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0z1A62Sh25BS0pYZEby6JDVvtMZavFTCUgQUpjuJUCZ0pKspQLd40O3Zc9rzgGRFcxNBKOgr7KnVwZw_A4kkx4R9zq1oON8aP4y00EY0AuIJYRdCs9v9oYNKrFasQoMXwuLiw5lh0Z8J6Jh8u8pjDNnP31p0oBYsjTQTPUE1MXVqgAuWNjrhtEFuouXKR
  2. CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC
  3. qoRSRba1C8bPYrpk_5OW6Qi9mPC.zhyzqUwivpQfArgb9

Whenever I try something I get this message that says:

No such file or directory

here are some of the output:

me@MyPC:~$ rm -f /media/me/702E29F142F/-9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0‌​z1A62Sh25BS0pYZEby6J‌​DVvtMZavFTCUgQUpjuJU‌​CZ0pKspQLd40O3Zc9rzg‌​GRFcxNBKOgr7KnVwZw_A‌​4kkx4R9zq1oON8aP4y00‌​EY0AuIJYRdCs9v9oYNKr‌​FasQoMXwuLiw5lh0Z8J6‌​Jh8u8pjDNnP31p0oBYsj‌​TQTPUE1MXVqgAuWNjrht‌​EFuouXKR

me@MyPC:~$ rmdir -- $ 'CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC'
rmdir: failed to remove '$': No such file or directory
rmdir: failed to remove 'CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC': No such file or directory

me@MyPC:~$ rmdir -- 'CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC'
rmdir: failed to remove 'CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC': No such file or directory

me@MyPC:~$ rmdir 'CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC'
rmdir: failed to remove 'CD09GzmqmJfZ2rBA5rtBsWR1EAewq-fZWJCJhlO6r1aC': No such file or directory

me@MyPC:~$ rmdir -- -9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0z1A62Sh25BS0pYZEby6JDVvtMZavFTCUgQUpjuJUCZ0pKspQLd40O3Zc9rzgGRFcxNBKOgr7KnVwZw_A4kkx4R9zq1oON8aP4y00EY0AuIJYRdCs9v9oYNKrFasQoMXwuLiw5lh0Z8J6Jh8u8pjDNnP31p0oBYsjTQTPUE1MXVqgAuWNjrhtEFuouXKR
rmdir: failed to remove '-9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0z1A62Sh25BS0pYZEby6JDVvtMZavFTCUgQUpjuJUCZ0pKspQLd40O3Zc9rzgGRFcxNBKOgr7KnVwZw_A4kkx4R9zq1oON8aP4y00EY0AuIJYRdCs9v9oYNKrFasQoMXwuLiw5lh0Z8J6Jh8u8pjDNnP31p0oBYsjTQTPUE1MXVqgAuWNjrhtEFuouXKR': No such file or directory

me@MyPC:~$ sudo rmdir -- -9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0z1A62Sh25BS0pYZEby6JDVvtMZavFTCUgQUpjuJUCZ0pKspQLd40O3Zc9rzgGRFcxNBKOgr7KnVwZw_A4kkx4R9zq1oON8aP4y00EY0AuIJYRdCs9v9oYNKrFasQoMXwuLiw5lh0Z8J6Jh8u8pjDNnP31p0oBYsjTQTPUE1MXVqgAuWNjrhtEFuouXKR
rmdir: failed to remove '-9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0z1A62Sh25BS0pYZEby6JDVvtMZavFTCUgQUpjuJUCZ0pKspQLd40O3Zc9rzgGRFcxNBKOgr7KnVwZw_A4kkx4R9zq1oON8aP4y00EY0AuIJYRdCs9v9oYNKrFasQoMXwuLiw5lh0Z8J6Jh8u8pjDNnP31p0oBYsjTQTPUE1MXVqgAuWNjrhtEFuouXKR': No such file or directory



me@MyPC:/media/me/702E29F142F2362F$ rmdir -- $'qoRSRba1C8bPYrpk_5OW6Qi9mPC.zhyzqUwivpQfArgb9'
rmdir: failed to remove 'qoRSRba1C8bPYrpk_5OW6Qi9mPC.zhyzqUwivpQfArgb9': No such file or directory

When I try moving it to trash or deleting using Nautilus, it looks like this:

Nautilus showing a similar "No such file or directory" error

Eliah Kagan
  • 119,640
AliOuld
  • 21

2 Answers2

5

Some of your names start with -, so pass -- first or use an absolute path.

For empty directories, use the rmdir command and write -- as a separate word before name of the first directory to remove. If -- has not been passed (this applies to the commands you've tried as well as rmdir) then words that begin with - will be interpreted as collections of options controlling how the command behaves rather than as filenames for the command to operate on.

You will have to write your commands based on the directory names you have. Because of possible errors in formatting the filenames in the Stack Exchange visual editor, this is a case where I don't recommend copying directly from this answer. However, as an example which I expect you to modify as needed, if you have a directory whose name is:

-9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0‌​z1A62Sh25BS0pYZEby6J‌​DVvtMZavFTCUgQUpjuJU‌​CZ0pKspQLd40O3Zc9rzg‌​GRFcxNBKOgr7KnVwZw_A‌​4kkx4R9zq1oON8aP4y00‌​EY0AuIJYRdCs9v9oYNKr‌​FasQoMXwuLiw5lh0Z8J6‌​Jh8u8pjDNnP31p0oBYsj‌​TQTPUE1MXVqgAuWNjrht‌​EFuouXKR

And it is empty, and you are in its parent directory (you can use cd to go there and pwd to check what directory you are currently in), then you can remove it like this:

rmdir -- -9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0‌​z1A62Sh25BS0pYZEby6J‌​DVvtMZavFTCUgQUpjuJU‌​CZ0pKspQLd40O3Zc9rzg‌​GRFcxNBKOgr7KnVwZw_A‌​4kkx4R9zq1oON8aP4y00‌​EY0AuIJYRdCs9v9oYNKr‌​FasQoMXwuLiw5lh0Z8J6‌​Jh8u8pjDNnP31p0oBYsj‌​TQTPUE1MXVqgAuWNjrht‌​EFuouXKR

Or, if it's owned by root or you otherwise don't have permissions to remove it:

sudo rmdir -- -9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0‌​z1A62Sh25BS0pYZEby6J‌​DVvtMZavFTCUgQUpjuJU‌​CZ0pKspQLd40O3Zc9rzg‌​GRFcxNBKOgr7KnVwZw_A‌​4kkx4R9zq1oON8aP4y00‌​EY0AuIJYRdCs9v9oYNKr‌​FasQoMXwuLiw5lh0Z8J6‌​Jh8u8pjDNnP31p0oBYsj‌​TQTPUE1MXVqgAuWNjrht‌​EFuouXKR

Notice that there is a space after the -- argument. That is important.

Or you can use the full path of the directory. Then you don't have to worry about what directory you are in when you run the command and the -- is optional. For example (based on what you showed in a comment):

rmdir /media/me/702E29F142F/-9tDCcQrfg8u8e.AlOYZ7DX0q-ZRR77j9q8Gq0‌​z1A62Sh25BS0pYZEby6J‌​DVvtMZavFTCUgQUpjuJU‌​CZ0pKspQLd40O3Zc9rzg‌​GRFcxNBKOgr7KnVwZw_A‌​4kkx4R9zq1oON8aP4y00‌​EY0AuIJYRdCs9v9oYNKr‌​FasQoMXwuLiw5lh0Z8J6‌​Jh8u8pjDNnP31p0oBYsj‌​TQTPUE1MXVqgAuWNjrht‌​EFuouXKR

(Or with sudo rmdir, as above.)

Some names may contain characters that require quoting.

If that doesn't help and you continue getting the same No such file or directory message, then the problem is that you aren't successfully naming the directories. Presumably their names contain unusual characters.

It's not obvious that this is the case based on what you have shown but it is a common problem so I'm including it just in case. If your directory names contain spaces or other characters treated specially by the shell like line breaks, *, or $, then you should enclose the names in single quotes. This will be sufficient so long as the names themselves do not contain any single quotes.

More generally, if you've used cd to get to the directory that contains these directories, you should be able to get a list of entries in that directory (including the subdirectories you're interesting in removing) by running:

ls -1b

This differs from an ordinary ls command in two useful ways:

  • The -b flag causes the paths to be printed with escape sequences which can be pasted between $' '. No space should appear between the initial $ and the opening ' character.
  • The -1 flag makes ls list one entry per line. That can help decrease confusion about where one filename ends and the next begins.

This should enable you to write commands that remove, rename, etc. these directories. If they are truly empty, you can then use the rmdir command to remove them. You may need to run this command as root, which you can do with sudo.

Here's a deliberately oversimplified illustration of what commands you might run. Supposed ls -1b listed:

abc\ def
ghi\njkl
pqr\b\b\bstuv
$$$$$$$\b\b\b$$$

In the first case there is a space. In the second case there is a newline (a line break). In the third case, there are three backspace characters. In the fourth case, which there are both $ and backspace characters.

To remove those directories you could use:

rmdir -- $'abc\ def'
rmdir -- $'ghi\njkl'
rmdir -- $'pqr\b\b\bstuv'
rmdir -- $'$$$$$$$\b\b\b$$$'

As above, you may need sudo.

rmdir can take multiple filenames but if you use one command per removal then it may be easier to understand whatever error messages you receive, if any.

In those particular examples, the directory names did not start with - and the -- flag was not necessary. But it did not do any harm.

$' ' versus plain ' '

Unlike quoting with ' ', quoting with $' ' causes backslash escapes like \n and \b to be expanded.

'ghi\njkl' identifies a file whose name is literally:

  • ghi\njkl

In contrast, $'ghi\njkl' identifies a file whose name is:

  • ghi jkl

If you're running a graphical file browser, you may be able to drag from it.

With some graphical file browsers (such as Nautilus, i.e., "Files") and some terminals (such as GNOME Terminal), there is an even easier way to get a usable absolute path to a file in a terminal command that you are writing.

This will work on most Ubuntu systems that have a graphical user interface installed but it will pretty much never work when you're logging in remotely via SSH.

You can drag the folder from the file browser window into the terminal window to paste the full path to it in the terminal. With your mouse over the terminal window, release the button.

For this to be useful, the best approach is to write the command you want to run first. For example, write this and include a space at the end but don't press Enter yet:

rmdir --

Then drag the folder from the file browser window into the terminal window. If your file browser and terminal emulator support it, you should see a path pasted, with \ or ' based quoting automatically provided. You can then press Enter to run the command. Even if the command does not succeed, this will usually give a more useful error message than No such file or directory.

Eliah Kagan
  • 119,640
2

Graphical method

I would use nautilus the file manager built into Ubuntu. Simply highlight the directories, right-click and select "send to trash". If directories have large files you might want to empty trash right away.

If the directories are owned by root Nautilus won't let you delete them. In this case open a terminal and use:

gksu nautilus

Can't move to trash but can delete directly

According to this Linux Mint question some Windows files can't be moved to trash but can be deleted directly.

Another answer in this thread points out how to find out the file system type using:

df -T /media/<path_to_project_folder>

Then changing the /etc/fstab entry worked for mounting using different parameters and successfully deleting the files.


Terminal Method

As per this Super User Q&A you can delete files with special characters (weird names) by changing to the directory containing them and using:

rm -i -- *

This will prompt you to delete each file. You can and should change '*' to a narrower match if there are a lot of files. The -- stops processing options, so a file named -d will be removed by rm successfully.

Another answer in the same thread proposes deleting by inode number using. It says you can use ls -li to show all files by their inode. Then run this command to remove the file:

find . -inum ${INODE_NUM} -delete

You can add -maxdepth 1 to my find just to be safe:

find . -maxdepth 1 -inum ${INODE_NUM} -delete