Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to loop directory, read, and delete

Status
Not open for further replies.

web4fun

MIS
Oct 2, 2002
127
US
Was wondering if anyone had / knew of a simple k-shell script that will use a loop to generate a list of the files that end in .csv and .dat to be deleted, and delete the files one at a time in the loop after I read them. I would be running this on a Red Hat server.

Apologies as I'm new to scripting and would love some assistance.

Thanks in advance.
 
Sorry..instead of Red Hat, it would be on a server running Fedora 8.
 
rm -i *.csv

this is an interactive remove. If you don't type "y" it will not remove, then it goes to the next file and prompts again.

delete or control C will quit out of the commmand


A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"

bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
you actually want to loop, view and then be prompted to delete after each view?

Code:
for file in `ls *.csv`;do
    less $file
    echo -n "delete $file? [y/n]: ";read delete
    [ $delete = "y" ] && rm $file
done

switch out less with whatever you want to use to view the csv.
 
Thanks to all. Yes, exsnafu I actually want to loop, view and then prompted to delete after each view so this would be perfect. Thank you so much.
 
exsnafu.........

Will that work in bash?

[root@netwatch ~]# yum remove windows
Loaded plugins: fastestmirror
Setting up Remove Process
No Match for argument: windows
No Packages marked for removal

OH YEAH!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top