toop toop - 9 months ago 39
Bash Question

unix - delete files only from directory

Say with a directory structure such as:

toplev/
file2.txt
file5.txt
midlev/
test.txt
anotherdirec/
other.dat
myfile.txt
furtherdown/
morefiles.txt
otherdirec/
myfile4.txt
file7.txt


How would you delete all files (not directories and not recursively) from the 'anotherdirec'? In this example it would delete 2 files (other.dat, myfile.txt)

I have tried the below command from within the 'midlev' directory but it gives this error (
find: bad option -maxdepth find: [-H | -L] path-list predicate-list
):

find anotherdirec/ -type f -maxdepth 1


I'm running SunOS 5.10.

Answer
rm anotherdirec/*

should work for you.