LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Deleting files (https://www.linuxquestions.org/questions/linux-newbie-8/deleting-files-41725/)

Tingle 01-16-2003 02:00 PM

Deleting files
 
Hi,

I apologise for the simple question (but the title does say where newbies come for help!)

I want to delete all the contents in a folder bar one called index.html however, they are all write protected so it asks me to confirm each one

Is there a way to force it to delete them?

I need to make a cron script to clean out a directory but the files inside are read only basically

Thanks in advance

iceman47 01-16-2003 02:06 PM

The manpage (man rm) says:

-f, --force
ignore nonexistent files, never prompt

Tingle 01-16-2003 02:34 PM

how about telling it to remove all the files in the directory apart from index.html? (without removing the directory itself, or those within)

Thanks

iceman47 01-16-2003 04:16 PM

Can't think of something how to do that right now, except for:
(this is an ugly workaround, but it'll work)
Code:

#!/bin/bash
mv /home/Tingle/foo/index.html /tmp/
rm -f /home/Tingle/foo/*
mv /tmp/index.html /home/Tingle/foo/

where foo is the name of the directory you want to have everything cleaned except index.html.
[edit: typo in code]

Tingle 01-16-2003 04:19 PM

Managed to find an alternative solution:

remove the directory with everything in it, readd it, chmod the new one, then untar a file containing the index.html in the appropriate directories

It works ok so that should do :)


All times are GMT -5. The time now is 06:48 AM.