How to write linux find command with for loop on Jupyter












0















I am able to have a list of file names in a list named 'a' using the linux terminal command on Jupiter as follows;



a=!find . -type f ! -name '*.*' -print


To have the files names without extensions, the corresponding command works on linux terminal;



find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


But how can I run this command on Jupyter assigning it to a name 'a' like above. The below code didn`t work.



a=!find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


I have tried changing the indentation of lines as well, i get syntax error, or nothing. From my search on the command line of for loop on Jupiter the '!' should be perhaps in a different location. How can I make it work?










share|improve this question























  • Define "didn't work". How is it not working as expected or intended? Why are you not using Python's internal file traversal rather than escaping out to a shell? Are you aware that there is no such thing as an "file extension" in a POSIX environment?

    – DopeGhoti
    Jan 23 at 22:30













  • thanks. I meant if i preserve to indentation i get invalid syntax for 'pathname do', if i remove the indentations, nothing happens but when i print 'a' i get ''sh: 1: sh: Syntax error: end of file unexpected (expecting "done")''. I am not familiar with Python's internal file traversal or the POSIX environment yet.

    – kutlus
    Jan 23 at 22:51











  • You may need to escape the newlines by ending each line of the multi-line quoted content with a backslash, or just deal with it being one ugly line and get rid of the newlines altogether.

    – DopeGhoti
    Jan 23 at 22:53
















0















I am able to have a list of file names in a list named 'a' using the linux terminal command on Jupiter as follows;



a=!find . -type f ! -name '*.*' -print


To have the files names without extensions, the corresponding command works on linux terminal;



find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


But how can I run this command on Jupyter assigning it to a name 'a' like above. The below code didn`t work.



a=!find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


I have tried changing the indentation of lines as well, i get syntax error, or nothing. From my search on the command line of for loop on Jupiter the '!' should be perhaps in a different location. How can I make it work?










share|improve this question























  • Define "didn't work". How is it not working as expected or intended? Why are you not using Python's internal file traversal rather than escaping out to a shell? Are you aware that there is no such thing as an "file extension" in a POSIX environment?

    – DopeGhoti
    Jan 23 at 22:30













  • thanks. I meant if i preserve to indentation i get invalid syntax for 'pathname do', if i remove the indentations, nothing happens but when i print 'a' i get ''sh: 1: sh: Syntax error: end of file unexpected (expecting "done")''. I am not familiar with Python's internal file traversal or the POSIX environment yet.

    – kutlus
    Jan 23 at 22:51











  • You may need to escape the newlines by ending each line of the multi-line quoted content with a backslash, or just deal with it being one ugly line and get rid of the newlines altogether.

    – DopeGhoti
    Jan 23 at 22:53














0












0








0








I am able to have a list of file names in a list named 'a' using the linux terminal command on Jupiter as follows;



a=!find . -type f ! -name '*.*' -print


To have the files names without extensions, the corresponding command works on linux terminal;



find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


But how can I run this command on Jupyter assigning it to a name 'a' like above. The below code didn`t work.



a=!find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


I have tried changing the indentation of lines as well, i get syntax error, or nothing. From my search on the command line of for loop on Jupiter the '!' should be perhaps in a different location. How can I make it work?










share|improve this question














I am able to have a list of file names in a list named 'a' using the linux terminal command on Jupiter as follows;



a=!find . -type f ! -name '*.*' -print


To have the files names without extensions, the corresponding command works on linux terminal;



find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


But how can I run this command on Jupyter assigning it to a name 'a' like above. The below code didn`t work.



a=!find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +


I have tried changing the indentation of lines as well, i get syntax error, or nothing. From my search on the command line of for loop on Jupiter the '!' should be perhaps in a different location. How can I make it work?







linux






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 23 at 22:10









kutluskutlus

596




596













  • Define "didn't work". How is it not working as expected or intended? Why are you not using Python's internal file traversal rather than escaping out to a shell? Are you aware that there is no such thing as an "file extension" in a POSIX environment?

    – DopeGhoti
    Jan 23 at 22:30













  • thanks. I meant if i preserve to indentation i get invalid syntax for 'pathname do', if i remove the indentations, nothing happens but when i print 'a' i get ''sh: 1: sh: Syntax error: end of file unexpected (expecting "done")''. I am not familiar with Python's internal file traversal or the POSIX environment yet.

    – kutlus
    Jan 23 at 22:51











  • You may need to escape the newlines by ending each line of the multi-line quoted content with a backslash, or just deal with it being one ugly line and get rid of the newlines altogether.

    – DopeGhoti
    Jan 23 at 22:53



















  • Define "didn't work". How is it not working as expected or intended? Why are you not using Python's internal file traversal rather than escaping out to a shell? Are you aware that there is no such thing as an "file extension" in a POSIX environment?

    – DopeGhoti
    Jan 23 at 22:30













  • thanks. I meant if i preserve to indentation i get invalid syntax for 'pathname do', if i remove the indentations, nothing happens but when i print 'a' i get ''sh: 1: sh: Syntax error: end of file unexpected (expecting "done")''. I am not familiar with Python's internal file traversal or the POSIX environment yet.

    – kutlus
    Jan 23 at 22:51











  • You may need to escape the newlines by ending each line of the multi-line quoted content with a backslash, or just deal with it being one ugly line and get rid of the newlines altogether.

    – DopeGhoti
    Jan 23 at 22:53

















Define "didn't work". How is it not working as expected or intended? Why are you not using Python's internal file traversal rather than escaping out to a shell? Are you aware that there is no such thing as an "file extension" in a POSIX environment?

– DopeGhoti
Jan 23 at 22:30







Define "didn't work". How is it not working as expected or intended? Why are you not using Python's internal file traversal rather than escaping out to a shell? Are you aware that there is no such thing as an "file extension" in a POSIX environment?

– DopeGhoti
Jan 23 at 22:30















thanks. I meant if i preserve to indentation i get invalid syntax for 'pathname do', if i remove the indentations, nothing happens but when i print 'a' i get ''sh: 1: sh: Syntax error: end of file unexpected (expecting "done")''. I am not familiar with Python's internal file traversal or the POSIX environment yet.

– kutlus
Jan 23 at 22:51





thanks. I meant if i preserve to indentation i get invalid syntax for 'pathname do', if i remove the indentations, nothing happens but when i print 'a' i get ''sh: 1: sh: Syntax error: end of file unexpected (expecting "done")''. I am not familiar with Python's internal file traversal or the POSIX environment yet.

– kutlus
Jan 23 at 22:51













You may need to escape the newlines by ending each line of the multi-line quoted content with a backslash, or just deal with it being one ugly line and get rid of the newlines altogether.

– DopeGhoti
Jan 23 at 22:53





You may need to escape the newlines by ending each line of the multi-line quoted content with a backslash, or just deal with it being one ugly line and get rid of the newlines altogether.

– DopeGhoti
Jan 23 at 22:53










1 Answer
1






active

oldest

votes


















0














I solved this problem in a different way if anyone has a similar issue. I used the command line
a=!find . -type f ! -name '*.*' -print



this created a list of filenames with extensions. I removed the extensions from each element.



files = [os.path.splitext(fname)[0] for fname in a]





share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f496339%2fhow-to-write-linux-find-command-with-for-loop-on-jupyter%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I solved this problem in a different way if anyone has a similar issue. I used the command line
    a=!find . -type f ! -name '*.*' -print



    this created a list of filenames with extensions. I removed the extensions from each element.



    files = [os.path.splitext(fname)[0] for fname in a]





    share|improve this answer




























      0














      I solved this problem in a different way if anyone has a similar issue. I used the command line
      a=!find . -type f ! -name '*.*' -print



      this created a list of filenames with extensions. I removed the extensions from each element.



      files = [os.path.splitext(fname)[0] for fname in a]





      share|improve this answer


























        0












        0








        0







        I solved this problem in a different way if anyone has a similar issue. I used the command line
        a=!find . -type f ! -name '*.*' -print



        this created a list of filenames with extensions. I removed the extensions from each element.



        files = [os.path.splitext(fname)[0] for fname in a]





        share|improve this answer













        I solved this problem in a different way if anyone has a similar issue. I used the command line
        a=!find . -type f ! -name '*.*' -print



        this created a list of filenames with extensions. I removed the extensions from each element.



        files = [os.path.splitext(fname)[0] for fname in a]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 24 at 0:45









        kutluskutlus

        596




        596






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496339%2fhow-to-write-linux-find-command-with-for-loop-on-jupyter%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 reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

            is 'sed' thread safe

            How to make a Squid Proxy server?