Script required to delete a list of files?


Forum: Extension Development
Topic: Script required to delete a list of files?
started by: Juanito

Posted by Juanito on April 13 2008,05:56
In order to upgrade the versions of bison, pkg-config, expat, etc in compile-3.3.5, it would make life a lot easier if I had a script to delete a list of files. This would avoid starting again from the beginning and would avoid the hit or miss approach of hoping the new version of an app would completely overwrite the old version of an app.

If a list of files is produced by:
Code Sample
$ ./configure --prefix=/opt/test
$ make
$ touch mymarker
# make install
$ sudo find / -not -type 'd' -cnewer mymarker | grep -v "\/proc\/" | tee files

- then I was thinking I could replace "/opt/test/" with "/opt/compile-3.3.5/" in "files" and then call a script that would delete all the files in "files"

I would guess this would only require a couple of lines, but it is beyond my (almost non-existant) scripting ability...

Posted by ^thehatsrule^ on April 13 2008,06:03
Why not uninstall them?

If you still have the source tree that has the same configure options, you can run `make uninstall`

Posted by Juanito on April 13 2008,09:30
Ah, thanks - this did the trick:
Code Sample
$ ./configure --same options as when compiled
$ make
# make uninstall

Posted by ^thehatsrule^ on April 13 2008,17:15
Quote (Juanito @ April 13 2008,05:30)
Ah, thanks - this did the trick:
Code Sample
$ ./configure --same options as when compiled
$ make
# make uninstall

Well, if you're just reconfiguring it, you don't need to build it - just do make uninstall right after.
Posted by roberts on April 13 2008,17:32
Just to answer the original question, I find myself typing loops on the command line to process lists. Example:

# for F in `cat myfiles.lst`; do echo "$F"; done

This just echos back your list to insure that the loop is typed correctly.

I always start with a simple echo; just to be sure.

Sometimes I am paranoid and will then replace the echo with ls -1 to be sure that files that I think I am going to be processing are really there.

Then when I calm down I replace the command (echo or ls -1) with the actual command I wish to perform, usually sed -i, tr,awk, or rm

I know many times one could use find together with -exec, but that is not always available, so too, one could use find with xargs but I still uses loops on the command line.

Posted by Juanito on April 22 2008,08:38
Thanks:
Code Sample
$ for F in `cat files_list`; do echo "$F"; done [to test/double-check]
# for F in `cat files_list`; do rm "$F"; done
- does indeed delete the files in files_list

On a connected topic:
Code Sample
$ tar -tzf ../myapp.dsl > files_list
- will produce a list of files without the leading "/" required by the delete loop above. Is there a way to have the leading "/" without adding it by hand?

Posted by mikshaw on April 22 2008,12:54
The leading / is removed when the package is created.
Probably the easiest thing to do is "cd /" before removing files.

Posted by ^thehatsrule^ on April 22 2008,17:25
fyi, those code snippets would only work on filenames not containing whitespace.
You could set IFS to newline or use `while read LINE; do echo $LINE; done < filelist ` (which can be more resource friendly afaik)

Posted by mikshaw on April 22 2008,17:39
also, an alternative to cd:
while read LINE; do echo "/$LINE"; done < filelist

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.