LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why ./home/Desktop is incorrect and ./Desktop is correct? (https://www.linuxquestions.org/questions/linux-newbie-8/why-home-desktop-is-incorrect-and-desktop-is-correct-4175542771/)

Yogesh24 05-16-2015 10:15 AM

Why ./home/Desktop is incorrect and ./Desktop is correct?
 
I'm learning about Linux, started yesterday. I have a question which didn't clear from the book and Google. The question is what is the difference between ./ and / in terminal? I'm asking this because when i give command for example - ./home/yogesh/Desktop/Books it is showing bash: ./home/yogesh/Desktop : No such file or directory but on removing the dot it's showing /home/yogesh/Desktop/Books: Is a directory.
Again on giving command like /Desktop it showing /Desktop :No such file or directory but on adding dot before / it is giving ./Desktop: is a directory.
What is the difference between ./ and / ?
I'm sorry if i asked something foolish but I have to know it anyway. Thankyou in advance and sorry for my bad English.

Teufel 05-16-2015 10:49 AM

/ is the topmost directory of the filesystem (the very root)
./ stands for your current location (either your home directory or where did you navigated with "cd" command)
When you open terminal usually you starting at your home directory (/home/yogesh). So if you want to list Books directory content you have to type it either
Code:

ls /home/yogesh/Desktop/Books
or
Code:

ls ./Desktop/Books
The last will be correct if you at your home directory (/home/yogesh)

Ztcoracat 05-16-2015 11:07 AM

Hi:

You can also use ./ to launch a script.

Code:

./ name of script
Study command-line when you have the time.
http://linuxcommand.org/

http://linuxcommand.org/learning_the_shell.php

Yogesh24 05-16-2015 11:12 AM

Thanks for the reply but i did'nt get it.Why ./home/yogesh is wrong and /home/yogesh is correct ?

michaelk 05-16-2015 11:16 AM

Actually if you look at the output of the ls -a you will see two objects represented by dots . and .. The single . means the directory itself and .. means its parrent directory. In a nutshell the . does not contain a trailing / (look at the output of the pwd command) therefore to run a command in the current working directory you need ./

An example of the .. is if you want to move one directory up in the tree i.e from /home/yogesh/Desktop/ to /home/yogesh/ quickly you would run the command
cd ..

/home/yogesh is an absolute path where as ./home/yogesh would expand to be the /current_working_directory/home/yogesh.

Teufel 05-16-2015 12:12 PM

Quote:

Originally Posted by Yogesh24 (Post 5363259)
Thanks for the reply but i did'nt get it.Why ./home/yogesh is wrong and /home/yogesh is correct ?

It's wrong because there is no "home" subdirectory in your current working directory.

ButterflyMelissa 05-16-2015 01:42 PM

okay, a quick intro in the file system...
say, the filesystem is a tree, that is upside down (weird, but, ride with me), then the upper most part is..."/", just that.
You could put everything in there and be done, but, that's messy, and Linux would NOT function that way. Neatness is the middle name of Linux...
All the users have a folder for their stuff (MP3's - legal I hope - pics, documents...) and since "home sweet home" goes the same for Linux, all the users have their "home" in the ..."home" folder. Located at the topmost level and thus directly attached to the root - as the slash is called...
INSIDE every "home" folder are the folders...of the users...
Correctness (and completeness) dictates mentioning the whole address:

Code:

/home/peter/Documents/resume.odt
...but...why go tru that when peter lives accross the street?

In brief...

Code:

/home/peter/Music/Waterloo.mp3
is what you feed a program that is "somewhere" on the drive, so it needs the wolde "address"...but...if the player "lives in the same folder...

Code:

./Watrerloo.mp3
...will do just as well...the "dot" in front basically means..."the guy that lives in this street"... :)

This picture clarifies all, if cory wanted to run at something in her folder, she'd enter

Code:

./thatProgram
but if that program is in the lib folder, she'd have to enter

Code:

/usr/lib/thatProgram
Hope that clarifies some and...welcome to Linux...

Thor


All times are GMT -5. The time now is 10:30 AM.