Find the answer to your Linux question:
Results 1 to 7 of 7
On DOS, I'd enter "dir > filelist.txt", or something similar, and that would save the dir listing into a text file with the given filename. How could I do something ...
  1. #1
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    211

    how to save a file listing into a text file?

    On DOS, I'd enter "dir > filelist.txt", or something similar, and that would save the dir listing into a text file with the given filename.

    How could I do something similar on linux?

  2. #2
    Linux Newbie PureGrain's Avatar
    Join Date
    Nov 2006
    Location
    Mt. Washington, Kentucky
    Posts
    154
    Code:
    ls >> text.txt
    to put it into a file in that directory.
    LINUX - "The other white meat.."
    Registered Linux User #439112

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Right. The technical name for this is I/O redirection. Every program has 2 output streams: STDOUT (standard output) and STDERR (standard error). Most things output from a program are sent to STDOUT, with the obvious exceptions of warnings and error messages.

    To redirect the STDOUT of a particular program to a file, you simply end it with '>' or '>>', followed by the filename. Both of these will create the file if it doesn't exist, but if the file does exist, they differ. '>' will erase the file and overwrite it, while '>>' will append the text to the end of the file.

    So for instance:
    Code:
    ls *.txt > text_files # lists all .txt files in a file called text_files, overwriting it if it already exists
    ls more_files/*.txt >> text_files # appends a list of all .txt files in the more_files directory to the earlier list
    Does that make sense?
    DISTRO=Arch
    Registered Linux User #388732

  4. #4
    Linux Newbie rudie_rage's Avatar
    Join Date
    Jun 2007
    Location
    Canada
    Posts
    133
    Ive seen something like this where a 1 or 2 was used.

    for example 1>

    how does that work? what do the numbers mean? Also, what about < ?

    This is one of those things that ive never needed until ive seen it, and now its become invaluable. lol. I'd like to know more.
    Living the digital dream....
    Disclaimer: I may be wrong since I was once before.
    Breathe out so I can breathe you in ~~Everlong

  5. #5
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    211
    Thanks, PureGrain and Cabhan... I feel almost embarassed to not even have tried the exact same thing... but in the other hand, I knew that "ls /w" or other arguments from DOS wouldn't work, so it seemed a reasonable generalization that the same would be true with this I/O redirection thing...

  6. #6
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    @rudie_rage:
    The numbers 0-2 have special meanings for the shell.
    0=Standard input, or stdin for short (normally the keyboard)
    1=Standard output, or stdout for short (normally the monitor)
    2=Standard error, or stderr for short (also normally the monitor)

    When doing a redirection, you can specify what's being redirected. If no number is given, stdout is assumed for >.

    Redirecting stderr to the null device (/dev/null) is quite useful for hiding superfluous error messages. For example, here are two commands that search your whole system for a file called "ctlmissile"
    Code:
    find / -name "ctlmissile"
    find / -name "ctlmissile" 2>/dev/null
    The first one will find "ctlmissile" (assuming you have it), but it will also spew a whole bunch of "Permission denied" messages when it tries to look in directories where you're not allowed to look. The second one throws all those messages into oblivion and just shows you where your file is.
    Stand up and be counted as a Linux user!

  7. #7
    Linux Newbie rudie_rage's Avatar
    Join Date
    Jun 2007
    Location
    Canada
    Posts
    133
    thanks Zelmo. I'll play around with it
    Living the digital dream....
    Disclaimer: I may be wrong since I was once before.
    Breathe out so I can breathe you in ~~Everlong

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...