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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-18-2012, 10:40 PM
|
#1
|
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
|
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.
|
|
|
09-18-2012, 10:59 PM
|
#2
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
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 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 or you escape the space in the filename 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.
|
09-18-2012, 11:03 PM
|
#3
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
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.
|
09-18-2012, 11:06 PM
|
#4
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by evo2
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.
|
09-18-2012, 11:07 PM
|
#5
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
accidental double post
Last edited by suicidaleggroll; 09-19-2012 at 08:07 AM.
|
|
|
09-19-2012, 01:04 AM
|
#6
|
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Original Poster
|
Thanks
Quote:
Originally Posted by evo2
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.
|
|
|
09-19-2012, 10:04 AM
|
#7
|
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Original Poster
|
Thanks a lot everyone. Answers are really helpful and cleared my doubts.
|
|
|
All times are GMT -5. The time now is 04:21 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|