Navigating directories with * / . and .. | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Navigating directories with * / . and ..

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-18-2013
bloodrule bloodrule is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 19 January 2013, 2:43 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Navigating directories with * / . and ..

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.
Sponsored Links
    #2  
Old 01-18-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 17 April 2014, 8:17 PM EDT
Location: Galactic Empire
Posts: 3,282
Thanks: 227
Thanked 1,157 Times in 1,094 Posts
The characters ? (question mark) and * (asterisk) are called wildcards.

The asterisk represents zero or more characters.

Code:
$ ls
doc_1.txt  doc2.txt  f1.csv  f2.csv  fl3.csv  pic_1.jpg  pic_2.jpg

$ ls *.txt
doc_1.txt  doc2.txt

The question mark represents only one character.

Code:
$ ls
doc_1.txt  doc2.txt  f1.csv  f2.csv  fl3.csv  pic_1.jpg  pic_2.jpg

$ ls ???.csv
fl3.csv

.. or ../ represents parent directory and ./ represents current directory. So ls */ means list the contents of all directories in current path.
Sponsored Links
    #3  
Old 01-19-2013
bloodrule bloodrule is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 19 January 2013, 2:43 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks - that helps a lot.

So how does" */./" differ from "*/." ? I seem to get slightly different results with each and still can't quite see why.

Also I understand that * and ? are called wildcards. But what are . .. and / called?
    #4  
Old 01-19-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 April 2014, 7:05 PM EDT
Location: San Jose, CA, USA
Posts: 3,454
Thanks: 140
Thanked 1,192 Times in 1,011 Posts
Quote:
Originally Posted by bloodrule View Post
Thanks - that helps a lot.

So how does" */./" differ from "*/." ? I seem to get slightly different results with each and still can't quite see why.

Also I understand that * and ? are called wildcards. But what are . .. and / called?
The pathname pattern * expands to the list of files in the current directory whose names do not have a period ( . ) as the first character in their name.

The pathname pattern */ expands to the list of directories in the current directory whose names do not have a period as the first character in their name. (Note that a directory is one type of file. Other types of files found on all UNIX and Linux systems include regular files, block special files, character special files, sockets, named pipes (AKA FIFO special files), and symbolic links. Most UNIX and Linux systems have more file types.)

The pathname pattern */. expands to the list of files named . (AKA dot in this context) in the directories named by the expansion of */ .

The pathname pattern */./ expands to the list of files of type directory named . in the directories named by the expansion of */ .

The pathname patterns */ , */. and */./ expand to the same list of files since dot is always a name of the directory in which it is located (unless the filesystem has been corrupted), but they cannot always be treated as synonyms. For example the command:

Code:
rmdir */

will remove all empty directories in the current working directory that you have permission to remove, and will print diagnostic messages for directories that are not empty and for directories that you don't have permission to remove, but the command:

Code:
rmdir */.

will not remove any directories and will give you a diagnostic message (saying you can't remove . for each of the directories named by the expansion of */. .

The file named . (AKA dot) is the current working directory. The file named .. (AKA dot-dot) is the parent directory of the current working directory. The file named / (AKA root) is the root directory for the hierarchy of files on the system available to the current process. In the root directory, . and .. may be different names for the same directory.
The Following User Says Thank You to Don Cragun For This Useful Post:
radoulov (01-19-2013)
Sponsored Links
    #5  
Old 01-19-2013
bloodrule bloodrule is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 19 January 2013, 2:43 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you!! That is the best answer I have ever seen to any question in any forum in ten years. I hope as many people as possible see your answer and learn from it.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Navigating a WebPage with Perl parthmittal2007 Shell Programming and Scripting 3 09-19-2012 08:48 AM
PERL navigating directories. How do I do it ShermW0829 Shell Programming and Scripting 0 03-19-2012 02:49 PM
navigating a web interface with a shell script boyincity Shell Programming and Scripting 2 02-01-2009 12:33 AM
Unix - Navigating the file system jjaggii UNIX for Dummies Questions & Answers 4 12-01-2005 03:33 PM



All times are GMT -4. The time now is 08:20 PM.