How to output only file names (with spaces) in ls -Al?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
64
down vote

favorite
16












I should echo only names of files or directories with this construction:



ls -Al | while read string
do
...
done


ls -Al output :



drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal domain
drwxr-xr-x 2 s162103 studs 3 march 28 22:32 public_html
drwxr-xr-x 7 s162103 studs 8 march 28 13:59 WebApplication1


For example if I try:



ls -Al | while read string
do
echo "$string" | awk 'print $9
done


then output only files and directories without spaces. If file or directory have spaces like "personal domain" it will be only word "personal".



I need very simple solution. Maybe there is better solution than awk.










share|improve this question



















  • 2




    Why not just ls -Al *' '*? Parsing ls's output never leads to anything good.
    – manatwork
    Mar 30 '13 at 15:01






  • 1




    If you need something that will work in any *nix try avoiding using ls -Al | while. A simple and more reliable way is for string in *; do echo "$string"; done.
    – forcefsck
    Mar 30 '13 at 15:17










  • need only with this construction..okay,not simple,any solution!
    – Alex Zern
    Mar 30 '13 at 15:31






  • 1




    Why do you need ls? Parsing ls and "work in all *nix and will not break if something happened" do not go well together.
    – terdon
    Mar 30 '13 at 15:59







  • 2




    mywiki.wooledge.org/ParsingLs
    – Braiam
    May 10 '14 at 23:29














up vote
64
down vote

favorite
16












I should echo only names of files or directories with this construction:



ls -Al | while read string
do
...
done


ls -Al output :



drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal domain
drwxr-xr-x 2 s162103 studs 3 march 28 22:32 public_html
drwxr-xr-x 7 s162103 studs 8 march 28 13:59 WebApplication1


For example if I try:



ls -Al | while read string
do
echo "$string" | awk 'print $9
done


then output only files and directories without spaces. If file or directory have spaces like "personal domain" it will be only word "personal".



I need very simple solution. Maybe there is better solution than awk.










share|improve this question



















  • 2




    Why not just ls -Al *' '*? Parsing ls's output never leads to anything good.
    – manatwork
    Mar 30 '13 at 15:01






  • 1




    If you need something that will work in any *nix try avoiding using ls -Al | while. A simple and more reliable way is for string in *; do echo "$string"; done.
    – forcefsck
    Mar 30 '13 at 15:17










  • need only with this construction..okay,not simple,any solution!
    – Alex Zern
    Mar 30 '13 at 15:31






  • 1




    Why do you need ls? Parsing ls and "work in all *nix and will not break if something happened" do not go well together.
    – terdon
    Mar 30 '13 at 15:59







  • 2




    mywiki.wooledge.org/ParsingLs
    – Braiam
    May 10 '14 at 23:29












up vote
64
down vote

favorite
16









up vote
64
down vote

favorite
16






16





I should echo only names of files or directories with this construction:



ls -Al | while read string
do
...
done


ls -Al output :



drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal domain
drwxr-xr-x 2 s162103 studs 3 march 28 22:32 public_html
drwxr-xr-x 7 s162103 studs 8 march 28 13:59 WebApplication1


For example if I try:



ls -Al | while read string
do
echo "$string" | awk 'print $9
done


then output only files and directories without spaces. If file or directory have spaces like "personal domain" it will be only word "personal".



I need very simple solution. Maybe there is better solution than awk.










share|improve this question















I should echo only names of files or directories with this construction:



ls -Al | while read string
do
...
done


ls -Al output :



drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal domain
drwxr-xr-x 2 s162103 studs 3 march 28 22:32 public_html
drwxr-xr-x 7 s162103 studs 8 march 28 13:59 WebApplication1


For example if I try:



ls -Al | while read string
do
echo "$string" | awk 'print $9
done


then output only files and directories without spaces. If file or directory have spaces like "personal domain" it will be only word "personal".



I need very simple solution. Maybe there is better solution than awk.







linux command-line ls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 4 '15 at 18:03









kenorb

8,251367106




8,251367106










asked Mar 30 '13 at 14:59









Alex Zern

469167




469167







  • 2




    Why not just ls -Al *' '*? Parsing ls's output never leads to anything good.
    – manatwork
    Mar 30 '13 at 15:01






  • 1




    If you need something that will work in any *nix try avoiding using ls -Al | while. A simple and more reliable way is for string in *; do echo "$string"; done.
    – forcefsck
    Mar 30 '13 at 15:17










  • need only with this construction..okay,not simple,any solution!
    – Alex Zern
    Mar 30 '13 at 15:31






  • 1




    Why do you need ls? Parsing ls and "work in all *nix and will not break if something happened" do not go well together.
    – terdon
    Mar 30 '13 at 15:59







  • 2




    mywiki.wooledge.org/ParsingLs
    – Braiam
    May 10 '14 at 23:29












  • 2




    Why not just ls -Al *' '*? Parsing ls's output never leads to anything good.
    – manatwork
    Mar 30 '13 at 15:01






  • 1




    If you need something that will work in any *nix try avoiding using ls -Al | while. A simple and more reliable way is for string in *; do echo "$string"; done.
    – forcefsck
    Mar 30 '13 at 15:17










  • need only with this construction..okay,not simple,any solution!
    – Alex Zern
    Mar 30 '13 at 15:31






  • 1




    Why do you need ls? Parsing ls and "work in all *nix and will not break if something happened" do not go well together.
    – terdon
    Mar 30 '13 at 15:59







  • 2




    mywiki.wooledge.org/ParsingLs
    – Braiam
    May 10 '14 at 23:29







2




2




Why not just ls -Al *' '*? Parsing ls's output never leads to anything good.
– manatwork
Mar 30 '13 at 15:01




Why not just ls -Al *' '*? Parsing ls's output never leads to anything good.
– manatwork
Mar 30 '13 at 15:01




1




1




If you need something that will work in any *nix try avoiding using ls -Al | while. A simple and more reliable way is for string in *; do echo "$string"; done.
– forcefsck
Mar 30 '13 at 15:17




If you need something that will work in any *nix try avoiding using ls -Al | while. A simple and more reliable way is for string in *; do echo "$string"; done.
– forcefsck
Mar 30 '13 at 15:17












need only with this construction..okay,not simple,any solution!
– Alex Zern
Mar 30 '13 at 15:31




need only with this construction..okay,not simple,any solution!
– Alex Zern
Mar 30 '13 at 15:31




1




1




Why do you need ls? Parsing ls and "work in all *nix and will not break if something happened" do not go well together.
– terdon
Mar 30 '13 at 15:59





Why do you need ls? Parsing ls and "work in all *nix and will not break if something happened" do not go well together.
– terdon
Mar 30 '13 at 15:59





2




2




mywiki.wooledge.org/ParsingLs
– Braiam
May 10 '14 at 23:29




mywiki.wooledge.org/ParsingLs
– Braiam
May 10 '14 at 23:29










9 Answers
9






active

oldest

votes

















up vote
79
down vote













You really should not parse the output of ls. If this is a homework assignment and you are required to, your professor does not know what they're talking about. Why don't you do something like this:



The good...



find ./ -printf "%fn"


or



for n in *; do printf '%sn' "$n"; done


...the bad...



If you really really want to use ls, you can make it a little bit more robust by doing something like this:



ls -lA | awk -F':[0-9]* ' '/:/print $2'


...and the ugly



If you insist on doing it the wrong, dangerous way and just have to use a while loop, do this:



ls -Al | while IFS= read -r string; do echo "$string" | 
awk -F':[0-9]* ' '/:/print $2'; done


Seriously though, just don't.






share|improve this answer






















  • drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
    – Alex Zern
    Mar 30 '13 at 16:30






  • 1




    @AlexZern Well, that's one of the reasons you don't parse the output of ls.
    – terdon
    Mar 30 '13 at 16:33






  • 1




    @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
    – terdon
    Mar 30 '13 at 16:37










  • because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
    – Alex Zern
    Mar 30 '13 at 16:46






  • 3




    OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
    – terdon
    Mar 30 '13 at 16:49


















up vote
62
down vote













Is there some reason that ls -A1* won't work?



E.g.:



$ touch file1 file2 file with spaces
$ ls -Al
total 0
-rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file1
-rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file2
-rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file with spaces
$ ls -A1
file1
file2
file with spaces
$



* Note: that's a capital letter A and the number one.






share|improve this answer
















  • 4




    the -1 is genius. I didnt know that was available. (I know I know. RTFM)
    – The Lazy Coder
    Aug 20 '15 at 16:38










  • that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
    – thecotne
    Nov 28 '15 at 11:22










  • @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
    – AJP
    May 5 '16 at 15:45










  • i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
    – thecotne
    May 6 '16 at 8:00






  • 2




    @TheLazyCoder would not be expected to read the manual.
    – c24w
    Jun 7 '17 at 15:05

















up vote
31
down vote













I wonder why no one mentioned this simple command:



ls -a | sort





share|improve this answer
















  • 2




    Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
    – msciwoj
    Sep 14 '16 at 10:49











  • @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
    – Ben
    Sep 14 '16 at 12:32











  • PERFECT! Why wasn't this one marked as the real answer!?
    – 夏期劇場
    Mar 17 '17 at 17:02






  • 3




    It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
    – Stéphane Chazelas
    Mar 23 at 11:22







  • 1




    @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
    – Kusalananda
    Mar 23 at 11:25

















up vote
3
down vote













You cannot parse the output of ls, let alone ls -l because newline, just like space is as valid a character as any in a filename. Also, you'll need to consider symlinks that have an output like ... foo -> bar.



Why would you use -l anyway if you only want the file name?



Just do:



for file in *; do
...
done


If you want to include dot files (except . and ..), depending on the shell:



zsh:



for file in *(ND); do
...
done


bash:



shopt -s nullglob dotglob
for file in *; do
...
done


ksh93:



FIGNORE='@(.|..)'
for file in ~(N)*; do
...
done


POSIXly:



for file in .[!.]* ..?* *; do
[ -e "$file" ] || [ -L "$file" ] || continue
...
done





share|improve this answer





























    up vote
    1
    down vote













    How about:



    for file in * .[!.]*
    do
    printf "%sn" "$file"
    done





    share|improve this answer



























      up vote
      1
      down vote













      ls -Al | tr -s ' ' | cut -f9- -d' '


      compress multiple spaces into single spaces with tr then you can use cut to split on the fields






      share|improve this answer



























        up vote
        1
        down vote













        Try (bash, zsh, ksh93 syntax):



        find . -type f -print0 | while IFS= read -r -d '' filename; do
        ...
        done



        This goes recursive and lists only on normal files (i.e. no dirs or symlinks/fifos/devices...).




        See also:



        • List only regular files (but not directories) in current directory


        • Why you shouldn't parse the output of ls(1) at wooledge wiki


        • Why not parse ls? at unix SE





        share|improve this answer





























          up vote
          0
          down vote













          try ls -1
          enter image description here
          Thats Integer 1



          From man page.



           ls -1 list one file per line. Avoid 'n' with -q or -b





          share|improve this answer




















          • Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
            – dave_thompson_085
            Dec 2 at 14:24

















          up vote
          -1
          down vote













          ls --file *|grep ^ 


          it displays what files under what directory.






          share|improve this answer






















          • I don't think that this addresses the question.
            – Jeff Schaller
            Dec 25 '16 at 20:09










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f70614%2fhow-to-output-only-file-names-with-spaces-in-ls-al%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          9 Answers
          9






          active

          oldest

          votes








          9 Answers
          9






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          79
          down vote













          You really should not parse the output of ls. If this is a homework assignment and you are required to, your professor does not know what they're talking about. Why don't you do something like this:



          The good...



          find ./ -printf "%fn"


          or



          for n in *; do printf '%sn' "$n"; done


          ...the bad...



          If you really really want to use ls, you can make it a little bit more robust by doing something like this:



          ls -lA | awk -F':[0-9]* ' '/:/print $2'


          ...and the ugly



          If you insist on doing it the wrong, dangerous way and just have to use a while loop, do this:



          ls -Al | while IFS= read -r string; do echo "$string" | 
          awk -F':[0-9]* ' '/:/print $2'; done


          Seriously though, just don't.






          share|improve this answer






















          • drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
            – Alex Zern
            Mar 30 '13 at 16:30






          • 1




            @AlexZern Well, that's one of the reasons you don't parse the output of ls.
            – terdon
            Mar 30 '13 at 16:33






          • 1




            @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
            – terdon
            Mar 30 '13 at 16:37










          • because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
            – Alex Zern
            Mar 30 '13 at 16:46






          • 3




            OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
            – terdon
            Mar 30 '13 at 16:49















          up vote
          79
          down vote













          You really should not parse the output of ls. If this is a homework assignment and you are required to, your professor does not know what they're talking about. Why don't you do something like this:



          The good...



          find ./ -printf "%fn"


          or



          for n in *; do printf '%sn' "$n"; done


          ...the bad...



          If you really really want to use ls, you can make it a little bit more robust by doing something like this:



          ls -lA | awk -F':[0-9]* ' '/:/print $2'


          ...and the ugly



          If you insist on doing it the wrong, dangerous way and just have to use a while loop, do this:



          ls -Al | while IFS= read -r string; do echo "$string" | 
          awk -F':[0-9]* ' '/:/print $2'; done


          Seriously though, just don't.






          share|improve this answer






















          • drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
            – Alex Zern
            Mar 30 '13 at 16:30






          • 1




            @AlexZern Well, that's one of the reasons you don't parse the output of ls.
            – terdon
            Mar 30 '13 at 16:33






          • 1




            @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
            – terdon
            Mar 30 '13 at 16:37










          • because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
            – Alex Zern
            Mar 30 '13 at 16:46






          • 3




            OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
            – terdon
            Mar 30 '13 at 16:49













          up vote
          79
          down vote










          up vote
          79
          down vote









          You really should not parse the output of ls. If this is a homework assignment and you are required to, your professor does not know what they're talking about. Why don't you do something like this:



          The good...



          find ./ -printf "%fn"


          or



          for n in *; do printf '%sn' "$n"; done


          ...the bad...



          If you really really want to use ls, you can make it a little bit more robust by doing something like this:



          ls -lA | awk -F':[0-9]* ' '/:/print $2'


          ...and the ugly



          If you insist on doing it the wrong, dangerous way and just have to use a while loop, do this:



          ls -Al | while IFS= read -r string; do echo "$string" | 
          awk -F':[0-9]* ' '/:/print $2'; done


          Seriously though, just don't.






          share|improve this answer














          You really should not parse the output of ls. If this is a homework assignment and you are required to, your professor does not know what they're talking about. Why don't you do something like this:



          The good...



          find ./ -printf "%fn"


          or



          for n in *; do printf '%sn' "$n"; done


          ...the bad...



          If you really really want to use ls, you can make it a little bit more robust by doing something like this:



          ls -lA | awk -F':[0-9]* ' '/:/print $2'


          ...and the ugly



          If you insist on doing it the wrong, dangerous way and just have to use a while loop, do this:



          ls -Al | while IFS= read -r string; do echo "$string" | 
          awk -F':[0-9]* ' '/:/print $2'; done


          Seriously though, just don't.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 23 at 10:37

























          answered Mar 30 '13 at 16:11









          terdon

          127k31245422




          127k31245422











          • drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
            – Alex Zern
            Mar 30 '13 at 16:30






          • 1




            @AlexZern Well, that's one of the reasons you don't parse the output of ls.
            – terdon
            Mar 30 '13 at 16:33






          • 1




            @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
            – terdon
            Mar 30 '13 at 16:37










          • because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
            – Alex Zern
            Mar 30 '13 at 16:46






          • 3




            OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
            – terdon
            Mar 30 '13 at 16:49

















          • drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
            – Alex Zern
            Mar 30 '13 at 16:30






          • 1




            @AlexZern Well, that's one of the reasons you don't parse the output of ls.
            – terdon
            Mar 30 '13 at 16:33






          • 1




            @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
            – terdon
            Mar 30 '13 at 16:37










          • because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
            – Alex Zern
            Mar 30 '13 at 16:46






          • 3




            OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
            – terdon
            Mar 30 '13 at 16:49
















          drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
          – Alex Zern
          Mar 30 '13 at 16:30




          drwx------ 2 s162103 studs 3 oct. 9 2012 .ssh drwxr-xr-x 3 s162103 studs 6 oct. 25 09:02 .subversion drwxrwxrwt 3 s162103 studs 3 nov. 15 2012 .TempoItems sometimes i've got date without time, only year and gawk return empty
          – Alex Zern
          Mar 30 '13 at 16:30




          1




          1




          @AlexZern Well, that's one of the reasons you don't parse the output of ls.
          – terdon
          Mar 30 '13 at 16:33




          @AlexZern Well, that's one of the reasons you don't parse the output of ls.
          – terdon
          Mar 30 '13 at 16:33




          1




          1




          @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
          – terdon
          Mar 30 '13 at 16:37




          @AlexZern why do you need the -l switch anyway? If all you want is the file names, just run ls -A. Using -l just makes your life harder since you now have to parse the output.
          – terdon
          Mar 30 '13 at 16:37












          because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
          – Alex Zern
          Mar 30 '13 at 16:46




          because I need additional information like access, date, owner,etc. And I wrote a huge script ,which works well, except print file and dir names with spaces.
          – Alex Zern
          Mar 30 '13 at 16:46




          3




          3




          OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
          – terdon
          Mar 30 '13 at 16:49





          OK then. What we have here is an XY problem. ls is just not the best way of getting what you need. Why don't you post a new question explaining the information you want to collect and we can suggest ways of doing it. Alternatively, you can use your script as is, and use one of the suggestions above to print the name only. But seriously, don't parse ls, just tell us exactly what you are trying to do in a new question.
          – terdon
          Mar 30 '13 at 16:49













          up vote
          62
          down vote













          Is there some reason that ls -A1* won't work?



          E.g.:



          $ touch file1 file2 file with spaces
          $ ls -Al
          total 0
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file1
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file2
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file with spaces
          $ ls -A1
          file1
          file2
          file with spaces
          $



          * Note: that's a capital letter A and the number one.






          share|improve this answer
















          • 4




            the -1 is genius. I didnt know that was available. (I know I know. RTFM)
            – The Lazy Coder
            Aug 20 '15 at 16:38










          • that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
            – thecotne
            Nov 28 '15 at 11:22










          • @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
            – AJP
            May 5 '16 at 15:45










          • i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
            – thecotne
            May 6 '16 at 8:00






          • 2




            @TheLazyCoder would not be expected to read the manual.
            – c24w
            Jun 7 '17 at 15:05














          up vote
          62
          down vote













          Is there some reason that ls -A1* won't work?



          E.g.:



          $ touch file1 file2 file with spaces
          $ ls -Al
          total 0
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file1
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file2
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file with spaces
          $ ls -A1
          file1
          file2
          file with spaces
          $



          * Note: that's a capital letter A and the number one.






          share|improve this answer
















          • 4




            the -1 is genius. I didnt know that was available. (I know I know. RTFM)
            – The Lazy Coder
            Aug 20 '15 at 16:38










          • that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
            – thecotne
            Nov 28 '15 at 11:22










          • @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
            – AJP
            May 5 '16 at 15:45










          • i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
            – thecotne
            May 6 '16 at 8:00






          • 2




            @TheLazyCoder would not be expected to read the manual.
            – c24w
            Jun 7 '17 at 15:05












          up vote
          62
          down vote










          up vote
          62
          down vote









          Is there some reason that ls -A1* won't work?



          E.g.:



          $ touch file1 file2 file with spaces
          $ ls -Al
          total 0
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file1
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file2
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file with spaces
          $ ls -A1
          file1
          file2
          file with spaces
          $



          * Note: that's a capital letter A and the number one.






          share|improve this answer












          Is there some reason that ls -A1* won't work?



          E.g.:



          $ touch file1 file2 file with spaces
          $ ls -Al
          total 0
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file1
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file2
          -rw-r--r-- 1 bahamat bahamat 0 Mar 30 22:31 file with spaces
          $ ls -A1
          file1
          file2
          file with spaces
          $



          * Note: that's a capital letter A and the number one.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 31 '13 at 5:35









          bahamat

          24.1k14690




          24.1k14690







          • 4




            the -1 is genius. I didnt know that was available. (I know I know. RTFM)
            – The Lazy Coder
            Aug 20 '15 at 16:38










          • that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
            – thecotne
            Nov 28 '15 at 11:22










          • @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
            – AJP
            May 5 '16 at 15:45










          • i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
            – thecotne
            May 6 '16 at 8:00






          • 2




            @TheLazyCoder would not be expected to read the manual.
            – c24w
            Jun 7 '17 at 15:05












          • 4




            the -1 is genius. I didnt know that was available. (I know I know. RTFM)
            – The Lazy Coder
            Aug 20 '15 at 16:38










          • that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
            – thecotne
            Nov 28 '15 at 11:22










          • @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
            – AJP
            May 5 '16 at 15:45










          • i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
            – thecotne
            May 6 '16 at 8:00






          • 2




            @TheLazyCoder would not be expected to read the manual.
            – c24w
            Jun 7 '17 at 15:05







          4




          4




          the -1 is genius. I didnt know that was available. (I know I know. RTFM)
          – The Lazy Coder
          Aug 20 '15 at 16:38




          the -1 is genius. I didnt know that was available. (I know I know. RTFM)
          – The Lazy Coder
          Aug 20 '15 at 16:38












          that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
          – thecotne
          Nov 28 '15 at 11:22




          that only works for current directory if you want to list file names from other directory say ~/projects then you will get full paths instead of file names
          – thecotne
          Nov 28 '15 at 11:22












          @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
          – AJP
          May 5 '16 at 15:45




          @thecotne on Mac 10.9.5 it just lists the file names. What OS are you using?
          – AJP
          May 5 '16 at 15:45












          i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
          – thecotne
          May 6 '16 at 8:00




          i am running this ls ~/projects/*.sublime-project -A1 for ls ~/projects -A1 i do get only names
          – thecotne
          May 6 '16 at 8:00




          2




          2




          @TheLazyCoder would not be expected to read the manual.
          – c24w
          Jun 7 '17 at 15:05




          @TheLazyCoder would not be expected to read the manual.
          – c24w
          Jun 7 '17 at 15:05










          up vote
          31
          down vote













          I wonder why no one mentioned this simple command:



          ls -a | sort





          share|improve this answer
















          • 2




            Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
            – msciwoj
            Sep 14 '16 at 10:49











          • @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
            – Ben
            Sep 14 '16 at 12:32











          • PERFECT! Why wasn't this one marked as the real answer!?
            – 夏期劇場
            Mar 17 '17 at 17:02






          • 3




            It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
            – Stéphane Chazelas
            Mar 23 at 11:22







          • 1




            @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
            – Kusalananda
            Mar 23 at 11:25














          up vote
          31
          down vote













          I wonder why no one mentioned this simple command:



          ls -a | sort





          share|improve this answer
















          • 2




            Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
            – msciwoj
            Sep 14 '16 at 10:49











          • @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
            – Ben
            Sep 14 '16 at 12:32











          • PERFECT! Why wasn't this one marked as the real answer!?
            – 夏期劇場
            Mar 17 '17 at 17:02






          • 3




            It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
            – Stéphane Chazelas
            Mar 23 at 11:22







          • 1




            @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
            – Kusalananda
            Mar 23 at 11:25












          up vote
          31
          down vote










          up vote
          31
          down vote









          I wonder why no one mentioned this simple command:



          ls -a | sort





          share|improve this answer












          I wonder why no one mentioned this simple command:



          ls -a | sort






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 11 '16 at 8:14









          Ben

          41246




          41246







          • 2




            Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
            – msciwoj
            Sep 14 '16 at 10:49











          • @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
            – Ben
            Sep 14 '16 at 12:32











          • PERFECT! Why wasn't this one marked as the real answer!?
            – 夏期劇場
            Mar 17 '17 at 17:02






          • 3




            It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
            – Stéphane Chazelas
            Mar 23 at 11:22







          • 1




            @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
            – Kusalananda
            Mar 23 at 11:25












          • 2




            Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
            – msciwoj
            Sep 14 '16 at 10:49











          • @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
            – Ben
            Sep 14 '16 at 12:32











          • PERFECT! Why wasn't this one marked as the real answer!?
            – 夏期劇場
            Mar 17 '17 at 17:02






          • 3




            It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
            – Stéphane Chazelas
            Mar 23 at 11:22







          • 1




            @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
            – Kusalananda
            Mar 23 at 11:25







          2




          2




          Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
          – msciwoj
          Sep 14 '16 at 10:49





          Brilliant! Any idea how piping to sort causes multi-column block to be unpivoted into single column?
          – msciwoj
          Sep 14 '16 at 10:49













          @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
          – Ben
          Sep 14 '16 at 12:32





          @msciwoj it just takes any strings separated by whitespaces and prints them sorted separated by endlines
          – Ben
          Sep 14 '16 at 12:32













          PERFECT! Why wasn't this one marked as the real answer!?
          – 夏期劇場
          Mar 17 '17 at 17:02




          PERFECT! Why wasn't this one marked as the real answer!?
          – 夏期劇場
          Mar 17 '17 at 17:02




          3




          3




          It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
          – Stéphane Chazelas
          Mar 23 at 11:22





          It works here because ls reverts to ls -1 (single columnd output) when its output doesn't go to a terminal (and disables non-printable character quoting/replacement; @Kusalananda, your ls is not POSIX compliant if it still does). ls output is already sorted. So piping it to sort will at best do nothing, and at worse mangle the output (if file names contain newline characters) or fail for filenames that are not text. ls -a | cat would be better. Or even better ls -A1 as already mentioned (and because you generally do want the replacements/quoting when displayed on a terminal)
          – Stéphane Chazelas
          Mar 23 at 11:22





          1




          1




          @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
          – Kusalananda
          Mar 23 at 11:25




          @StéphaneChazelas Noted. ls behaves differently when output is not a terminal.
          – Kusalananda
          Mar 23 at 11:25










          up vote
          3
          down vote













          You cannot parse the output of ls, let alone ls -l because newline, just like space is as valid a character as any in a filename. Also, you'll need to consider symlinks that have an output like ... foo -> bar.



          Why would you use -l anyway if you only want the file name?



          Just do:



          for file in *; do
          ...
          done


          If you want to include dot files (except . and ..), depending on the shell:



          zsh:



          for file in *(ND); do
          ...
          done


          bash:



          shopt -s nullglob dotglob
          for file in *; do
          ...
          done


          ksh93:



          FIGNORE='@(.|..)'
          for file in ~(N)*; do
          ...
          done


          POSIXly:



          for file in .[!.]* ..?* *; do
          [ -e "$file" ] || [ -L "$file" ] || continue
          ...
          done





          share|improve this answer


























            up vote
            3
            down vote













            You cannot parse the output of ls, let alone ls -l because newline, just like space is as valid a character as any in a filename. Also, you'll need to consider symlinks that have an output like ... foo -> bar.



            Why would you use -l anyway if you only want the file name?



            Just do:



            for file in *; do
            ...
            done


            If you want to include dot files (except . and ..), depending on the shell:



            zsh:



            for file in *(ND); do
            ...
            done


            bash:



            shopt -s nullglob dotglob
            for file in *; do
            ...
            done


            ksh93:



            FIGNORE='@(.|..)'
            for file in ~(N)*; do
            ...
            done


            POSIXly:



            for file in .[!.]* ..?* *; do
            [ -e "$file" ] || [ -L "$file" ] || continue
            ...
            done





            share|improve this answer
























              up vote
              3
              down vote










              up vote
              3
              down vote









              You cannot parse the output of ls, let alone ls -l because newline, just like space is as valid a character as any in a filename. Also, you'll need to consider symlinks that have an output like ... foo -> bar.



              Why would you use -l anyway if you only want the file name?



              Just do:



              for file in *; do
              ...
              done


              If you want to include dot files (except . and ..), depending on the shell:



              zsh:



              for file in *(ND); do
              ...
              done


              bash:



              shopt -s nullglob dotglob
              for file in *; do
              ...
              done


              ksh93:



              FIGNORE='@(.|..)'
              for file in ~(N)*; do
              ...
              done


              POSIXly:



              for file in .[!.]* ..?* *; do
              [ -e "$file" ] || [ -L "$file" ] || continue
              ...
              done





              share|improve this answer














              You cannot parse the output of ls, let alone ls -l because newline, just like space is as valid a character as any in a filename. Also, you'll need to consider symlinks that have an output like ... foo -> bar.



              Why would you use -l anyway if you only want the file name?



              Just do:



              for file in *; do
              ...
              done


              If you want to include dot files (except . and ..), depending on the shell:



              zsh:



              for file in *(ND); do
              ...
              done


              bash:



              shopt -s nullglob dotglob
              for file in *; do
              ...
              done


              ksh93:



              FIGNORE='@(.|..)'
              for file in ~(N)*; do
              ...
              done


              POSIXly:



              for file in .[!.]* ..?* *; do
              [ -e "$file" ] || [ -L "$file" ] || continue
              ...
              done






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 23 at 12:08

























              answered Apr 10 '15 at 19:24









              Stéphane Chazelas

              297k54561907




              297k54561907




















                  up vote
                  1
                  down vote













                  How about:



                  for file in * .[!.]*
                  do
                  printf "%sn" "$file"
                  done





                  share|improve this answer
























                    up vote
                    1
                    down vote













                    How about:



                    for file in * .[!.]*
                    do
                    printf "%sn" "$file"
                    done





                    share|improve this answer






















                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      How about:



                      for file in * .[!.]*
                      do
                      printf "%sn" "$file"
                      done





                      share|improve this answer












                      How about:



                      for file in * .[!.]*
                      do
                      printf "%sn" "$file"
                      done






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 30 '13 at 16:13









                      Scrutinizer

                      1,01455




                      1,01455




















                          up vote
                          1
                          down vote













                          ls -Al | tr -s ' ' | cut -f9- -d' '


                          compress multiple spaces into single spaces with tr then you can use cut to split on the fields






                          share|improve this answer
























                            up vote
                            1
                            down vote













                            ls -Al | tr -s ' ' | cut -f9- -d' '


                            compress multiple spaces into single spaces with tr then you can use cut to split on the fields






                            share|improve this answer






















                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              ls -Al | tr -s ' ' | cut -f9- -d' '


                              compress multiple spaces into single spaces with tr then you can use cut to split on the fields






                              share|improve this answer












                              ls -Al | tr -s ' ' | cut -f9- -d' '


                              compress multiple spaces into single spaces with tr then you can use cut to split on the fields







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 4 '15 at 21:16









                              simpleuser

                              19512




                              19512




















                                  up vote
                                  1
                                  down vote













                                  Try (bash, zsh, ksh93 syntax):



                                  find . -type f -print0 | while IFS= read -r -d '' filename; do
                                  ...
                                  done



                                  This goes recursive and lists only on normal files (i.e. no dirs or symlinks/fifos/devices...).




                                  See also:



                                  • List only regular files (but not directories) in current directory


                                  • Why you shouldn't parse the output of ls(1) at wooledge wiki


                                  • Why not parse ls? at unix SE





                                  share|improve this answer


























                                    up vote
                                    1
                                    down vote













                                    Try (bash, zsh, ksh93 syntax):



                                    find . -type f -print0 | while IFS= read -r -d '' filename; do
                                    ...
                                    done



                                    This goes recursive and lists only on normal files (i.e. no dirs or symlinks/fifos/devices...).




                                    See also:



                                    • List only regular files (but not directories) in current directory


                                    • Why you shouldn't parse the output of ls(1) at wooledge wiki


                                    • Why not parse ls? at unix SE





                                    share|improve this answer
























                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote









                                      Try (bash, zsh, ksh93 syntax):



                                      find . -type f -print0 | while IFS= read -r -d '' filename; do
                                      ...
                                      done



                                      This goes recursive and lists only on normal files (i.e. no dirs or symlinks/fifos/devices...).




                                      See also:



                                      • List only regular files (but not directories) in current directory


                                      • Why you shouldn't parse the output of ls(1) at wooledge wiki


                                      • Why not parse ls? at unix SE





                                      share|improve this answer














                                      Try (bash, zsh, ksh93 syntax):



                                      find . -type f -print0 | while IFS= read -r -d '' filename; do
                                      ...
                                      done



                                      This goes recursive and lists only on normal files (i.e. no dirs or symlinks/fifos/devices...).




                                      See also:



                                      • List only regular files (but not directories) in current directory


                                      • Why you shouldn't parse the output of ls(1) at wooledge wiki


                                      • Why not parse ls? at unix SE






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Apr 13 '17 at 12:37









                                      Community

                                      1




                                      1










                                      answered Mar 4 '15 at 18:01









                                      kenorb

                                      8,251367106




                                      8,251367106




















                                          up vote
                                          0
                                          down vote













                                          try ls -1
                                          enter image description here
                                          Thats Integer 1



                                          From man page.



                                           ls -1 list one file per line. Avoid 'n' with -q or -b





                                          share|improve this answer




















                                          • Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
                                            – dave_thompson_085
                                            Dec 2 at 14:24














                                          up vote
                                          0
                                          down vote













                                          try ls -1
                                          enter image description here
                                          Thats Integer 1



                                          From man page.



                                           ls -1 list one file per line. Avoid 'n' with -q or -b





                                          share|improve this answer




















                                          • Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
                                            – dave_thompson_085
                                            Dec 2 at 14:24












                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote









                                          try ls -1
                                          enter image description here
                                          Thats Integer 1



                                          From man page.



                                           ls -1 list one file per line. Avoid 'n' with -q or -b





                                          share|improve this answer












                                          try ls -1
                                          enter image description here
                                          Thats Integer 1



                                          From man page.



                                           ls -1 list one file per line. Avoid 'n' with -q or -b






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Dec 2 at 8:30









                                          abdul rashid

                                          1




                                          1











                                          • Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
                                            – dave_thompson_085
                                            Dec 2 at 14:24
















                                          • Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
                                            – dave_thompson_085
                                            Dec 2 at 14:24















                                          Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
                                          – dave_thompson_085
                                          Dec 2 at 14:24




                                          Already given 5 years ago by bahamat but without being amazingly ugly and inaccessible to some readers
                                          – dave_thompson_085
                                          Dec 2 at 14:24










                                          up vote
                                          -1
                                          down vote













                                          ls --file *|grep ^ 


                                          it displays what files under what directory.






                                          share|improve this answer






















                                          • I don't think that this addresses the question.
                                            – Jeff Schaller
                                            Dec 25 '16 at 20:09














                                          up vote
                                          -1
                                          down vote













                                          ls --file *|grep ^ 


                                          it displays what files under what directory.






                                          share|improve this answer






















                                          • I don't think that this addresses the question.
                                            – Jeff Schaller
                                            Dec 25 '16 at 20:09












                                          up vote
                                          -1
                                          down vote










                                          up vote
                                          -1
                                          down vote









                                          ls --file *|grep ^ 


                                          it displays what files under what directory.






                                          share|improve this answer














                                          ls --file *|grep ^ 


                                          it displays what files under what directory.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Dec 25 '16 at 20:09









                                          Jeff Schaller

                                          37.5k1052121




                                          37.5k1052121










                                          answered Dec 25 '16 at 19:21









                                          vars

                                          1




                                          1











                                          • I don't think that this addresses the question.
                                            – Jeff Schaller
                                            Dec 25 '16 at 20:09
















                                          • I don't think that this addresses the question.
                                            – Jeff Schaller
                                            Dec 25 '16 at 20:09















                                          I don't think that this addresses the question.
                                          – Jeff Schaller
                                          Dec 25 '16 at 20:09




                                          I don't think that this addresses the question.
                                          – Jeff Schaller
                                          Dec 25 '16 at 20:09

















                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f70614%2fhow-to-output-only-file-names-with-spaces-in-ls-al%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown






                                          Popular posts from this blog

                                          How to check contact read email or not when send email to Individual?

                                          Displaying single band from multi-band raster using QGIS

                                          How many registers does an x86_64 CPU actually have?