I am running WSL (Windows Subsystem for Linux) and when I use the ls -l
function on the terminal, I get new lines printed i.e. each file is on a new line e.g.:
total 12K
drwxrwxrwx 1 user user 4.0K Apr 4 23:28 .
drwxr-xr-x 1 user user 4.0K Apr 4 23:28 ..
-rw-rw-rw- 1 user user 0 Mar 28 01:03 a1.file
-rw-rw-rw- 1 user user 4.5K Mar 23 16:27 books.xml
-rw-rw-rw- 1 user user 0 Mar 13 00:19 file1
-rw-rw-rw- 1 user user 513 Mar 13 00:19 file2.txt
-rw-rw-rw- 1 user user 2.8K Mar 13 12:42 file3.txt
-rw-rw-rw- 1 user user 405 Apr 4 23:26 ls_l.txt
-rw-rw-rw- 1 user user 0 Apr 4 23:28 ls_l2.txt
-rw-rw-rw- 1 user user 89 Mar 13 00:18 pattern
-rw-rw-rw- 1 user user 86 Mar 28 01:41 somefile.file
However, when I use echo `ls -l` > file1.txt
, it has the same thing as ls -l
normally but all in one line, where each line is separated by spaces and not new lines e.g.:
total 12K drwxrwxrwx 1 user user 4.0K Mar 27 22:45 . drwxr-xr-x 1 user user 4.0K Mar 27 22:45 .. -rw-rw-rw- 1 user user 4.5K Mar 23 16:27 books.xml -rw-rw-rw- 1 user user 0 Mar 13 00:19 file1 -rw-rw-rw- 1 user user 513 Mar 13 00:19 file2.txt -rw-rw-rw- 1 user user 2.8K Mar 13 12:42 file3.txt -rw-rw-rw- 1 user user 403 Mar 27 22:45 ls_l.txt -rw-rw-rw- 1 user user 89 Mar 13 00:18 pattern
Note that I have these relevant aliases:
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls -lah'
vim
in the terminal. – user12055579 Apr 05 '20 at 04:16ls -l > a1.file
to be put in file with only one line. I think I may have piped something (as an issue seen here: https://unix.stackexchange.com/questions/10421/output-from-ls-has-newlines-but-displays-on-a-single-line-why) but I still don't know how I would pipe output fromls -l
to be put in a file. Is that even possible? – user12055579 Apr 05 '20 at 04:18echo `ls -l` > file1.txt
. Why does it put it on one line only? – user12055579 Apr 05 '20 at 04:26echo ls -l | file1.txt
won't provide a list of files, nor write tofile1.txt
and in fact it is a syntax error in any shell. Maybe your memory is playing tricks with you? – Apr 05 '20 at 04:30. `ls -l` > file1.txt
should not work either in most cases (unless the first file listed in the present directory is the name of an executable, and, in this case, must be namedls -l
). Are you sure that that is the question you want answered? – Apr 05 '20 at 04:34echo `ls -l` > file1.txt
. – user12055579 Apr 05 '20 at 04:36