Fedora - n00b - do these / \ have to be used ? an alternative command?


Why did a colleague use this command
cd /users\ folders/users-personal/

To get to this pwd
/users folders/users-personal

he could have gone
cd "users folders"
then
cd "users-personal"

but that was two lines of code I admit

is there an easier way to jump two directories if there is a space in the directory name of one of them without using / \?

 




fcekAsked:
Who is Participating?
 
farzanjCommented:
In the command
cd /users\ folders/users-personal/
The bolded slash is ESCAPING the space.  This way cd would know that it is still the name of the folder.

Otherwise, when it sees a space it thinks that it is the end of a folder name and probably another one is coming.
0
 
wesly_chenCommented:
cd "/users folders/users-personal"
0
 
farzanjCommented:
Escaping means changing the usual meaning of a character, and use it literally.  In this case, a space delimits a folder name.  So to tell that it is still the same name, it has to escape it.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
svgmucCommented:
You can also

> cd "user folders/users-personal"

The / separates directories (or folders).

The \ is an escape character and in this case makes the cd command ignore the blank character and consider it part of the name... If you left the \ off, it would assume user and folders were two different arguments.
0
 
farzanjCommented:
Yes there are certainly more than one ways to do the same thing.


he could have gone
cd "users folders"
then
cd "users-personal"

YES I AGREE.  You could break it into two commands.  Same thing
0
 
farzanjCommented:
And lastly, yes, you can avoid escaping a space if you quote it

so
cd users\ folders

would be same as
cd "users folders"
0
 
fcekAuthor Commented:

lastly is there a way to jump back to $ from here:

 [ed@server1 /]$ cd /users\ folders/users-personal/

I do it in two steps
cd ..
then another
cd ..
and I land here
[ed@server1 /]$



0
 
wesly_chenCommented:
cd ../..
or
say
$ pwd
/tmp
$ cd "/users folders/users-personal"
$ pwd
/users folders/users-personal
$ cd -
$ pwd
/tmp
0
 
TintinCommented:
If your shell is bash, ksh or zsh, you can go to the last directory you were in by doing

cd -

Open in new window

0
 
fcekAuthor Commented:
Thanks everyone
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.