read list of filenames from text file and remove these files in multiple directories

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-09-2007
read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like a combination of find, pipe, and xargs may work, but would like to consult some gurus. Thanks in advance!! >Smilie
# 2  
Old 03-10-2007
first you have to copy those files into a directory or any where else
Let us consider "fil1" and fil2 and so on......


find / -type f -name "fil*" -exec rm {} \;

if any help ...let us know
# 3  
Old 03-10-2007
Please give a try on this:

find dir_name -name file -print -exec tar -cvf arch.tar {} \; -exec rm -f {} \;
Ex:
find ./test_dir -name log_file* -print -exec tar -cvf log_arch.tar {} \; -exec rm -f {} \;

thank you.
# 4  
Old 03-10-2007
Quote:
Originally Posted by fxvisions
I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions ,

Does the file contain file names or file extensions?
Quote:
to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like a combination of find, pipe, and xargs may work, but would like to consult some gurus.

The best method will depend on the format of the file, the sanity of the filenames, etc.

The best way might be to move the files to another directory, then use whatever archiving method you like on that directory.

This code will retain the directory structure in the archive directory, so that multiple files of the same name can be accommodated:
Code:
archivedir=$HOME/arc
[ -d "$archivedir" ] || mkdir -p "$archivedir" || exit 1
while IFS= read -r file
do
  find . -name "$file" |
    while IFS= read -r f
    do
      dir=$archivedir/${f%/*}
      [ -d "$dir" ] || mkdir -p "$archivedir" || continue
      mv "$f" "$dir"
    done
done < FILE_WITH_LIST

# 5  
Old 08-07-2008
another solution maybe

i found this solutions in some forum lately...
it reads a list of files (with or without pathnames) from a file and removes/deletes them using rm.

Code:
xargs rm -rf </lists/blah.txt

this solutions seems to have a problem if using with files that contains SPACES and stuff..

others use this
Code:
 cat filename.txt | while read file; do rm "$file"; done

this worked for me on files with spaces.

Last edited by axel1973; 08-07-2008 at 07:06 AM..
# 6  
Old 08-07-2008
Quote:
Originally Posted by axel1973
i found this solutions in some forum lately...
it reads a list of files (with or without pathnames) from a file and removes/deletes them using rm.

Code:
xargs rm -rf </lists/blah.txt

this solutions seems to have a problem if using with files that contains SPACES and stuff..

Set IFS to a newline first, then it will work.
Quote:
others use this
Code:
 cat filename.txt | while read file; do rm "$file"; done


There is no need for cat:
Code:
while read file; do rm "$file"; done < filename.txt

Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I custom sort the files in a directory using the filenames in a text file.? KMusunuru UNIX for Beginners Questions & Answers 5 02-15-2017 09:49 PM
awk GSUB read field values from multiple text files dellanicholson UNIX for Beginners Questions & Answers 1 06-05-2016 11:37 PM
Read multiple text files and copy data to csv lp.descamps Shell Programming and Scripting 30 04-05-2016 06:34 PM
There are multiple filenames in the directory.How to return the the lastest files for each file name grand_sam Shell Programming and Scripting 4 02-18-2015 11:08 PM
Remove multiple lines from a text file prvnrk Shell Programming and Scripting 1 05-21-2014 07:47 AM
ls -ltr a list of filenames-with-spaces within a text file uschaafm UNIX for Advanced & Expert Users 4 11-28-2012 08:28 AM
Remove files from subdirectories given a list of filenames yogeshkumkar Shell Programming and Scripting 15 03-15-2012 02:09 PM
Remove filenames beginning with multiple dots sriharsharavi Shell Programming and Scripting 5 08-03-2011 01:00 PM
Need to remove multiple text from a single file jojo123 Shell Programming and Scripting 3 12-27-2009 12:04 PM
Shell Script Needed to Read a text from a list files kashriram Shell Programming and Scripting 4 11-13-2009 07:44 PM
Remove Duplicate Filenames in 2 very large directories jaysunn Shell Programming and Scripting 7 10-20-2009 09:34 PM
extract multiple cloumns from multiple files; skip rows and include filenames; awk manishabh Shell Programming and Scripting 4 08-18-2009 11:55 PM
a remove script taken in input a file which contain a list of directories yeclota Shell Programming and Scripting 2 09-09-2008 11:56 AM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 10:56 PM
All times are GMT -4. The time now is 05:19 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.