LinuxQuestions.org
Visit Jeremy's Blog.
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 07-25-2007, 07:41 AM   #1
Yash Pal
LQ Newbie
 
Registered: May 2007
Posts: 6

Rep: Reputation: 0
Opening a directory in command line


Could any one tell me How to open a directory. No book or on line explanation of commands seems to give this. Commands for opening of files do not appear to work for Directories. Manipulating files is covered, cd,cp, mkdir, rmdir etc are covered in books etc,but I could not open a directory with command line.
 
Old 07-25-2007, 07:52 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
What do you mean by "open" a directory?
 
Old 07-25-2007, 07:55 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
"cd" = change directory
That is the equivalent of "opening" the directory.
To be sure, a directory is just another file, but you cannot see the raw contents with normal tools.
 
Old 07-25-2007, 09:10 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
As per Centinul, what do you mean exactly?
There is a technique in Perl you might want:
Code:
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
while( defined($file = readdir(DIR)) ) 
{
    next if $file =~ /^\.\.?$/;     # skip . and ..
    # do something with "$dirname/$file"
}
closedir(DIR);
HTH
 
Old 07-25-2007, 09:17 PM   #5
skywave
LQ Newbie
 
Registered: Jul 2007
Distribution: PCLOS, openSUSE
Posts: 9

Rep: Reputation: Disabled
yap, what do you mead open? are you saying you want to browse directory just like using "cd" command in dos prompt?
In that case just try "ls \" that is to browse your root, or "ls \usr\lib" that is to access folder lib in your usr directory.

Hope this can help you
 
Old 07-26-2007, 01:37 AM   #6
Yash Pal
LQ Newbie
 
Registered: May 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Refer Centinul's question:What do you mean by "open" a directory?: I mean "How can I view the directory's contents".
I made(or whaterever you call it in Linuxspeak) a directory and named it "babu". With "touch" command, I opened a new file in it. I entered some text in that file. The next day, I wanted to view the contents, add some more text to the file in that directory and make another file in the directory.But for that, I should be able to "open"(as I call it) or view the contents of that directory which I could not do.
Chrism01 has given a remedy which is worse than the disease. Please appreciate that such an explanation is a daunting one for a normal and new user.
My "instructor" at the place I have joined to learn Linux gives only superficial explanation. I have to necessarily depend only on my enthusiasm and other members' support.
 
Old 07-26-2007, 02:24 AM   #7
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Code:
ls
is what you are looking for
 
Old 07-26-2007, 02:35 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
In bash, the simplest way to see a dir's contents is to move into the dir using the 'cd' cmd eg:

cd mydir

then list the contents

ls

then use editor of choice to add text to file.
Note that 'touch' creates a file if it does not already exist. If file does already exist, it updates the timestamp to 'now'. 'touch' does NOT open a file...
 
Old 07-27-2007, 04:45 AM   #9
Yash Pal
LQ Newbie
 
Registered: May 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Deeply grateful to all for all the support and understanding extended to a novice
 
  


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
Opening multiple instances of Seamonkey from the command line? vonst Linux - Software 3 01-20-2007 04:33 PM
opening an html file from command line ashlesha Linux - Newbie 5 07-18-2006 02:14 PM
change user home directory from command line cccc Debian 1 03-23-2006 06:07 PM
share a samba directory with the command line Mugatu Linux - Software 2 01-08-2004 02:44 PM
Opening an X program from ssh command line petway56 Linux - General 2 02-14-2003 05:33 PM


All times are GMT -5. The time now is 04:27 AM.

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