LinuxQuestions.org
Review your favorite Linux distribution.
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 09-18-2012, 10:40 PM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Use of "\" (backslash) in commands


Hello Friends,
Could anyone explain the use of "\" (backward slash) with "rm" command.
I've seen, that many people use following command when delete a file or directory:
example% \rm -rf <directory>
So why thay use fwd slash before rm?
Thanks a lot.
 
Old 09-18-2012, 10:59 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,497
Blog Entries: 2

Rep: Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017Reputation: 4017
I have never seen that. The backslash is an escape character, which is used to give characters to commands that would normally have a different meaning in the shell.
For example, if you have a filename with a space in it, for example "aaa bbb" you could not simply remove the file with
Code:
rm aaa bbb
because rm would try to remove two files, aaa and bbb, but not the file aaa bbb. To circumvent that you can either quote the filename
Code:
rm "aaa bbb"
or you escape the space in the filename
Code:
rm aaa\ bbb
EDIT: Thanks to evo2 and suicidaleggroll, I didn't know that one could escape an alias.

Last edited by TobiSGD; 09-18-2012 at 11:15 PM.
 
1 members found this post helpful.
Old 09-18-2012, 11:03 PM   #3
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,193

Rep: Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120
Hi,

it's to avoid shell aliases and the like.

Try the following.
Code:
alias rm='rm -i'
touch foo bar
rm foo
\rm bar
when you rm foo, you should be asked to confirm (since the alias has -i), but when you \rm bar the alias is not used.

Cheers,

Evo2.
 
1 members found this post helpful.
Old 09-18-2012, 11:06 PM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,721

Rep: Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975
Quote:
Originally Posted by evo2 View Post
Hi,

it's to avoid shell aliases and the like.

Try the following.
Code:
alias rm='rm -i'
touch foo bar
rm foo
\rm bar
when you rm foo, you should be asked to confirm (since the alias has -i), but when you \rm bar the alias is not used.

Cheers,

Evo2.
^ this

The leading backslash bypasses any aliases the user has set up for the command. For example, I have an alias for df, so whenever I run "df" it actually runs "df -h", just so that I don't always have to type the -h. However, if I ever want to run the df without the -h, for whatever reason, I need to run "\df" so it runs the regular version without my custom alias.
 
1 members found this post helpful.
Old 09-18-2012, 11:07 PM   #5
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,721

Rep: Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975Reputation: 975
accidental double post

Last edited by suicidaleggroll; 09-19-2012 at 08:07 AM.
 
Old 09-19-2012, 01:04 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Wink Thanks

Quote:
Originally Posted by evo2 View Post
Hi,

it's to avoid shell aliases and the like.

Try the following.
Code:
alias rm='rm -i'
touch foo bar
rm foo
\rm bar
when you rm foo, you should be asked to confirm (since the alias has -i), but when you \rm bar the alias is not used.

Cheers,

Evo2.
Thanks. It's really helpful.
 
Old 09-19-2012, 10:04 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Thanks a lot everyone. Answers are really helpful and cleared my doubts.
 
  


Reply

Tags
command, slash


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
Latex Problem: Backslash Recognized as Two Backslashes "doesn't match its definition" rm_-rf_windows Linux - General 2 05-09-2012 09:54 PM
Accepting single backslash "\" as a user input. sundar_r05 Linux - Enterprise 6 02-02-2010 05:29 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM


All times are GMT -5. The time now is 06:15 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration