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 ...
- 06-24-2007 #1Linux 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?
- 06-25-2007 #2to put it into a file in that directory.Code:
ls >> text.txt
LINUX - "The other white meat.."
Registered Linux User #439112
- 06-25-2007 #3
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:
Does that make sense?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
DISTRO=Arch
Registered Linux User #388732
- 06-25-2007 #4
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
- 06-25-2007 #5Linux 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...
- 06-26-2007 #6
@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"
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.Code:find / -name "ctlmissile" find / -name "ctlmissile" 2>/dev/null
Stand up and be counted as a Linux user!
- 06-26-2007 #7
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


Reply With Quote