ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello
I want to pipe the output of ls in a folder to a file (lets call it test.txt) but when i do so, but when i do ls > test.txt in test.txt there is also test.txt (logical, sense it there, is there anyway to avoid this)
This is the normal behavior: when you redirect the output of a command to a file, first the file (empty) is created then the command is executed and the file populated with its output. To avoid that, just create the file in another location, e.g. in the /tmp directory:
Well it is working as per design and it is not showing you the false information as when you do ls -l > test.txt the file do exist there.
If you want to avoid that you can do other way round. Support you want to do ls -l /root and save the output into a file then do the following:
ls -l /root > /test.txt
This will put the output of ls -l ran on /root to test.txt file located under / provided test.txt file exist there on / else you have to use double redirection to create it
This will put the output of ls -l ran on /root to test.txt file located under / provided test.txt file exist there on / else you have to use double redirection to create it
ls -l /root >> /test.txt
Wrong. Both redirectors will create the file if it doesn't exist. The difference is that the >-redirector will delete the contents of the file when it already exists, while the >>-redirector will append the new text to the existing file without deleting previous content.
Yup thats true. I dont know why I said that even after knowing that it apends after the last line but still it was wrong. You always correct me... :-) Thank you
Last edited by T3RM1NVT0R; 05-03-2011 at 05:16 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.