How to list *.tar.gz, one filename per line?











up vote
7
down vote

favorite
3












I am trying to list every .tar.gz file, only using the following command:



ls *.tar.gz -l



...It shows me the following list:



-rw-rw-r-- 1 osm osm  949 Nov 27 16:17 file1.tar.gz
-rw-rw-r-- 1 osm osm 949 Nov 27 16:17 file2.tar.gz


However, I just need to list it this way:



file1.tar.gz 
file2.tar.gz


and also not:



file1.tar.gz file2.tar.gz


How is this "properly" done?










share|improve this question




















  • 6




    it is a good habit to use options before filenames. and you need to use -1 instead of -l
    – AnonymousLurker
    Nov 27 at 16:53






  • 17




    ls -1 *.tar.gz, but what do you want to use the list for? If you are doing something to those filenames, then ls is not the right way to do it. See Why *not* parse `ls` (and what do to instead)?
    – Kusalananda
    Nov 27 at 16:53








  • 3




    the manual you need is man ls. Ensure that your display font has good contrast between 1 (one) and l (lower case letter ell).
    – ctrl-alt-delor
    Nov 27 at 19:19






  • 2




    Possible duplicate of Output from ls has newlines but displays on a single line. Why?
    – Julien Lopez
    Nov 28 at 7:27















up vote
7
down vote

favorite
3












I am trying to list every .tar.gz file, only using the following command:



ls *.tar.gz -l



...It shows me the following list:



-rw-rw-r-- 1 osm osm  949 Nov 27 16:17 file1.tar.gz
-rw-rw-r-- 1 osm osm 949 Nov 27 16:17 file2.tar.gz


However, I just need to list it this way:



file1.tar.gz 
file2.tar.gz


and also not:



file1.tar.gz file2.tar.gz


How is this "properly" done?










share|improve this question




















  • 6




    it is a good habit to use options before filenames. and you need to use -1 instead of -l
    – AnonymousLurker
    Nov 27 at 16:53






  • 17




    ls -1 *.tar.gz, but what do you want to use the list for? If you are doing something to those filenames, then ls is not the right way to do it. See Why *not* parse `ls` (and what do to instead)?
    – Kusalananda
    Nov 27 at 16:53








  • 3




    the manual you need is man ls. Ensure that your display font has good contrast between 1 (one) and l (lower case letter ell).
    – ctrl-alt-delor
    Nov 27 at 19:19






  • 2




    Possible duplicate of Output from ls has newlines but displays on a single line. Why?
    – Julien Lopez
    Nov 28 at 7:27













up vote
7
down vote

favorite
3









up vote
7
down vote

favorite
3






3





I am trying to list every .tar.gz file, only using the following command:



ls *.tar.gz -l



...It shows me the following list:



-rw-rw-r-- 1 osm osm  949 Nov 27 16:17 file1.tar.gz
-rw-rw-r-- 1 osm osm 949 Nov 27 16:17 file2.tar.gz


However, I just need to list it this way:



file1.tar.gz 
file2.tar.gz


and also not:



file1.tar.gz file2.tar.gz


How is this "properly" done?










share|improve this question















I am trying to list every .tar.gz file, only using the following command:



ls *.tar.gz -l



...It shows me the following list:



-rw-rw-r-- 1 osm osm  949 Nov 27 16:17 file1.tar.gz
-rw-rw-r-- 1 osm osm 949 Nov 27 16:17 file2.tar.gz


However, I just need to list it this way:



file1.tar.gz 
file2.tar.gz


and also not:



file1.tar.gz file2.tar.gz


How is this "properly" done?







ls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Jesse Steele

12717




12717










asked Nov 27 at 16:51









McLan

1704




1704








  • 6




    it is a good habit to use options before filenames. and you need to use -1 instead of -l
    – AnonymousLurker
    Nov 27 at 16:53






  • 17




    ls -1 *.tar.gz, but what do you want to use the list for? If you are doing something to those filenames, then ls is not the right way to do it. See Why *not* parse `ls` (and what do to instead)?
    – Kusalananda
    Nov 27 at 16:53








  • 3




    the manual you need is man ls. Ensure that your display font has good contrast between 1 (one) and l (lower case letter ell).
    – ctrl-alt-delor
    Nov 27 at 19:19






  • 2




    Possible duplicate of Output from ls has newlines but displays on a single line. Why?
    – Julien Lopez
    Nov 28 at 7:27














  • 6




    it is a good habit to use options before filenames. and you need to use -1 instead of -l
    – AnonymousLurker
    Nov 27 at 16:53






  • 17




    ls -1 *.tar.gz, but what do you want to use the list for? If you are doing something to those filenames, then ls is not the right way to do it. See Why *not* parse `ls` (and what do to instead)?
    – Kusalananda
    Nov 27 at 16:53








  • 3




    the manual you need is man ls. Ensure that your display font has good contrast between 1 (one) and l (lower case letter ell).
    – ctrl-alt-delor
    Nov 27 at 19:19






  • 2




    Possible duplicate of Output from ls has newlines but displays on a single line. Why?
    – Julien Lopez
    Nov 28 at 7:27








6




6




it is a good habit to use options before filenames. and you need to use -1 instead of -l
– AnonymousLurker
Nov 27 at 16:53




it is a good habit to use options before filenames. and you need to use -1 instead of -l
– AnonymousLurker
Nov 27 at 16:53




17




17




ls -1 *.tar.gz, but what do you want to use the list for? If you are doing something to those filenames, then ls is not the right way to do it. See Why *not* parse `ls` (and what do to instead)?
– Kusalananda
Nov 27 at 16:53






ls -1 *.tar.gz, but what do you want to use the list for? If you are doing something to those filenames, then ls is not the right way to do it. See Why *not* parse `ls` (and what do to instead)?
– Kusalananda
Nov 27 at 16:53






3




3




the manual you need is man ls. Ensure that your display font has good contrast between 1 (one) and l (lower case letter ell).
– ctrl-alt-delor
Nov 27 at 19:19




the manual you need is man ls. Ensure that your display font has good contrast between 1 (one) and l (lower case letter ell).
– ctrl-alt-delor
Nov 27 at 19:19




2




2




Possible duplicate of Output from ls has newlines but displays on a single line. Why?
– Julien Lopez
Nov 28 at 7:27




Possible duplicate of Output from ls has newlines but displays on a single line. Why?
– Julien Lopez
Nov 28 at 7:27










5 Answers
5






active

oldest

votes

















up vote
38
down vote



accepted










The -1 option (the digit “one”, not lower-case “L”) will list one file per line with no other information:



ls -1 -- *.tar.gz





share|improve this answer

















  • 1




    Why the double dashes? ls -1 *.tar.gz works just as well.
    – RonJohn
    Nov 28 at 19:50






  • 7




    @RonJohn it avoids surprises with filenames starting with -.
    – Stephen Kitt
    Nov 28 at 19:54






  • 3




    Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
    – wizzwizz4
    Nov 28 at 22:02












  • I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
    – Peter A. Schneider
    2 days ago






  • 1




    (... which made me look up columns!)
    – Peter A. Schneider
    2 days ago


















up vote
19
down vote













If you only need the filenames, you could use printf:



printf '%sn' *.tar.gz


... the shell will expand the *.tar.gz wildcard to the filenames, then printf will print them, with each followed by a newline. This output would differ a bit from that of ls in the case of filenames with newlines embedded in them:



setup



$ touch file{1,2}.tar.gz
$ touch file$'n'3.tar.gz


ls



$ ls -1 -- *.tar.gz
file1.tar.gz
file2.tar.gz
file?3.tar.gz


printf



$ printf '%sn' *.tar.gz
file1.tar.gz
file2.tar.gz
file
3.tar.gz





share|improve this answer

















  • 6




    See also ls -b, ls -Q, ls --quoting-style=....
    – Stephen Kitt
    Nov 27 at 17:10










  • And printf '%qn'. (Both GNU.)
    – dave_thompson_085
    2 days ago


















up vote
9
down vote













ls behaves differently when its output is piped. For example:



ls          # outputs filenames in columns
ls | cat # passes one filename per line to the cat command


So if you want see all your *.tar.gz files, one per line, you can do this:



ls *.tar.gz | cat


But what if you don't want to pipe your output? That is, is there a way to force ls to output the filenames one to a line without piping the output?



Yes, with the -1 switch. (That's a dash with the number 1.) So you can use these commands:



ls -1             # shows all (non-hidden) files, one per line
ls -1 *.tar.gz # shows only *.tar.gz files, one per line





share|improve this answer










New contributor




J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    7
    down vote













    Or with GNU find:



    find  -name "*.tar.gz"  -printf '%Pn'


    In contrary to ls with * it will search for .tar.gz files recursively:



    $ find  -name "*.tar.gz"  -printf '%Pn'
    file1.tar.gz
    dir/file3.tar.gz
    file2.tar.gz





    share|improve this answer





















    • Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
      – Martin Bonner
      2 days ago










    • @MartinBonner because -print will add ./ before the filename.
      – Arkadiusz Drabczyk
      2 days ago


















    up vote
    4
    down vote













    A slightly more roundabout and loopy way:



    for i in *.tar.gz; do
    echo "$i"
    done


    EDIT: added quotes to handle weird filenames






    share|improve this answer



















    • 5




      touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
      – Jeff Schaller
      Nov 27 at 20:49










    • oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
      – snetch
      Nov 27 at 20:57






    • 2




      sorry! rm -- '-e a.tar.gz' should do the trick
      – Jeff Schaller
      Nov 27 at 21:01










    • You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
      – snetch
      Nov 27 at 21:02










    • Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
      – Jesse Steele
      Nov 29 at 0:02











    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%2f484481%2fhow-to-list-tar-gz-one-filename-per-line%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    38
    down vote



    accepted










    The -1 option (the digit “one”, not lower-case “L”) will list one file per line with no other information:



    ls -1 -- *.tar.gz





    share|improve this answer

















    • 1




      Why the double dashes? ls -1 *.tar.gz works just as well.
      – RonJohn
      Nov 28 at 19:50






    • 7




      @RonJohn it avoids surprises with filenames starting with -.
      – Stephen Kitt
      Nov 28 at 19:54






    • 3




      Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
      – wizzwizz4
      Nov 28 at 22:02












    • I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
      – Peter A. Schneider
      2 days ago






    • 1




      (... which made me look up columns!)
      – Peter A. Schneider
      2 days ago















    up vote
    38
    down vote



    accepted










    The -1 option (the digit “one”, not lower-case “L”) will list one file per line with no other information:



    ls -1 -- *.tar.gz





    share|improve this answer

















    • 1




      Why the double dashes? ls -1 *.tar.gz works just as well.
      – RonJohn
      Nov 28 at 19:50






    • 7




      @RonJohn it avoids surprises with filenames starting with -.
      – Stephen Kitt
      Nov 28 at 19:54






    • 3




      Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
      – wizzwizz4
      Nov 28 at 22:02












    • I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
      – Peter A. Schneider
      2 days ago






    • 1




      (... which made me look up columns!)
      – Peter A. Schneider
      2 days ago













    up vote
    38
    down vote



    accepted







    up vote
    38
    down vote



    accepted






    The -1 option (the digit “one”, not lower-case “L”) will list one file per line with no other information:



    ls -1 -- *.tar.gz





    share|improve this answer












    The -1 option (the digit “one”, not lower-case “L”) will list one file per line with no other information:



    ls -1 -- *.tar.gz






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 27 at 16:52









    Stephen Kitt

    159k24354430




    159k24354430








    • 1




      Why the double dashes? ls -1 *.tar.gz works just as well.
      – RonJohn
      Nov 28 at 19:50






    • 7




      @RonJohn it avoids surprises with filenames starting with -.
      – Stephen Kitt
      Nov 28 at 19:54






    • 3




      Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
      – wizzwizz4
      Nov 28 at 22:02












    • I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
      – Peter A. Schneider
      2 days ago






    • 1




      (... which made me look up columns!)
      – Peter A. Schneider
      2 days ago














    • 1




      Why the double dashes? ls -1 *.tar.gz works just as well.
      – RonJohn
      Nov 28 at 19:50






    • 7




      @RonJohn it avoids surprises with filenames starting with -.
      – Stephen Kitt
      Nov 28 at 19:54






    • 3




      Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
      – wizzwizz4
      Nov 28 at 22:02












    • I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
      – Peter A. Schneider
      2 days ago






    • 1




      (... which made me look up columns!)
      – Peter A. Schneider
      2 days ago








    1




    1




    Why the double dashes? ls -1 *.tar.gz works just as well.
    – RonJohn
    Nov 28 at 19:50




    Why the double dashes? ls -1 *.tar.gz works just as well.
    – RonJohn
    Nov 28 at 19:50




    7




    7




    @RonJohn it avoids surprises with filenames starting with -.
    – Stephen Kitt
    Nov 28 at 19:54




    @RonJohn it avoids surprises with filenames starting with -.
    – Stephen Kitt
    Nov 28 at 19:54




    3




    3




    Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
    – wizzwizz4
    Nov 28 at 22:02






    Specifically... Say I was an attacker, and had the following files: .hiddenfile, benign.php, evil.bin, --hide=*evil*; without the -- you won't see evil.bin or --hide=*evil*.
    – wizzwizz4
    Nov 28 at 22:02














    I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
    – Peter A. Schneider
    2 days ago




    I'm utterly disppointed that there is no -2 (or -3 etc.)! ;-)
    – Peter A. Schneider
    2 days ago




    1




    1




    (... which made me look up columns!)
    – Peter A. Schneider
    2 days ago




    (... which made me look up columns!)
    – Peter A. Schneider
    2 days ago












    up vote
    19
    down vote













    If you only need the filenames, you could use printf:



    printf '%sn' *.tar.gz


    ... the shell will expand the *.tar.gz wildcard to the filenames, then printf will print them, with each followed by a newline. This output would differ a bit from that of ls in the case of filenames with newlines embedded in them:



    setup



    $ touch file{1,2}.tar.gz
    $ touch file$'n'3.tar.gz


    ls



    $ ls -1 -- *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file?3.tar.gz


    printf



    $ printf '%sn' *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file
    3.tar.gz





    share|improve this answer

















    • 6




      See also ls -b, ls -Q, ls --quoting-style=....
      – Stephen Kitt
      Nov 27 at 17:10










    • And printf '%qn'. (Both GNU.)
      – dave_thompson_085
      2 days ago















    up vote
    19
    down vote













    If you only need the filenames, you could use printf:



    printf '%sn' *.tar.gz


    ... the shell will expand the *.tar.gz wildcard to the filenames, then printf will print them, with each followed by a newline. This output would differ a bit from that of ls in the case of filenames with newlines embedded in them:



    setup



    $ touch file{1,2}.tar.gz
    $ touch file$'n'3.tar.gz


    ls



    $ ls -1 -- *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file?3.tar.gz


    printf



    $ printf '%sn' *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file
    3.tar.gz





    share|improve this answer

















    • 6




      See also ls -b, ls -Q, ls --quoting-style=....
      – Stephen Kitt
      Nov 27 at 17:10










    • And printf '%qn'. (Both GNU.)
      – dave_thompson_085
      2 days ago













    up vote
    19
    down vote










    up vote
    19
    down vote









    If you only need the filenames, you could use printf:



    printf '%sn' *.tar.gz


    ... the shell will expand the *.tar.gz wildcard to the filenames, then printf will print them, with each followed by a newline. This output would differ a bit from that of ls in the case of filenames with newlines embedded in them:



    setup



    $ touch file{1,2}.tar.gz
    $ touch file$'n'3.tar.gz


    ls



    $ ls -1 -- *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file?3.tar.gz


    printf



    $ printf '%sn' *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file
    3.tar.gz





    share|improve this answer












    If you only need the filenames, you could use printf:



    printf '%sn' *.tar.gz


    ... the shell will expand the *.tar.gz wildcard to the filenames, then printf will print them, with each followed by a newline. This output would differ a bit from that of ls in the case of filenames with newlines embedded in them:



    setup



    $ touch file{1,2}.tar.gz
    $ touch file$'n'3.tar.gz


    ls



    $ ls -1 -- *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file?3.tar.gz


    printf



    $ printf '%sn' *.tar.gz
    file1.tar.gz
    file2.tar.gz
    file
    3.tar.gz






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 27 at 17:03









    Jeff Schaller

    37k1052121




    37k1052121








    • 6




      See also ls -b, ls -Q, ls --quoting-style=....
      – Stephen Kitt
      Nov 27 at 17:10










    • And printf '%qn'. (Both GNU.)
      – dave_thompson_085
      2 days ago














    • 6




      See also ls -b, ls -Q, ls --quoting-style=....
      – Stephen Kitt
      Nov 27 at 17:10










    • And printf '%qn'. (Both GNU.)
      – dave_thompson_085
      2 days ago








    6




    6




    See also ls -b, ls -Q, ls --quoting-style=....
    – Stephen Kitt
    Nov 27 at 17:10




    See also ls -b, ls -Q, ls --quoting-style=....
    – Stephen Kitt
    Nov 27 at 17:10












    And printf '%qn'. (Both GNU.)
    – dave_thompson_085
    2 days ago




    And printf '%qn'. (Both GNU.)
    – dave_thompson_085
    2 days ago










    up vote
    9
    down vote













    ls behaves differently when its output is piped. For example:



    ls          # outputs filenames in columns
    ls | cat # passes one filename per line to the cat command


    So if you want see all your *.tar.gz files, one per line, you can do this:



    ls *.tar.gz | cat


    But what if you don't want to pipe your output? That is, is there a way to force ls to output the filenames one to a line without piping the output?



    Yes, with the -1 switch. (That's a dash with the number 1.) So you can use these commands:



    ls -1             # shows all (non-hidden) files, one per line
    ls -1 *.tar.gz # shows only *.tar.gz files, one per line





    share|improve this answer










    New contributor




    J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      9
      down vote













      ls behaves differently when its output is piped. For example:



      ls          # outputs filenames in columns
      ls | cat # passes one filename per line to the cat command


      So if you want see all your *.tar.gz files, one per line, you can do this:



      ls *.tar.gz | cat


      But what if you don't want to pipe your output? That is, is there a way to force ls to output the filenames one to a line without piping the output?



      Yes, with the -1 switch. (That's a dash with the number 1.) So you can use these commands:



      ls -1             # shows all (non-hidden) files, one per line
      ls -1 *.tar.gz # shows only *.tar.gz files, one per line





      share|improve this answer










      New contributor




      J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        9
        down vote










        up vote
        9
        down vote









        ls behaves differently when its output is piped. For example:



        ls          # outputs filenames in columns
        ls | cat # passes one filename per line to the cat command


        So if you want see all your *.tar.gz files, one per line, you can do this:



        ls *.tar.gz | cat


        But what if you don't want to pipe your output? That is, is there a way to force ls to output the filenames one to a line without piping the output?



        Yes, with the -1 switch. (That's a dash with the number 1.) So you can use these commands:



        ls -1             # shows all (non-hidden) files, one per line
        ls -1 *.tar.gz # shows only *.tar.gz files, one per line





        share|improve this answer










        New contributor




        J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        ls behaves differently when its output is piped. For example:



        ls          # outputs filenames in columns
        ls | cat # passes one filename per line to the cat command


        So if you want see all your *.tar.gz files, one per line, you can do this:



        ls *.tar.gz | cat


        But what if you don't want to pipe your output? That is, is there a way to force ls to output the filenames one to a line without piping the output?



        Yes, with the -1 switch. (That's a dash with the number 1.) So you can use these commands:



        ls -1             # shows all (non-hidden) files, one per line
        ls -1 *.tar.gz # shows only *.tar.gz files, one per line






        share|improve this answer










        New contributor




        J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer








        edited Nov 27 at 23:00





















        New contributor




        J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Nov 27 at 22:47









        J-L

        1913




        1913




        New contributor




        J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        J-L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






















            up vote
            7
            down vote













            Or with GNU find:



            find  -name "*.tar.gz"  -printf '%Pn'


            In contrary to ls with * it will search for .tar.gz files recursively:



            $ find  -name "*.tar.gz"  -printf '%Pn'
            file1.tar.gz
            dir/file3.tar.gz
            file2.tar.gz





            share|improve this answer





















            • Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
              – Martin Bonner
              2 days ago










            • @MartinBonner because -print will add ./ before the filename.
              – Arkadiusz Drabczyk
              2 days ago















            up vote
            7
            down vote













            Or with GNU find:



            find  -name "*.tar.gz"  -printf '%Pn'


            In contrary to ls with * it will search for .tar.gz files recursively:



            $ find  -name "*.tar.gz"  -printf '%Pn'
            file1.tar.gz
            dir/file3.tar.gz
            file2.tar.gz





            share|improve this answer





















            • Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
              – Martin Bonner
              2 days ago










            • @MartinBonner because -print will add ./ before the filename.
              – Arkadiusz Drabczyk
              2 days ago













            up vote
            7
            down vote










            up vote
            7
            down vote









            Or with GNU find:



            find  -name "*.tar.gz"  -printf '%Pn'


            In contrary to ls with * it will search for .tar.gz files recursively:



            $ find  -name "*.tar.gz"  -printf '%Pn'
            file1.tar.gz
            dir/file3.tar.gz
            file2.tar.gz





            share|improve this answer












            Or with GNU find:



            find  -name "*.tar.gz"  -printf '%Pn'


            In contrary to ls with * it will search for .tar.gz files recursively:



            $ find  -name "*.tar.gz"  -printf '%Pn'
            file1.tar.gz
            dir/file3.tar.gz
            file2.tar.gz






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 27 at 21:01









            Arkadiusz Drabczyk

            7,67021734




            7,67021734












            • Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
              – Martin Bonner
              2 days ago










            • @MartinBonner because -print will add ./ before the filename.
              – Arkadiusz Drabczyk
              2 days ago


















            • Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
              – Martin Bonner
              2 days ago










            • @MartinBonner because -print will add ./ before the filename.
              – Arkadiusz Drabczyk
              2 days ago
















            Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
            – Martin Bonner
            2 days ago




            Why -printf '%Pn' rather than just -print - at which point any Posix compatible find will work.
            – Martin Bonner
            2 days ago












            @MartinBonner because -print will add ./ before the filename.
            – Arkadiusz Drabczyk
            2 days ago




            @MartinBonner because -print will add ./ before the filename.
            – Arkadiusz Drabczyk
            2 days ago










            up vote
            4
            down vote













            A slightly more roundabout and loopy way:



            for i in *.tar.gz; do
            echo "$i"
            done


            EDIT: added quotes to handle weird filenames






            share|improve this answer



















            • 5




              touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
              – Jeff Schaller
              Nov 27 at 20:49










            • oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
              – snetch
              Nov 27 at 20:57






            • 2




              sorry! rm -- '-e a.tar.gz' should do the trick
              – Jeff Schaller
              Nov 27 at 21:01










            • You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
              – snetch
              Nov 27 at 21:02










            • Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
              – Jesse Steele
              Nov 29 at 0:02















            up vote
            4
            down vote













            A slightly more roundabout and loopy way:



            for i in *.tar.gz; do
            echo "$i"
            done


            EDIT: added quotes to handle weird filenames






            share|improve this answer



















            • 5




              touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
              – Jeff Schaller
              Nov 27 at 20:49










            • oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
              – snetch
              Nov 27 at 20:57






            • 2




              sorry! rm -- '-e a.tar.gz' should do the trick
              – Jeff Schaller
              Nov 27 at 21:01










            • You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
              – snetch
              Nov 27 at 21:02










            • Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
              – Jesse Steele
              Nov 29 at 0:02













            up vote
            4
            down vote










            up vote
            4
            down vote









            A slightly more roundabout and loopy way:



            for i in *.tar.gz; do
            echo "$i"
            done


            EDIT: added quotes to handle weird filenames






            share|improve this answer














            A slightly more roundabout and loopy way:



            for i in *.tar.gz; do
            echo "$i"
            done


            EDIT: added quotes to handle weird filenames







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 27 at 21:04

























            answered Nov 27 at 20:38









            snetch

            16719




            16719








            • 5




              touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
              – Jeff Schaller
              Nov 27 at 20:49










            • oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
              – snetch
              Nov 27 at 20:57






            • 2




              sorry! rm -- '-e a.tar.gz' should do the trick
              – Jeff Schaller
              Nov 27 at 21:01










            • You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
              – snetch
              Nov 27 at 21:02










            • Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
              – Jesse Steele
              Nov 29 at 0:02














            • 5




              touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
              – Jeff Schaller
              Nov 27 at 20:49










            • oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
              – snetch
              Nov 27 at 20:57






            • 2




              sorry! rm -- '-e a.tar.gz' should do the trick
              – Jeff Schaller
              Nov 27 at 21:01










            • You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
              – snetch
              Nov 27 at 21:02










            • Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
              – Jesse Steele
              Nov 29 at 0:02








            5




            5




            touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
            – Jeff Schaller
            Nov 27 at 20:49




            touch -- '-e a.tar.gz' for a reason to quote your variables and unix.stackexchange.com/q/65803/117549 for reasons to use printf instead of echo
            – Jeff Schaller
            Nov 27 at 20:49












            oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
            – snetch
            Nov 27 at 20:57




            oof, I just spent 5 minutes trying to figure out how to remove the resulting -e a.tar.gz file
            – snetch
            Nov 27 at 20:57




            2




            2




            sorry! rm -- '-e a.tar.gz' should do the trick
            – Jeff Schaller
            Nov 27 at 21:01




            sorry! rm -- '-e a.tar.gz' should do the trick
            – Jeff Schaller
            Nov 27 at 21:01












            You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
            – snetch
            Nov 27 at 21:02




            You're good, it was a lesson, and I did learn that -- works for rm and a lot of others.
            – snetch
            Nov 27 at 21:02












            Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
            – Jesse Steele
            Nov 29 at 0:02




            Thank you for that. It wouldn't be a complete question if someone didn't suggest a for-do loop to solve the problem. lol Upvoting.
            – Jesse Steele
            Nov 29 at 0:02


















            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%2f484481%2fhow-to-list-tar-gz-one-filename-per-line%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

            Plaza Victoria

            Puebla de Zaragoza

            Musa