LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Opening a directory in command line (https://www.linuxquestions.org/questions/linux-newbie-8/opening-a-directory-in-command-line-572135/)

Yash Pal 07-25-2007 06:41 AM

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.

Centinul 07-25-2007 06:52 AM

What do you mean by "open" a directory?

pixellany 07-25-2007 06:55 AM

"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.

chrism01 07-25-2007 08:10 PM

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

skywave 07-25-2007 08:17 PM

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

Yash Pal 07-26-2007 12:37 AM

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.

rupertwh 07-26-2007 01:24 AM

Code:

ls
is what you are looking for

chrism01 07-26-2007 01:35 AM

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...

Yash Pal 07-27-2007 03:45 AM

Deeply grateful to all for all the support and understanding extended to a novice


All times are GMT -5. The time now is 11:43 AM.