![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| print as well as count the files found by find command | amicon007 | Shell Programming and Scripting | 3 | 02-05-2009 12:38 PM |
| find command in while loop - how to get control when no files found? | mavsman | Shell Programming and Scripting | 3 | 04-03-2008 12:44 PM |
| Files in Lost+Found | spricks | UNIX for Dummies Questions & Answers | 1 | 02-05-2008 11:26 AM |
| Monitoring a directory for new files with .xx and executing command if found | krkan | Shell Programming and Scripting | 4 | 03-14-2006 11:16 PM |
| variable not found with loop? | douknownam | Shell Programming and Scripting | 2 | 09-27-2004 11:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Loop through found files
Hi I am trying to write a script which will loop through all files that end in ".txt" and ask user if they want to delete the file or not Code:
#this print out all files dir=/root/etc/ find $dir -name "*.txt" output: 1.txt 2.txt etc but what i really want is 1.txt delete(Y/N): 2.txt delete(Y/N): etc I have tried loops for example Code:
for file $dir in "*.txt"; do echo "$file delete (y/n)" done but they dont seem to be working, any ideas are very much appreciated thanks |
|
||||
|
First of all thanks for the replies, the set of commands dont exactly do what i want though unfornutely @radoulov Is it possible to modify this slightly to ask the user first before deleting, I have been trying to play around with but cant figure out correct syntax Code:
find $dir -name "*.txt" -exec echo "delete y/n" {} \; read x {} \;
@cfjohnson this doesnt seem to search the correct directory, I found an example which will search the correct dir e.g. Code:
for file in `find $dir -name "*.txt"`; do The only problem is that some files have spaces in their names for example "/etc/space inFilename" and then it prints the file out twice ie /etc/space inFilename is there anyway to print it out as one? Thanks again Calypso |
|
||||
|
@cfajohnson Im afraid it still doesnt seem to work, now the script takes out all spaces so when i do Code:
find $dir -name "*.txt" | while IFS= read -r file; do mv -i $file `echo file | sed 's/ //g'` done i just get the following errors /etc/file: No such file or directory name: No such file or directory |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|