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. |
/ 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 Code:
ls ./Desktop/Books |
Hi:
You can also use ./ to launch a script. Code:
./ name of script http://linuxcommand.org/ http://linuxcommand.org/learning_the_shell.php |
Thanks for the reply but i did'nt get it.Why ./home/yogesh is wrong and /home/yogesh is correct ?
|
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. |
Quote:
|
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 In brief... Code:
/home/peter/Music/Waterloo.mp3 Code:
./Watrerloo.mp3 This picture clarifies all, if cory wanted to run at something in her folder, she'd enter Code:
./thatProgram Code:
/usr/lib/thatProgram Thor |
All times are GMT -5. The time now is 10:30 AM. |