LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   alias for rm directory - prompt (https://www.linuxquestions.org/questions/linux-newbie-8/alias-for-rm-directory-prompt-4175579335/)

publicLearner 05-09-2016 11:19 AM

alias for rm directory - prompt
 
Hi members,
I've an alias for rm to prompt whenever I delete any file as:

Code:

#Make rm as interactive
alias rm='rm -i'

I've this in my .bashrc file.

This works as good as I had wanted.

Is there a way I could alias for rm -rf, and fuse it with interactive flag?

Any guidance would be highly appreciated.

Habitual 05-09-2016 11:41 AM

Based upon your .bashrc, anyh occurrence of rm should automatically include -i so an
Code:

rm -fr
would actually be
Code:

rm -ifr

lazydog 05-09-2016 11:43 AM

If you have an alias setup say
Code:

rm='rm -i'
but you what to use rm in its raw form then you should just need to escape it like
Code:

\rm -rf
and it should work.

publicLearner 05-10-2016 10:03 AM

Quote:

Originally Posted by Habitual (Post 5542719)
Based upon your .bashrc, anyh occurrence of rm should automatically include -i so an
Code:

rm -fr
would actually be
Code:

rm -ifr

Hi habitual,
Thanks for your reply.
Unfortunately, this doesn't happen when I remove directory. :(

Habitual 05-10-2016 10:12 AM

open a terminal and issue:
Code:

type rm
and paste the output please.

Nevermind. That's a strange one.

Directories get clobbered silently.

Code:

type rm
rm is /bin/rm

mkdir -pv var/named
mkdir: created directory ‘var’
mkdir: created directory ‘var/named’

alias rm="rm -i"
rm -fr var/
cd var/
bash: cd: var/: No such file or directory

Files get prompted
Code:

touch xyz

type rm
rm is aliased to `rm -i'

rm  xyz
rm: remove regular empty file ‘xyz’?

Works on files but not directories (which are files, hello)?

I guess I'm missing something basic. Can I blame too much|little caffeine?

publicLearner 05-10-2016 10:14 AM

Quote:

Originally Posted by lazydog (Post 5542721)
If you have an alias setup say
Code:

rm='rm -i'
but you what to use rm in its raw form then you should just need to escape it like
Code:

\rm -rf
and it should work.


Hi lazydog,
Thank you for your reply.

Code:

rm one.txt
This prompts for Y, N.

mkdir out_rm

But
Code:

\rm -rf out_rm
doesn't work for a prompt.

publicLearner 05-10-2016 10:15 AM

Quote:

Originally Posted by Habitual (Post 5543253)
open a terminal and issue:
Code:

type rm
and paste the output please.

Hi,
Please see the output:

Code:

$ type rm
rm is aliased to `rm -i'


Habitual 05-10-2016 10:20 AM

I edited

I'm stumped, for now. ;)

publicLearner 05-10-2016 10:36 AM

Quote:

Originally Posted by Habitual (Post 5543253)
open a terminal and issue:
Code:

type rm
and paste the output please.

Nevermind. That's a strange one.

Directories get clobbered silently.

Code:

type rm
rm is /bin/rm

mkdir -pv var/named
mkdir: created directory ‘var’
mkdir: created directory ‘var/named’

alias rm="rm -i"
rm -fr var/
cd var/
bash: cd: var/: No such file or directory

Files get prompted
Code:

touch xyz

type rm
rm is aliased to `rm -i'

rm  xyz
rm: remove regular empty file ‘xyz’?

Works on files but not directories (which are files, hello)?

I guess I'm missing something basic. Can I blame too much|little caffeine?

Hi habitual,

Thanks for your time, and reply.
By files I refer to as .txt, .fasta, .c, .py, .php, .cpp, .hpp, .h, .js, .etc, any random document/file present in any directory.

Code:

touch file.txt
rm file.txt

I'll get a prompt.
I think we're on the same page, and not misunderstanding any thing.
By directories, I refer to folders.

Yes, it is a strange.
I wanted to be more wary while using rm, and thus, looking out for options that could make it interactive. :)

Habitual 05-10-2016 10:44 AM

Quote:

Originally Posted by publicLearner (Post 5543268)
I'll get a prompt.
I think we're on the same page, and not misunderstanding any thing.
By directories, I refer to folders.

I believe so, yes.

Since I have the same .bashrc I've had for about 5 years, the only interactive rm'ing I see are on remote hosts, servers all.
I suspect rm has been "made interactive" in recent desktops.

On remote hosts, at the very first prompt on "rm /some/file" I hit control+C
and then issue the same command with
Code:

\rm some/file
I consider interactive to be more for Desktop Users than experienced admins.

keefaz 05-10-2016 10:51 AM

The -f switch takes precedence over -i, no?

edit
Code:

rm -rfi # interactive
rm -rif # rm with no question


Habitual 05-10-2016 11:00 AM

Quote:

Originally Posted by keefaz (Post 5543277)
The -f switch takes precedence over -i, no?

edit
Code:

rm -rfi # interactive
rm -rif # rm with no question


Code:

-f, --force
              ignore nonexistent files and arguments, never prompt

I knew it was easy.
I'm gonna say too much caffeine on this one! (facepalm)

Thanks!

publicLearner 05-10-2016 11:05 AM

Quote:

Originally Posted by Habitual (Post 5543283)
Code:

-f, --force
              ignore nonexistent files and arguments, never prompt

I knew it was easy.
I'm gonna say too much caffeine on this one! (facepalm)

Thanks!

haha.
Oh! I see. :D

@habitaul, keefaz, lazydog
Thank you very much for digging this one out. :)

keefaz 05-10-2016 11:08 AM

Quote:

Originally Posted by Habitual (Post 5543283)
Code:

-f, --force
              ignore nonexistent files and arguments, never prompt

I knew it was easy.
I'm gonna say too much caffeine on this one! (facepalm)

Thanks!

Not so easy, on my system the -i takes priority over -f if placed after -f when invocating rm options

eg
Code:

rm -rif => f takes priority over i
rm -rfi => i takes priority over f


Habitual 05-10-2016 11:39 AM

Quote:

Originally Posted by keefaz (Post 5543291)
Not so easy, on my system the -i takes priority over -f if placed after -f when invocating rm options

eg
Code:

rm -rif => f takes priority over i
rm -rfi => i takes priority over f


As usual with Linux, our options have options.
Gotta Love It.


All times are GMT -5. The time now is 11:35 AM.