Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Say I wanted to make sure I'm removing the right files first, so I did something like:

rm -i *

just to make sure that I'm okay with the files that I am removing. So this will ask me for each file. After a few files, suppose I realize it's exactly what I wanted to remove. Instead of CTRL+Cing and just doing rm *, is there a way I can just say Yes to all?

This question comes more so from curiosity rather than functionality.

share|improve this question
3  
thank god its just out of curiosity :) –  Shakehar Mar 26 '11 at 20:30
    
Strange question, but anyway, let's be creative in our answers! –  dolmen Mar 26 '11 at 20:45
add comment

6 Answers 6

up vote 5 down vote accepted

No.

(Unless you find a way to flip the 'interactive' bit with a debugger.)

share|improve this answer
    
[citation needed] :-) –  Daniel Beck Mar 26 '11 at 20:26
6  
@Daniel: coreutils/src/remove.c:335coreutils/lib/yesno.c:46 (generated) → rpmatch(3): "returns 0 for a recognized negative response ("no"), 1 for a recognized positive response ("yes"), and -1 when the value of response is unrecognized" –  grawity Mar 26 '11 at 20:40
    
Very nice find! –  Daniel Beck Mar 26 '11 at 20:45
3  
Also, you can just paste large number of y[line break] to terminal, which is not "Yes to all", but same thing happens. –  Olli Mar 26 '11 at 21:22
    
haha true for the 'y[linebreak]' thing, i like it! :) –  Amit Mar 31 '11 at 3:53
add comment

Well, this doesn't really answer your question. But instead of using rm -i, consider aliasing rm to rm -I:

The man page states:

-I     prompt once before removing more than three files, or when removing 
       recursively. Less intrusive than -i, while still giving protection 
       against most mistakes

in your ~/.bashrc, put:

 alias rm='rm -I'

this is actually useful!

share|improve this answer
    
Indeed I may consider doing this. Thanks –  Amit May 12 '11 at 4:01
add comment

Just check first using ls *.bla and then rm -f *.bla maybe?

Use caution!

share|improve this answer
    
haha true this is a possibility –  Amit Mar 31 '11 at 3:51
add comment

If you are running in screen (a good idea in general), you can do:

ctrl-a : exec .! yes y

This would cause screen to run the 'yes' command with y being the output, and direct said output to the running program (rm -i).

share|improve this answer
add comment

This can be done by replacing the application file descriptors on the fly. You'll need an intermediate file though.

You can use gdb and a named pipe like this (assuming you are using more terminals, else you have to use screen or something else):

  • create a named pipe with "mkfifo myYesYesPipe"
  • start the interactive copy with rm -i and find its PID
  • open gdb

Then type the following commands in gdb, replacing the PID

attach rmPID
call open("/path/to/myYesYesPipe",66,0666)
call dup2(3,0)
call close(3)
detach
quit

This replaces the keyboard with a named pipe for rm.

Now you have to fill the named pipe

  • run yes > /path/to/myYesYesPipe

rm will read the pipe and overwrite everything.

share|improve this answer
    
@grawity. you inspired me to use the debugger. –  David Costa Mar 27 '11 at 17:21
add comment
  1. Put the rm process in the background with Ctrl+Z.
  2. Recall the last command (the rm -i * command)
  3. Remove the -i
  4. Enter to run the command
  5. fg %1
  6. Ctrl+C
share|improve this answer
2  
5s/fg/kill/; 6d –  grawity Mar 26 '11 at 20:55
3  
How is this better than what the user explicitly mentioned he doesn't want to do? –  Daniel Beck Mar 26 '11 at 20:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.