Find the answer to your Linux question:
Results 1 to 2 of 2
Hey guys, Im trying to write a script that uses a loop to generate a list of certain files. I've got files that end with .csv and files that end ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    1

    Script that Loops and searches for a specific file

    Hey guys,

    Im trying to write a script that uses a loop to generate a list of certain files. I've got files that end with .csv and files that end with .dat. I would also like it to delete the files one at a time. I hope I can get some help with this script, im still very very new in Linux.

    Thanks for your replies.

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    You can accomplish this with one command called 'find' as follows:

    Code:
    find . -maxdepth 1 -type f \( -name "*.csv" -o -name "*.dat" \) -exec rm -i {} \;
    The '.' after find means search the current directory. Replace the dot with the directory you want to search. The '-i' option for the rm command means it'll prompt you as to whether to delete the file or not.

Posting Permissions

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