Reputation: 1695
I am looking for a unix command to delete all files within a directory without deleting the directory itself. (note the directory does not contain subdirectories).
Upvotes: 10
Views: 62802
Reputation: 1
you can use rm -r /UrDir/*.*
This would ignore the files in the sub-directories
Upvotes: 0
Reputation: 1123
If you want to Delete all file as well as all Directory that means all things then try this:
rm -rf *
Upvotes: 1
Reputation: 4963
If you are in the directory where you want to remove all the files then the following command works fine:
rm *
Upvotes: 2
Reputation: 318508
You can use find /path/to/your/folder/ -delete
to delete everything within that folder.
While a wildcard rm
would braek with too many files ("Argument list too long"), this works no matter how many files there are.
You can also make it delete only files but preserve any subdirectories:
find /path/to/your/folder/ -type f -delete
You could also specify any other criteria find
supports to restrict the "results".
Upvotes: 4
Reputation: 2264
This will help you,
rm path/*
eg:
rm ../mydir/*
In this command,if mydir
has any sub_directory! it'll raise error an message and skip that sub_directory and remove rest of the files in main directory.
Upvotes: 0
Reputation: 131
you can remove all the files form the current directory using rm *
if you want to remove from a specific directory, type rm /path/*
Upvotes: 2
Reputation: 3070
try
rm -r yourDirectory/*
it deletes all file inside the "yourdirectory" directory
Upvotes: 7
Reputation: 6873
rm -i <directory>/*
this should do the trick
EDIT: added -i just in case (safety first). directory should be a full or relative path (e.g. /tmp/foo
or ../trash/stuffs
)
Upvotes: 10