Home » Questions » Computers [ Ask a new question ]

What's the importance of / in the following Linux command

What's the importance of / in the following Linux command

What's the difference between

Asked by: Guest | Views: 364
Total answers/comments: 2
Guest [Entry]

"The difference may be minor in the cd example you provided, but beware when you mv files.

For example if you want to move several files to another directory, and you type

for i in *.mp3 ; do mv $i dest ; done

Forgetting the trailing slash, then each of the files moved will overwrite a file called dest (the first will actually create a file called dest if it doesn't already exist). The result is that all files except the last are overwritten with the last file, and it's now called dest.

To move to a directory, you must specify the trailing /

for i in *.mp3 ; do mv $i dest/ ; done

One side effect of the slash is that if the directory doesn't exist, you'll get an error message."
Guest [Entry]

"cd abc/xyz

Is correct, since ""abc/xyz"" refers to 'the ""xyz"" entity in the ""abc"" directory'. When you type

cd abc/xyz/

it refers to 'The """" entity in the ""xyz"" directory in the ""abc"" directory'. The """" (empty string) entity gets automatically translated to ""."", which is the ""current"" directory, which in this case is the ""xyz"" directory. So it all works out to the same thing.

(Some people feel that directories ""must"" have a slash appended. They are mistaken.)"