Linux / UNIX Tech Support Forum
This is a discussion on Shell script to delete all files with .html extension in a folder within the Shell scripting forums, part of the Development/Scripting category; Hi all..I am very much new to shell scripting and I am highly interested to learn this as I can ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
| Sponsored Links | ||
|
|
|
||||
|
No need to write a shell script, simply use find command. In this example, list all *.html files stored in /path/to/dir:
Code:
find /path/to/dir -iname "*.html" Code:
find /path/to/dir -iname "*.html" -delete Code:
#!/bin/bash # Task: Clean html files # add your find command here find /dir1 -iname "*.html" -delete find /dir2 -iname "*.html" -delete
__________________
Vivek Gite Linux Evangelist |
| The Following User Says Thank You to nixcraft For This Useful Post: | ||
vamsi (24-11-2009)
| ||
|
||||
|
See our cron job FAQ:
__________________
Vivek Gite Linux Evangelist |
| The Following User Says Thank You to nixcraft For This Useful Post: | ||
vamsi (24-11-2009)
| ||
|
||||
|
If your version of find does not support the delete option you can use the following when deleting files.
Code:
find /path/to/dir -iname "*.html" -exec rm -f {} \; -print
HTH, jaysunn |
| The Following User Says Thank You to jaysunn For This Useful Post: | ||
vamsi (24-11-2009)
| ||
|
||||
|
Good point, also take a look at xargs (for speed) and print0 (files with spaces).
__________________
Vivek Gite Linux Evangelist |
| The Following User Says Thank You to nixcraft For This Useful Post: | ||
vamsi (24-11-2009)
| ||
|
|||
|
Quote:
|
|
||||
|
Hello
To avoid pressing y 1000 times after running the rm command without the -f option. Use this if you are in the directory that contain the html files. Code:
rm -f *.html Jaysunn |
|
||||
|
Quote:
Only if you want to clear all *.html files from the current directory. If you need to process 10-20 subdirs, find is handy tool, IMO. On a related not what do you think of using find ... | xargs rm syntax instead of find .... -exec rm syntax? |
|
||||
|
Quote:
Quote:
Code:
\rm *.html /bin/rm *.html
__________________
Vivek Gite Linux Evangelist |
|
||||
|
Yes due to the O/P's O/S. I explained that the rm without the -f option will be unbearable to run.
Quote:
Code:
[root@radio5 testing]# rm *.html rm: remove regular empty file `a.html'? y rm: remove regular empty file `b.html'? y rm: remove regular empty file `c.html'? y rm: remove regular empty file `d.html'? y rm: remove regular empty file `e.html'? y rm: remove regular empty file `google45648f09a80004b1.html'? y rm: remove regular empty file `googlec628fdecd594064c.html'? y rm: remove regular file `index.html'? y rm: remove regular file `jason.html'? y [root@radio5 testing]# Jaysunn |
![]() |
| Tags |
| /etc/cron.daily , centos find file , find , find -delete , find and delete html files , find cron job , find file linux |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to Give free space on hard disk & propose a list of files to be delete | manike | Shell scripting | 1 | 30-05-2009 09:31 PM |
| shell script to zip old files and then delete | shankar43 | Shell scripting | 2 | 13-03-2009 09:10 AM |
| A script for Removing all the files inside a folder and its sub folder | vivekv | Shell scripting | 1 | 25-10-2007 01:44 PM |
| i need a script to delete one folder with files on my ftp | silver_ch | Shell scripting | 1 | 27-03-2007 10:15 AM |
| HTML Program cannot open in cgi-bin folder | sonaikar | Linux software | 5 | 04-02-2005 04:45 PM |