LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2013, 09:28 PM   #1
Bloodrule
LQ Newbie
 
Registered: Sep 2010
Posts: 5

Rep: Reputation: 0
Linux syntax for directories


I would be very happy (after a lot of fruitless searching) if someone could explain the meaning of these variations on the ls command:

ls */
ls */.
ls */./

I understand the basic use of ls already eg ls -al but am wanting to list from different points in the file structure without having to leave the directory I am in and my experimenting has left me confused.

Also in the examples above what is the correct term for the characters after the "ls"? Are they correctly called operators? Or is that the wrong term?

Thanks.
 
Old 01-19-2013, 03:37 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
* --> Used to match any string, of any length, or more generally, it stands for all.
/ --> Directory sepeartor or path seperator.
. --> Stands for current directory.

So, all patterns mentioned in your examples, can be replaced with:-
Code:
~$ ls *
Which means, list all.

Well, it actually depends upon what you want to search? All your mentioned examples will give you same result.
A ls */ means all in all i.e. list all files/directory inside all directories in your present working directory.

For more details and explainations, once go through: globbing

Last edited by shivaa; 01-19-2013 at 03:39 AM. Reason: Minor formatting change
 
Old 01-19-2013, 01:24 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by Bloodrule View Post
I would be very happy (after a lot of fruitless searching) if someone could explain the meaning of these variations on the ls command:

ls */
ls */.
ls */./

I understand the basic use of ls already eg ls -al but am wanting to list from different points in the file structure without having to leave the directory I am in and my experimenting has left me confused.

Also in the examples above what is the correct term for the characters after the "ls"? Are they correctly called operators? Or is that the wrong term?

Thanks.
As earlier mentioned, the / is a path separator. name preceding a / are expected to be a directory.

A "." by itself refers to the directory named "." in the current working directory. So a "ls ." means to list the contents of the current directory. A path like "name/." is the same as "name/", and when used with the ls command it will list the contents of the directory.

Another form of the "." is "..". This is an entry in a directory that refers to the parent directory. All directories have an entry for . and .. - this is what creates the tree structure of directories. It also allows you to use "../name" which means the directory (or file) with the name "name" in the parent directory of the current working directory.

In all cases, a "." is used to tell "ls" to not list the entry by default. So doing a "ls" by itself, will not list any directory entry that starts with ".". The key is "by default". If you do a "ls -a" then it will list all entries. These names are referred to as "hidden files".

As mentioned elsewhere.. The shell has a number of special characters that it uses to allow a more expressive command line. Things like "*" are used to match "all files". (a super simple directory listing can be done by the command "echo *". This will list all names in the current directory that are not hidden. Other characters have other uses (){}[]\?... for these uses see the manpage on your shell (usually bash, but there are other command line interpreters)

One note about the ? - it stands for "any character". So when you do a "ls ?" it means "list any file that has only one character in its name". The shell uses the special characters to expand the command line - so "echo ?" is replaced by "echo " and a list of the files with names of only one letter. In the same way that "echo *" is replaced by "echo " and the list of all file names that don't start with a ".".
 
Old 01-19-2013, 01:39 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
Quote:
Originally Posted by shivaa View Post
* --> Used to match any string, of any length, or more generally, it stands for all.
/ --> Directory sepeartor or path seperator.
. --> Stands for current directory.

So, all patterns mentioned in your examples, can be replaced with:-
Code:
~$ ls *
Which means, list all.

Well, it actually depends upon what you want to search? All your mentioned examples will give you same result.
A ls */ means all in all i.e. list all files/directory inside all directories in your present working directory.

For more details and explainations, once go through: globbing
Sorry, but wrong. Sometimes it helps to actually test your assumptions.
Code:
ls *
will list all files and directories in the current directory.
Code:
ls */
will not do the same, it will list the directories (not files) in the current directory and the contents (files and directories) of those directories.
 
Old 01-19-2013, 04:13 PM   #5
Bloodrule
LQ Newbie
 
Registered: Sep 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your replies. Still confused a bit over "/"

I understand it is a path separator. Yet when used alone cd / changes the current directory to root. Does that mean that in this instance the "/" character has a different meaning than as a path separator?
 
Old 01-19-2013, 05:32 PM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
No. It's just that the root of the filesystem hierarchy is itself a directory, here denoted by a single /.
 
Old 01-19-2013, 11:27 PM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
A "/" is always a path or directory seperator in a Unix based file system. A single "/" is also a part of path in a file system, but since it has nothing before or after it, so it simply points to root directory. In simple words, it points to the topmost directory in file system hierarchy i.e. "/".

Consider this example,
Code:
~$ cd /home/jack/foo
Here it is absolute path of foo directory. It starts from a "/" and then goes into multiple sub-directories. And if I remove everything after first "/". it will become,
Code:
~$ cd /
And you can see now it's pointing to the root directory.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
VIM syntax highlighting: Use of AWK syntax inside shell scripts kaiserkarl13 Programming 0 11-13-2012 11:04 AM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 01:52 PM
is there any syntax difference in C/C++ on Linux? adnankhawer Linux - General 2 03-21-2008 05:50 PM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 01:23 PM
Help please - Syntax for Qpopper on Linux marknc Linux - Newbie 6 03-14-2004 04:50 AM


All times are GMT -5. The time now is 12:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration