Evan Cutler
asked on
how to delete files but preserve subfolders in unix
greetings,
I have a master folder.
In the master folder, I have files and subfolders.
I want to delete the files but retain the subfolders.
rm -f * attempts to remove the subfolders and throws errors.
Thanks
I have a master folder.
In the master folder, I have files and subfolders.
I want to delete the files but retain the subfolders.
rm -f * attempts to remove the subfolders and throws errors.
Thanks
ASKER
Thanks seth, but that deletes all files in the subfolders as well.
Can we limit to current folder?
Can we limit to current folder?
then the command you have will do what you want so not sure what the issue is
that command without -R will not be recursive; it will see the folder, knows it can't remove it because it's a folder and -R wasn't specified and reports an error which is expected behaviour
that command without -R will not be recursive; it will see the folder, knows it can't remove it because it's a folder and -R wasn't specified and reports an error which is expected behaviour
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you so much guys.
I used an ls command to find the files and then removed them.
ls |grep -v ^d|xargs rm -f
I used an ls command to find the files and then removed them.
ls |grep -v ^d|xargs rm -f
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for arcee123's comment #a39534364
for the following reason:
This solution was more stable in my environment using SOLARIS.
I thank you guys very much...
Accepted answer: 0 points for arcee123's comment #a39534364
for the following reason:
This solution was more stable in my environment using SOLARIS.
I thank you guys very much...
Your ls command does not work because ls shows you names of files and folders. The grep removes both files and folders from the list that start with a d
I think you would mean:
ls -l | grep -v ^d | xargs rm -f
but that would give you output containing security files, size etc. so the rm would fail (or at least give a whole bunch of errors).
Did you check my last comment? It works, why no accept that?
I think you would mean:
ls -l | grep -v ^d | xargs rm -f
but that would give you output containing security files, size etc. so the rm would fail (or at least give a whole bunch of errors).
Did you check my last comment? It works, why no accept that?
I object to the way this question is closed, the solution does not work on Linux. Closing comment is now mentioning SOLARIS which was never in the original question.
ASKER
I am on Solaris.
This worked there.
This worked there.
ASKER
Admin,
if you can, please grant the points if it's allowable.
I just don't know how to handle this.
Thanks
if you can, please grant the points if it's allowable.
I just don't know how to handle this.
Thanks
Open in new window