Is it possible to remove folder prefix from a `ls` command

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











up vote
10
down vote

favorite
2












I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output:



lib/mylib_1.jar
lib/mylib_2.jar
...


Is there any option to have the following output:



mylib_1.jar
mylib_2.jar
...


Making cd lib before is not an option as I am in a loop and need to be in the parent folder for the actions I want to do inside the loop.



I tried to find information by typing man ls but I did not find any solution.



A solution with another command would be good as long I can pipe it to my ls command or self sufficient.










share|improve this question



























    up vote
    10
    down vote

    favorite
    2












    I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output:



    lib/mylib_1.jar
    lib/mylib_2.jar
    ...


    Is there any option to have the following output:



    mylib_1.jar
    mylib_2.jar
    ...


    Making cd lib before is not an option as I am in a loop and need to be in the parent folder for the actions I want to do inside the loop.



    I tried to find information by typing man ls but I did not find any solution.



    A solution with another command would be good as long I can pipe it to my ls command or self sufficient.










    share|improve this question

























      up vote
      10
      down vote

      favorite
      2









      up vote
      10
      down vote

      favorite
      2






      2





      I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output:



      lib/mylib_1.jar
      lib/mylib_2.jar
      ...


      Is there any option to have the following output:



      mylib_1.jar
      mylib_2.jar
      ...


      Making cd lib before is not an option as I am in a loop and need to be in the parent folder for the actions I want to do inside the loop.



      I tried to find information by typing man ls but I did not find any solution.



      A solution with another command would be good as long I can pipe it to my ls command or self sufficient.










      share|improve this question















      I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output:



      lib/mylib_1.jar
      lib/mylib_2.jar
      ...


      Is there any option to have the following output:



      mylib_1.jar
      mylib_2.jar
      ...


      Making cd lib before is not an option as I am in a loop and need to be in the parent folder for the actions I want to do inside the loop.



      I tried to find information by typing man ls but I did not find any solution.



      A solution with another command would be good as long I can pipe it to my ls command or self sufficient.







      bash shell directory ls






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 mins ago

























      asked Apr 15 '14 at 13:29









      рüффп

      74821529




      74821529




















          7 Answers
          7






          active

          oldest

          votes

















          up vote
          17
          down vote



          accepted










          Instead of parsing ls you should use find instead. Then you can also execute basename on each file to strip the leading directories:



          find lib/ -name '*.jar' -exec basename ;





          share|improve this answer






















          • Ok this way is perfect for me as well.
            – Ñ€üффп
            Apr 15 '14 at 13:46






          • 2




            Also see the -maxdepth option.
            – Smith John
            Apr 15 '14 at 20:11

















          up vote
          12
          down vote













          With GNU find there is no need to run basename for every single file, this will be much faster (especially if there is a lot of files):



          find lib -name '*.jar' -printf '%Pn'





          share|improve this answer



























            up vote
            10
            down vote













            How about (cd lib && echo *.jar), assuming that you don't have whitespace or special characters in the file names. Parent script never changes directory.






            share|improve this answer




















            • Spaces won't be an issue either.
              – terdon♦
              Apr 15 '14 at 14:39










            • This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
              – Graeme
              Apr 15 '14 at 15:14










            • Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
              – Graeme
              Apr 15 '14 at 15:16

















            up vote
            5
            down vote













            As Josh Jolly said in his answer, you should never parse ls, use the approach in his answer instead. Still, here's an awk solution to remove paths from file names, just don't use it with ls:



            find . | awk -F'/' 'print $NF'


            The -F'/' sets the field separator to / which means that the last field, $NF, will be the file name.






            share|improve this answer





























              up vote
              1
              down vote













              find is probably the way to go, but if you really, really do (you don't) want to strip off lib/ from ls -1, you can use sed:



              $ ls -1 lib/*.jar | sed 's#^lib/##'
              mylib_1.jar
              mylib_2.jar





              share|improve this answer





























                up vote
                0
                down vote













                You can do this using xargs with a --max-args (or the shorter alias -n) parameter:




                ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename
                ls --quoting-style=c -1 lib/*.jar | xargs -n 1 basename



                Note that we use --quoting-style=c to make sure spaces in filenames do not screw up xargs.






                share|improve this answer






















                • I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                  – yoni
                  May 5 '17 at 22:48


















                up vote
                -1
                down vote













                An alternative way solve your query is to list all the files using ls -R. Combine the output of ls command with grep to list only .jar files.
                You can use following command to do the same for your query:



                ls -R lib | grep jar| grep -v jar*





                share|improve this answer




















                • This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                  – Jules
                  Apr 16 '14 at 3:14










                • grep -v jar* would filter out results with file named like your quoted example.
                  – joshi.mohit86
                  Apr 16 '14 at 6:18










                • true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                  – Jules
                  Apr 19 '14 at 3:39











                • No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                  – joshi.mohit86
                  May 13 '14 at 10:07










                • No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                  – Jules
                  May 14 '14 at 11:35










                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: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                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%2f124887%2fis-it-possible-to-remove-folder-prefix-from-a-ls-command%23new-answer', 'question_page');

                );

                Post as a guest






























                7 Answers
                7






                active

                oldest

                votes








                7 Answers
                7






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                17
                down vote



                accepted










                Instead of parsing ls you should use find instead. Then you can also execute basename on each file to strip the leading directories:



                find lib/ -name '*.jar' -exec basename ;





                share|improve this answer






















                • Ok this way is perfect for me as well.
                  – Ñ€üффп
                  Apr 15 '14 at 13:46






                • 2




                  Also see the -maxdepth option.
                  – Smith John
                  Apr 15 '14 at 20:11














                up vote
                17
                down vote



                accepted










                Instead of parsing ls you should use find instead. Then you can also execute basename on each file to strip the leading directories:



                find lib/ -name '*.jar' -exec basename ;





                share|improve this answer






















                • Ok this way is perfect for me as well.
                  – Ñ€üффп
                  Apr 15 '14 at 13:46






                • 2




                  Also see the -maxdepth option.
                  – Smith John
                  Apr 15 '14 at 20:11












                up vote
                17
                down vote



                accepted







                up vote
                17
                down vote



                accepted






                Instead of parsing ls you should use find instead. Then you can also execute basename on each file to strip the leading directories:



                find lib/ -name '*.jar' -exec basename ;





                share|improve this answer














                Instead of parsing ls you should use find instead. Then you can also execute basename on each file to strip the leading directories:



                find lib/ -name '*.jar' -exec basename ;






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 15 '14 at 13:37









                terdon♦

                124k29236414




                124k29236414










                answered Apr 15 '14 at 13:30









                Josh Jolly

                1,292812




                1,292812











                • Ok this way is perfect for me as well.
                  – Ñ€üффп
                  Apr 15 '14 at 13:46






                • 2




                  Also see the -maxdepth option.
                  – Smith John
                  Apr 15 '14 at 20:11
















                • Ok this way is perfect for me as well.
                  – Ñ€üффп
                  Apr 15 '14 at 13:46






                • 2




                  Also see the -maxdepth option.
                  – Smith John
                  Apr 15 '14 at 20:11















                Ok this way is perfect for me as well.
                – Ñ€üффп
                Apr 15 '14 at 13:46




                Ok this way is perfect for me as well.
                – Ñ€üффп
                Apr 15 '14 at 13:46




                2




                2




                Also see the -maxdepth option.
                – Smith John
                Apr 15 '14 at 20:11




                Also see the -maxdepth option.
                – Smith John
                Apr 15 '14 at 20:11












                up vote
                12
                down vote













                With GNU find there is no need to run basename for every single file, this will be much faster (especially if there is a lot of files):



                find lib -name '*.jar' -printf '%Pn'





                share|improve this answer
























                  up vote
                  12
                  down vote













                  With GNU find there is no need to run basename for every single file, this will be much faster (especially if there is a lot of files):



                  find lib -name '*.jar' -printf '%Pn'





                  share|improve this answer






















                    up vote
                    12
                    down vote










                    up vote
                    12
                    down vote









                    With GNU find there is no need to run basename for every single file, this will be much faster (especially if there is a lot of files):



                    find lib -name '*.jar' -printf '%Pn'





                    share|improve this answer












                    With GNU find there is no need to run basename for every single file, this will be much faster (especially if there is a lot of files):



                    find lib -name '*.jar' -printf '%Pn'






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 15 '14 at 13:49









                    Graeme

                    24.5k46294




                    24.5k46294




















                        up vote
                        10
                        down vote













                        How about (cd lib && echo *.jar), assuming that you don't have whitespace or special characters in the file names. Parent script never changes directory.






                        share|improve this answer




















                        • Spaces won't be an issue either.
                          – terdon♦
                          Apr 15 '14 at 14:39










                        • This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
                          – Graeme
                          Apr 15 '14 at 15:14










                        • Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
                          – Graeme
                          Apr 15 '14 at 15:16














                        up vote
                        10
                        down vote













                        How about (cd lib && echo *.jar), assuming that you don't have whitespace or special characters in the file names. Parent script never changes directory.






                        share|improve this answer




















                        • Spaces won't be an issue either.
                          – terdon♦
                          Apr 15 '14 at 14:39










                        • This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
                          – Graeme
                          Apr 15 '14 at 15:14










                        • Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
                          – Graeme
                          Apr 15 '14 at 15:16












                        up vote
                        10
                        down vote










                        up vote
                        10
                        down vote









                        How about (cd lib && echo *.jar), assuming that you don't have whitespace or special characters in the file names. Parent script never changes directory.






                        share|improve this answer












                        How about (cd lib && echo *.jar), assuming that you don't have whitespace or special characters in the file names. Parent script never changes directory.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Apr 15 '14 at 14:36









                        Doug O'Neal

                        2,8021817




                        2,8021817











                        • Spaces won't be an issue either.
                          – terdon♦
                          Apr 15 '14 at 14:39










                        • This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
                          – Graeme
                          Apr 15 '14 at 15:14










                        • Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
                          – Graeme
                          Apr 15 '14 at 15:16
















                        • Spaces won't be an issue either.
                          – terdon♦
                          Apr 15 '14 at 14:39










                        • This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
                          – Graeme
                          Apr 15 '14 at 15:14










                        • Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
                          – Graeme
                          Apr 15 '14 at 15:16















                        Spaces won't be an issue either.
                        – terdon♦
                        Apr 15 '14 at 14:39




                        Spaces won't be an issue either.
                        – terdon♦
                        Apr 15 '14 at 14:39












                        This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
                        – Graeme
                        Apr 15 '14 at 15:14




                        This is a good idea and will probably be the fastest option. I would do printf '%sn' *.jar to get each file on a different line though.
                        – Graeme
                        Apr 15 '14 at 15:14












                        Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
                        – Graeme
                        Apr 15 '14 at 15:16




                        Or even printf '%s' *.jar to eliminate whitespace issues (although this is not the Q).
                        – Graeme
                        Apr 15 '14 at 15:16










                        up vote
                        5
                        down vote













                        As Josh Jolly said in his answer, you should never parse ls, use the approach in his answer instead. Still, here's an awk solution to remove paths from file names, just don't use it with ls:



                        find . | awk -F'/' 'print $NF'


                        The -F'/' sets the field separator to / which means that the last field, $NF, will be the file name.






                        share|improve this answer


























                          up vote
                          5
                          down vote













                          As Josh Jolly said in his answer, you should never parse ls, use the approach in his answer instead. Still, here's an awk solution to remove paths from file names, just don't use it with ls:



                          find . | awk -F'/' 'print $NF'


                          The -F'/' sets the field separator to / which means that the last field, $NF, will be the file name.






                          share|improve this answer
























                            up vote
                            5
                            down vote










                            up vote
                            5
                            down vote









                            As Josh Jolly said in his answer, you should never parse ls, use the approach in his answer instead. Still, here's an awk solution to remove paths from file names, just don't use it with ls:



                            find . | awk -F'/' 'print $NF'


                            The -F'/' sets the field separator to / which means that the last field, $NF, will be the file name.






                            share|improve this answer














                            As Josh Jolly said in his answer, you should never parse ls, use the approach in his answer instead. Still, here's an awk solution to remove paths from file names, just don't use it with ls:



                            find . | awk -F'/' 'print $NF'


                            The -F'/' sets the field separator to / which means that the last field, $NF, will be the file name.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 15 '14 at 13:39

























                            answered Apr 15 '14 at 13:34









                            terdon♦

                            124k29236414




                            124k29236414




















                                up vote
                                1
                                down vote













                                find is probably the way to go, but if you really, really do (you don't) want to strip off lib/ from ls -1, you can use sed:



                                $ ls -1 lib/*.jar | sed 's#^lib/##'
                                mylib_1.jar
                                mylib_2.jar





                                share|improve this answer


























                                  up vote
                                  1
                                  down vote













                                  find is probably the way to go, but if you really, really do (you don't) want to strip off lib/ from ls -1, you can use sed:



                                  $ ls -1 lib/*.jar | sed 's#^lib/##'
                                  mylib_1.jar
                                  mylib_2.jar





                                  share|improve this answer
























                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    find is probably the way to go, but if you really, really do (you don't) want to strip off lib/ from ls -1, you can use sed:



                                    $ ls -1 lib/*.jar | sed 's#^lib/##'
                                    mylib_1.jar
                                    mylib_2.jar





                                    share|improve this answer














                                    find is probably the way to go, but if you really, really do (you don't) want to strip off lib/ from ls -1, you can use sed:



                                    $ ls -1 lib/*.jar | sed 's#^lib/##'
                                    mylib_1.jar
                                    mylib_2.jar






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Apr 15 '14 at 15:35

























                                    answered Apr 15 '14 at 13:40







                                    user61786



























                                        up vote
                                        0
                                        down vote













                                        You can do this using xargs with a --max-args (or the shorter alias -n) parameter:




                                        ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename
                                        ls --quoting-style=c -1 lib/*.jar | xargs -n 1 basename



                                        Note that we use --quoting-style=c to make sure spaces in filenames do not screw up xargs.






                                        share|improve this answer






















                                        • I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                                          – yoni
                                          May 5 '17 at 22:48















                                        up vote
                                        0
                                        down vote













                                        You can do this using xargs with a --max-args (or the shorter alias -n) parameter:




                                        ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename
                                        ls --quoting-style=c -1 lib/*.jar | xargs -n 1 basename



                                        Note that we use --quoting-style=c to make sure spaces in filenames do not screw up xargs.






                                        share|improve this answer






















                                        • I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                                          – yoni
                                          May 5 '17 at 22:48













                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote









                                        You can do this using xargs with a --max-args (or the shorter alias -n) parameter:




                                        ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename
                                        ls --quoting-style=c -1 lib/*.jar | xargs -n 1 basename



                                        Note that we use --quoting-style=c to make sure spaces in filenames do not screw up xargs.






                                        share|improve this answer














                                        You can do this using xargs with a --max-args (or the shorter alias -n) parameter:




                                        ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename
                                        ls --quoting-style=c -1 lib/*.jar | xargs -n 1 basename



                                        Note that we use --quoting-style=c to make sure spaces in filenames do not screw up xargs.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited May 5 '17 at 22:49

























                                        answered May 5 '17 at 17:52









                                        yoni

                                        1013




                                        1013











                                        • I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                                          – yoni
                                          May 5 '17 at 22:48

















                                        • I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                                          – yoni
                                          May 5 '17 at 22:48
















                                        I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                                        – yoni
                                        May 5 '17 at 22:48





                                        I didn't notice that. Thank you! Found this gem on another stack exchange. You can introduce quotes to ls results with --quoting-style=c. So the resulting full command would be: ` ls --quoting-style=c -1 lib/*.jar | xargs --max-args 1 basename`
                                        – yoni
                                        May 5 '17 at 22:48











                                        up vote
                                        -1
                                        down vote













                                        An alternative way solve your query is to list all the files using ls -R. Combine the output of ls command with grep to list only .jar files.
                                        You can use following command to do the same for your query:



                                        ls -R lib | grep jar| grep -v jar*





                                        share|improve this answer




















                                        • This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                                          – Jules
                                          Apr 16 '14 at 3:14










                                        • grep -v jar* would filter out results with file named like your quoted example.
                                          – joshi.mohit86
                                          Apr 16 '14 at 6:18










                                        • true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                                          – Jules
                                          Apr 19 '14 at 3:39











                                        • No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                                          – joshi.mohit86
                                          May 13 '14 at 10:07










                                        • No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                                          – Jules
                                          May 14 '14 at 11:35














                                        up vote
                                        -1
                                        down vote













                                        An alternative way solve your query is to list all the files using ls -R. Combine the output of ls command with grep to list only .jar files.
                                        You can use following command to do the same for your query:



                                        ls -R lib | grep jar| grep -v jar*





                                        share|improve this answer




















                                        • This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                                          – Jules
                                          Apr 16 '14 at 3:14










                                        • grep -v jar* would filter out results with file named like your quoted example.
                                          – joshi.mohit86
                                          Apr 16 '14 at 6:18










                                        • true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                                          – Jules
                                          Apr 19 '14 at 3:39











                                        • No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                                          – joshi.mohit86
                                          May 13 '14 at 10:07










                                        • No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                                          – Jules
                                          May 14 '14 at 11:35












                                        up vote
                                        -1
                                        down vote










                                        up vote
                                        -1
                                        down vote









                                        An alternative way solve your query is to list all the files using ls -R. Combine the output of ls command with grep to list only .jar files.
                                        You can use following command to do the same for your query:



                                        ls -R lib | grep jar| grep -v jar*





                                        share|improve this answer












                                        An alternative way solve your query is to list all the files using ls -R. Combine the output of ls command with grep to list only .jar files.
                                        You can use following command to do the same for your query:



                                        ls -R lib | grep jar| grep -v jar*






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Apr 15 '14 at 14:04









                                        joshi.mohit86

                                        1




                                        1











                                        • This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                                          – Jules
                                          Apr 16 '14 at 3:14










                                        • grep -v jar* would filter out results with file named like your quoted example.
                                          – joshi.mohit86
                                          Apr 16 '14 at 6:18










                                        • true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                                          – Jules
                                          Apr 19 '14 at 3:39











                                        • No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                                          – joshi.mohit86
                                          May 13 '14 at 10:07










                                        • No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                                          – Jules
                                          May 14 '14 at 11:35
















                                        • This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                                          – Jules
                                          Apr 16 '14 at 3:14










                                        • grep -v jar* would filter out results with file named like your quoted example.
                                          – joshi.mohit86
                                          Apr 16 '14 at 6:18










                                        • true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                                          – Jules
                                          Apr 19 '14 at 3:39











                                        • No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                                          – joshi.mohit86
                                          May 13 '14 at 10:07










                                        • No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                                          – Jules
                                          May 14 '14 at 11:35















                                        This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                                        – Jules
                                        Apr 16 '14 at 3:14




                                        This would fail badly if there were a subdirectory that also contains jar files, or a file named for example "list-of-jars.txt".
                                        – Jules
                                        Apr 16 '14 at 3:14












                                        grep -v jar* would filter out results with file named like your quoted example.
                                        – joshi.mohit86
                                        Apr 16 '14 at 6:18




                                        grep -v jar* would filter out results with file named like your quoted example.
                                        – joshi.mohit86
                                        Apr 16 '14 at 6:18












                                        true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                                        – Jules
                                        Apr 19 '14 at 3:39





                                        true. it would also filter out all the intended files. Now I look at it again, I can see no circumstances where the command you suggest would actually produce any output at all...
                                        – Jules
                                        Apr 19 '14 at 3:39













                                        No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                                        – joshi.mohit86
                                        May 13 '14 at 10:07




                                        No, it would display files like mylib_2.jar and filter out files like list-of-jars.txt.
                                        – joshi.mohit86
                                        May 13 '14 at 10:07












                                        No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                                        – Jules
                                        May 14 '14 at 11:35




                                        No, it doesn't. I just tried it. find development -name '*.jar' | wc -l -> 70. ls -R development | grep jar| grep -v jar* -> no output at all.
                                        – Jules
                                        May 14 '14 at 11:35

















                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f124887%2fis-it-possible-to-remove-folder-prefix-from-a-ls-command%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        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?