1

Let's say I ran a command that redirected certain files from a directory into a file. Now i want to delete those files from the directory. How would i accomplish this. I'm thinking that i would maybe use a for loop and read each line of the file and then run a command to remove it? I don't need the whole code just a little help to get started. I would like to do this using bash.

1
  • Never mind. I would just run the same command and use rm or xargs rm . Sorry dumb question its still early . Jan 14, 2021 at 15:39

1 Answer 1

0

similar to for loop. that will list all files in ~/test. replace ls with rm

dir="$HOME/test"

while IFS= read -r file || [ "$file" ]
  do
    [ -f "$dir/$file" ] || continue
    ls "$dir/$file"
done < index.txt
1
  • Thank you for you response. This worked for me Jan 18, 2021 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .