Viewed k times. Like this:. Improve this question. MultiplyByZer0 4, 3 3 gold badges 29 29 silver badges 46 46 bronze badges. If you are using ls for any other purpose like, say, to get a list of files in a script to iterate over , you are most certainly using the wrong tool. Why do you call it a wrong tool? It formats the listing for output in the user terminal.
It may replace special characters in the filename, it may omit characters that have special meaning, etc In other words, ls formats a list to the user. You want unformatted filenames. Any special reason that you are not using the python 'glob' module? Show 2 more comments. Active Oldest Votes. Use the -1 option note this is a "one" digit, not a lowercase letter "L" , like this: ls -1a First, though, make sure your ls supports Improve this answer.
Bert F Bert F I clarified in the answer. Searched on Google for linux ls one file per line and this was the top article. Can't believe how wordy the chosen answer is or that this answer has fewer votes than the one that pipes to cat. Show 1 more comment. Yes, you can easily make ls output one filename per line: ls -a cat Explanation: The command ls senses if the output is to a terminal or to a file or pipe and adjusts accordingly.
So, if you pipe ls -a to python it should work without any special measures. Peter G. Wow, this is brilliant. How would you avoid the. If not, just drop the -a option. For echo , some shells implement it as a shell builtin command. It might not accept the -e option. If you still want to use echo , try to find where the echo binary file is, using which echo. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Appending a line break to an output file in a shell script Ask Question. Asked 9 years, 10 months ago. Active 1 year, 1 month ago. Viewed k times. Improve this question. Peter Mortensen Ode Ode 1 1 gold badge 5 5 silver badges 12 12 bronze badges. How do you determine that the newlines are not added? Actually, I just looked at it seems the program I'm opening the log in is not interpreting the LF correctly, and is expecting Windows line breaks.
If I cat the output, it seems to honor the breaks. Google Green Messages. Use Your iPhone as a Webcam. Hide Private Photos on iPhone. All Microsoft's PowerToys for Windows. Take Screenshot by Tapping Back of iPhone.
Windows 11 Default Browser. Browse All Windows Articles. Windows 10 Annual Updates. OneDrive Windows 7 and 8. Copy and Paste Between Android and Windows. Protect Windows 10 From Internet Explorer. Mozilla Fights Double Standard.
Connect to a Hidden Wi-Fi Network. Change the Size of the Touch Keyboard. Reader Favorites Take Screenshot on Windows. Mount an ISO image in Windows. Boot Into Safe Mode. Where to Download Windows Legally. Find Your Lost Product Keys. Clean Install Windows 10 the Easy Way. The Best Tech Newsletter Anywhere Join , subscribers and get a daily digest of news, geek trivia, and our feature articles.
0コメント