LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2016, 11:19 AM   #1
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Rep: Reputation: Disabled
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.
 
Old 05-09-2016, 11:41 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Based upon your .bashrc, anyh occurrence of rm should automatically include -i so an
Code:
rm -fr
would actually be
Code:
rm -ifr
 
1 members found this post helpful.
Old 05-09-2016, 11:43 AM   #3
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
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.
 
1 members found this post helpful.
Old 05-10-2016, 10:03 AM   #4
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
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.
 
Old 05-10-2016, 10:12 AM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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?

Last edited by Habitual; 05-10-2016 at 10:19 AM.
 
1 members found this post helpful.
Old 05-10-2016, 10:14 AM   #6
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by lazydog View Post
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.
 
Old 05-10-2016, 10:15 AM   #7
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
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'
 
Old 05-10-2016, 10:20 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I edited

I'm stumped, for now.
 
1 members found this post helpful.
Old 05-10-2016, 10:36 AM   #9
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
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.
 
Old 05-10-2016, 10:44 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by publicLearner View Post
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.
 
1 members found this post helpful.
Old 05-10-2016, 10:51 AM   #11
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
The -f switch takes precedence over -i, no?

edit
Code:
rm -rfi # interactive
rm -rif # rm with no question

Last edited by keefaz; 05-10-2016 at 10:53 AM.
 
1 members found this post helpful.
Old 05-10-2016, 11:00 AM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
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!
 
1 members found this post helpful.
Old 05-10-2016, 11:05 AM   #13
publicLearner
LQ Newbie
 
Registered: Mar 2015
Location: Washington, DC
Distribution: Mac 10.10 Yosemite
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
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.

@habitaul, keefaz, lazydog
Thank you very much for digging this one out.
 
Old 05-10-2016, 11:08 AM   #14
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by Habitual View Post
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
 
1 members found this post helpful.
Old 05-10-2016, 11:39 AM   #15
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
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.
 
1 members found this post helpful.
  


Reply

Tags
alias, remove


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] I would like to create an alias that tells me the current directory I am in... BMan8577 Linux - Newbie 5 12-12-2011 11:28 PM
How to Copy files from local directory to a particular directory using alias dynamics Linux - Newbie 7 09-11-2009 04:19 PM
directory use to write alias ernestk Linux - Server 2 09-11-2007 10:25 PM
directory for alias command ernestk Linux - Server 1 08-30-2007 05:56 PM
apache: url to alias directory w/o '/' psychobyte Linux - Networking 2 06-08-2006 02:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration