Find the answer to your Linux question:
Results 1 to 3 of 3
I am writing a script which will need to read a list congaing files and directories, and delete them. Any advice? I'm actually stuck on the first step, how do ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10

    shell script that deletes files found in a list

    I am writing a script which will need to read a list congaing files and directories, and delete them. Any advice?

    I'm actually stuck on the first step, how do I read a list? I can choose the deliminator the list will use, so probably comma (,)

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    if you use newline \n as the list delimiter--

    /dir1/file1
    /dir2/file2

    like that, then something like this should work

    for i in `cat list`
    do
    rm $i
    done
    the sun is new every day (heraclitus)

  3. #3
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    change IFS to cater for files with spaces when using for loop and cat like that, otherwise, just use while read loop
    Code:
    while read -r line
    do
       rm -i "$line"
    done < "file"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...