Make ls print it all on one line (like in terminal)

Solution 1:

ls | xargs

It works for me, it's the simplest way I've found ever. Hope this helps you as well.

Solution 2:

i don't know of a switch which could do that, but you can pipe your output through tr to do it:

ls | tr "\n" " " | <whatever you like>

Solution 3:

If your ls has this option, you can use a high value and it might do what you want:

ls -w 10000 -C . | head

Solution 4:

ah, now that you've updated the question....

while true ; do echo * ; done | uniq

will do what you posted, just simpler.

however, you are better off using something that uses inotify to do this.. like

inotifywait -m . -e create,delete

if you don't have inotify, then something like this works well too:

import os
import time

last = set()
while True:
    cur = set(os.listdir('.'))
    added = cur-last
    removed = last-cur
    if added: print 'added', added
    if removed: print 'removed', removed
    last = set(os.listdir('.'))
    time.sleep(0.1)

Solution 5:

What about the quite trivial

echo *

? :-) You don't need even to fork for it. :-)