Why is "/" AFTER file name, sometimes, but not always with cd?


#1



Learn Command Line, 5/9


No error message, however, I want to know, for learn, it said: cd 2015
(change directory to 2015)

And then directly below, the next instruction said: cd jan/memory/

So my question is, why is there no "/" after the file 2015, but there is one after memory/ ?


#2

It's simply two ways to accomplish the same task.

Let's say for some crazy reason you have a file names memory and a folder named memory in the same location. Adding the / at the end would make sure you don't try and cd to the file.

Most people wouldn't have a file and folder named the same thing in the same place, but it is not outside the realm of possibility as Linux systems do not need a file type extension to know what program to open.


#3

Hi,

so, the / after "memory" designates it as a FOLDER?

and so the "2015" was just a file?

And how does a directory compare to a folder?

thanks,

Megan


#4

No, the were both folders. It was just showing​ you two different ways to cd in to a folder.

Directory and folder are the same thing. Directory is just a more technical sounding word for it.


#5

Now I am in Manipulation, trying to do 5/10. I am getting error messages: there is no drama directory. I have looked at the help topics in the forum. Several other people have had the same problem, yet there was no resolution listed. No one said how to fix the problem. I signed in, I pwd. I can see the file movies, but no drama. how do I get to the drama directory? (cd .. didn't work)


#6

Looks like i figured out how to get there, but not by following the "Instructions". I started out above drama, so cd .. brought me above drama, not down into drama.


#7

I'm also stuck with 5/10. How can I navigate to the drama/directory


#8

First use pwd to find out where you are.

if you are not "under" or "within" the drama directory, you can write a command to take you there.

$ cd /home/ccuser/workspace/movies/drama

then I did ls to list the files is the directory that I am currently in. (the directory was drama)

when I executed the command ls, it output these 2 files: biopic historical

so I then knew I could work with these files.

i found that if a command in code academy doesn't work, i do pwd (print working directory) to figure out what directory i am actually in, then i can navigate elsewhere if needed.


#9

getting the notifications out there.. @megbig8 @marinamts @alan-redding

/ separates directory names, it isn't part of the name. Directories share namespace with files i.e. you can't have a file and a directory sharing the same name.

Since it's a separator it usually makes no difference whether you have one at the end. Tab completion might add the / for you, this is so you can continue to type the next name without adding the / yourself (and to let you know that it fully matched)
The one exception I can think of is with links to directories, without the trailing slash you are referring to the link file, but with the trailing slash you are referring to the directory that is linked to.

If you're not sure where you are or where something else is, pwd and ls can help a lot. ls can print out recursively with the -R option (though it's not that readable, the tree command (not installed) has a much better representation)
There are (of course) also commands for searching. So one might for example want to search the home directory for a directory named drama:
find ~ -name drama -type d


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.