LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   The ls command (https://www.linuxquestions.org/questions/linux-general-1/the-ls-command-331947/)

Gins 06-09-2005 02:26 PM

The ls command
 
Could you tell me the differences among the following commands.

$ls ../
$ls ./
$ls /



[ka@c83-250-88-135 ka]$ ls ../
ka/
The above ' ka ' is a folder under the folder ' home ' .
---------------------------------------------------------------------------------------
[ka@c83-250-88-135 ka]$ ls /
bin/ boot/ dev/ etc/ home/ initrd/ lib/ lost+found/ mnt/ opt/ proc/ root/ sbin/ sys/ tmp/ usr/ var/
[ka@c83-250-88-135 ka]$
---------------------------------------------------------------------

The following command shows all my files and folders.
[ka@c83-250-88-135 ka]$ ls ./

rose_bud4201 06-09-2005 02:29 PM

/, by itself, indicates the root directory of your filesystem. It's akin to windows' C:

. indicates your current directory. You could type ls . and ls ./ get the same results. The trailing "/" just is extra visual confirmation that you're talking about a directory; bash doesn't really need it.

.. indicates the directory above your current directory. Again, the trailing / is just visual.

keefaz 06-09-2005 02:34 PM

Gins, are you going to asking help for all Linux core commands ?

;)
http://www.icon.co.za/~psheer/book/rute.html.gz

Gins 06-09-2005 02:49 PM

I thank keefaz and rose_bud for the replies. The information you all gave me is very important.

Gins 06-11-2005 02:27 PM

I found the following on the website mentioned by keefaz.
http://www.icon.co.za/~psheer/book/rute.html.gz


4.6 Relative vs. Absolute Pathnames

Commands can be given file name arguments in two ways. If you are in the same directory as the file (i.e., the file is in the current directory), then you can just enter the file name on its own (e.g., cp my_file new_file). Otherwise, you can enter the full path name, like cp /home/jack/my_file /home/jack/new_file. Very often administrators use the notation ./my_file to be clear about the distinction, for instance, cp ./my_file ./new_file.
The leading ./ makes it clear that both files are relative to the current directory. File names not starting with a / are called relative path names, and otherwise, absolute path names.
-----------------------------------------------------------------------------------------

I can't fathom the last two sentences of the above.

Rose_bud4201 told me the simple forward slash [ / ] is akin to Windows C: prompt. Yes I agree with him. I tested it.

On top of that he told me the dot [ . ] or [ ./ ] means your current directory. Yes I agree with him. I tested it.

I have some difficulty understanding the meaning of Relative and Absolute Pathnames. The explanations given on the website is not clear to me.

Would you be able shed some light on this?



File names not starting with / are called relative path names. What is the meaning of this? You could create a file using, for example, the ' touch ' command. I can create a file called ' America1234 ' . It doesn't have any forward slash [ / ] .

Are you able to create a file name [ /America1234 ] ? If you can create it, why use the forward slash [ / ] ?

Komakino 06-11-2005 02:36 PM

argh!! You are SO frustrating!! You have lots to learn but asking every single question on a forum is not the way to do it!! Get yourself a decent linux book!

What it means by relative and absolute pathnames is:

relative: in relation to the current directory.
absolute in relation to the root directory (/)
For example if I do:
Code:

touch newfile.txt
it will create a file newfile.txt in whatever directory I am currently in. If I am currently in /home/steve then the absolute path will be:
Code:

/home/steve/newfile.txt
and the relative pathname would be
Code:

./newfile.txt
(./because it's in the same directory I am currently in).
If I now move to a different directory, say /home, then the absolute path does not change, it is still /home/steve/newfile.txt but the relative path is now ./steve/newfile.txt

If I now change directory to / (the root directory) the absolute pathname is still /home/steve/newfile.txt, but the relative path again changes and is now /home/steve/newfile.txt because it is relative to where I am, and I am currently at the root of the filesystem.

For a windows analogy. In windows, the file command.com is in c:\windows\system , so its absolute path is:
C:\windows\system\command.com
if I was browsing through C:\windows then at that moment the relative path of command.com is .\system\command.com

Alles klar?

Gins 06-11-2005 03:23 PM

Thank you for the beautiful explanation. As a matter of fact, I have bought a couple of books on Linux. I must buy some more books. Today I tried in vain to buy a book called ' UNIX Complete' . It was written by a person called Peter Dyson. It seems the book is out of print. I checked even at online bookshops .

One online bookshops in the UK says it is out of print at the moment. However, I borrowed it from a public library. I could keep it at home just for 4 weeks.
As far as I am concerned, when I ask questions from you all via the online forums, I learn better than reading books.



As your answer is an excellent one, I printed it out. I always print out the answers which I consider is very worth.

Komakino 06-11-2005 03:37 PM

Wow, I've never been considered very worthy before! :)

And I didn't mean to appear rude, sorry.


All times are GMT -5. The time now is 02:07 AM.