0

How do I move all the files and all the folders from the current directory to the Trash on the command line in Terminal.app?

Apple says to use mv command. But that page describes only single files or single folders.

I tried this:

mv * ~/.Trash 

That moves all the files but leaves behind any nested folders.

Console messages:

mv: rename assets to /Users/basil_dot_work/.Trash/assets: Directory not empty … 

I want to completely empty the current folder. (Well maybe leave behind the hidden files that make the Finder happy.)

9
  • Really, it doesn't move everything? * is expanded by Zsh. Show output of ls -la before and after running mv. Commented Apr 11 at 20:36
  • * should match all files and folders, except the ones that begin with .. Commented Apr 11 at 21:00
  • @Barmar Nope, leaves behind multiple folders. I’ve done it multiple times. The folders can be manually dragged to trash in the Finder, so I don’t think it is a permissions issue. Commented Apr 11 at 21:31
  • If you do echo * do you see those folders in the output? Commented Apr 11 at 21:31
  • Do you get any error messages saying why it's not moving those folders? Commented Apr 11 at 21:32

1 Answer 1

2

Solution: trash command

See this Answer on similar Question, How to move files to trash from command line?.

macOS 15 Sequoia offers a new command-line tool: trash

To empty the current folder, merely run:

trash * 

All files, and all folders, are moved to the user’s Trash folder.

The man page says:

TRASH(8) System Manager's Manual TRASH(8) NAME trash – Moves files and directories to the user trash folder SYNOPSIS trash [-h] [--help] [-s] [-stopOnError] [-v] [--verbose] FILE [FILE...] DESCRIPTION The trash moves files and directories into the user trash folder. The options are as follows: -h | --help display usage information for the tool and exit -v | --verbose display more verbose status -s | --stopOnError exit with an error if any move to a trash folder fails EXAMPLES In a directory with a file named "Foo.txt" and a directory "Bar", trash Foo.txt Bar moves the file and directory into the user's trash folder, if it exists and permissions allow the items to be moved into the user's trash folder. HISTORY First appeared in macOS 14.0 macOS May 25, 2022 

Reportedly that last line about being in macOS 14 Sonoma is incorrect. People say only 15 Sequoia and later has trash command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.