4

Using the rm 'filename' command, i have noticed that the file isn't actually deposited into the trash. I realise that this isn't completely removing the file from the computer, however im perplexed as to why it would not appear in the trash?

In short:

Why doesn't the 'rm' command deposit file in trash.

1

3 Answers 3

11

rm is a standard Unix command and Unix does not always have trash. At the programming level the BSD API does not have a system call to trash a file, Apple supplies those at a higher level.

Also you need a command that deletes files e.g. to remove them from trash and rm happens to be it. You need another command to put a file in trash.

1
  • I think that the command that emulates (is executed) when Secure Empty Trash is run is srm not simply rm. From man srm srm removes each specified file by overwriting, renaming, and truncating it before unlinking. This prevents other people from undeleting or recovering any information about the file from the command line.
    – AMR
    Commented Jul 22, 2015 at 21:47
4

Actually when you use 'rm' you are deleting the file directly. When you delete a file from the Finder it actually moves it to the Trash, that is it doesn't delete it.

If you want to move the file to the Trash instead of deleting it try:

mv fileName ~/.Trash/

What this does is it moves the file called fileName to your user's trash. The '~' means your user's directory and .Trash is your trash (the dot before Trash means it's a hidden file). After trying this command open the Trash from the finder and your file should be there.

Also, if you want to play around with files I would recommend to use fictitious files. You can easily create files using the touch command which creates an empty file if it doesn't exist:

touch newFile

So if you want to test my solution you should do this (where $ is the prompt):

$touch newFile
$mv newFile ~/.Trash/

And you should see newFile in the Trash.

3
  • Moving a file to the Trash in the Finder , moves the file to its respective Trash directory on that file system. Your proposal can be dangerous.
    – fd0
    Commented Jul 7, 2015 at 15:27
  • That's why I recommend using fictitious files so you don't mess up you system :o
    – loco.loop
    Commented Jul 7, 2015 at 15:40
  • When you trash a file from Finder, it remembers the old path, and you can “Put Back” later. mv fileName ~/.Trash/ doesn’t do that. Commented Apr 16, 2021 at 1:58
1

You may want to use rmtrash (available on http://www.nightproductions.net/cli.htm or using homebrew), which moves a file to the trash.

1
  • What’s the name of the Homebrew formula? I tried brew search rmtrash and found nothing. Commented Apr 16, 2021 at 1:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .