Can the “rename” command distinguish between directories and files? [duplicate]












2
















This question already has an answer here:




  • How do I rename a directory via the command line?

    6 answers




I need to rename only directories and not files, and I want to do it with rename.



Is there any way to do it?



It says nothing in the manual about differentiating between directories and files.



This command changes everything, no matter directory or files:



rename 's/ /n/g' *


This command solved my problem:



rename 's/ /n/g' */


I need a slash behind it.










share|improve this question















marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Those links are helpful to me.

    – JulianLai
    Jan 15 at 10:30






  • 4





    Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of rename... I suggest you remove that part of your question and post it as an answer!

    – Zanna
    Jan 15 at 14:50






  • 2





    by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.

    – RoVo
    Jan 15 at 16:09






  • 1





    @JulianLai It causes problems for people that use ls | wc -l to count the number of objects, or generally when parsing the output of ls -- which is discouraged, but widely done.

    – PerlDuck
    Jan 15 at 16:20






  • 2





    and many many more things.

    – RoVo
    Jan 15 at 16:20
















2
















This question already has an answer here:




  • How do I rename a directory via the command line?

    6 answers




I need to rename only directories and not files, and I want to do it with rename.



Is there any way to do it?



It says nothing in the manual about differentiating between directories and files.



This command changes everything, no matter directory or files:



rename 's/ /n/g' *


This command solved my problem:



rename 's/ /n/g' */


I need a slash behind it.










share|improve this question















marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Those links are helpful to me.

    – JulianLai
    Jan 15 at 10:30






  • 4





    Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of rename... I suggest you remove that part of your question and post it as an answer!

    – Zanna
    Jan 15 at 14:50






  • 2





    by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.

    – RoVo
    Jan 15 at 16:09






  • 1





    @JulianLai It causes problems for people that use ls | wc -l to count the number of objects, or generally when parsing the output of ls -- which is discouraged, but widely done.

    – PerlDuck
    Jan 15 at 16:20






  • 2





    and many many more things.

    – RoVo
    Jan 15 at 16:20














2












2








2









This question already has an answer here:




  • How do I rename a directory via the command line?

    6 answers




I need to rename only directories and not files, and I want to do it with rename.



Is there any way to do it?



It says nothing in the manual about differentiating between directories and files.



This command changes everything, no matter directory or files:



rename 's/ /n/g' *


This command solved my problem:



rename 's/ /n/g' */


I need a slash behind it.










share|improve this question

















This question already has an answer here:




  • How do I rename a directory via the command line?

    6 answers




I need to rename only directories and not files, and I want to do it with rename.



Is there any way to do it?



It says nothing in the manual about differentiating between directories and files.



This command changes everything, no matter directory or files:



rename 's/ /n/g' *


This command solved my problem:



rename 's/ /n/g' */


I need a slash behind it.





This question already has an answer here:




  • How do I rename a directory via the command line?

    6 answers








command-line directory rename






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 15 at 14:46









Zanna

50.8k13136241




50.8k13136241










asked Jan 15 at 8:48









JulianLaiJulianLai

6942621




6942621




marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Those links are helpful to me.

    – JulianLai
    Jan 15 at 10:30






  • 4





    Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of rename... I suggest you remove that part of your question and post it as an answer!

    – Zanna
    Jan 15 at 14:50






  • 2





    by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.

    – RoVo
    Jan 15 at 16:09






  • 1





    @JulianLai It causes problems for people that use ls | wc -l to count the number of objects, or generally when parsing the output of ls -- which is discouraged, but widely done.

    – PerlDuck
    Jan 15 at 16:20






  • 2





    and many many more things.

    – RoVo
    Jan 15 at 16:20



















  • Those links are helpful to me.

    – JulianLai
    Jan 15 at 10:30






  • 4





    Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of rename... I suggest you remove that part of your question and post it as an answer!

    – Zanna
    Jan 15 at 14:50






  • 2





    by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.

    – RoVo
    Jan 15 at 16:09






  • 1





    @JulianLai It causes problems for people that use ls | wc -l to count the number of objects, or generally when parsing the output of ls -- which is discouraged, but widely done.

    – PerlDuck
    Jan 15 at 16:20






  • 2





    and many many more things.

    – RoVo
    Jan 15 at 16:20

















Those links are helpful to me.

– JulianLai
Jan 15 at 10:30





Those links are helpful to me.

– JulianLai
Jan 15 at 10:30




4




4





Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of rename... I suggest you remove that part of your question and post it as an answer!

– Zanna
Jan 15 at 14:50





Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of rename... I suggest you remove that part of your question and post it as an answer!

– Zanna
Jan 15 at 14:50




2




2





by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.

– RoVo
Jan 15 at 16:09





by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.

– RoVo
Jan 15 at 16:09




1




1





@JulianLai It causes problems for people that use ls | wc -l to count the number of objects, or generally when parsing the output of ls -- which is discouraged, but widely done.

– PerlDuck
Jan 15 at 16:20





@JulianLai It causes problems for people that use ls | wc -l to count the number of objects, or generally when parsing the output of ls -- which is discouraged, but widely done.

– PerlDuck
Jan 15 at 16:20




2




2





and many many more things.

– RoVo
Jan 15 at 16:20





and many many more things.

– RoVo
Jan 15 at 16:20










1 Answer
1






active

oldest

votes


















3














rename does not distinguish between files and folders.





The shell is responsible for expanding the wildcard * into files and folders.





  • * will be expanded to all non-hidden files and folders.


  • */ will be expanded to all non-hidden folders.


But I don't know of any way to expand to files only. You can use find -exec instead.



only folders:





rename 's/ /n/g' */


or



find . -maxdepth 1 -type d -exec rename 's/ /n/g' {} +


Only files:



find . -maxdepth 1 -type f -exec rename 's/ /n/g' {} +


Note that find will also find hidden files unlike * (unless you turn on the dotglob shell option by running shopt -s dotglob).





zsh seems to be able to match files only with wildcards.






Disclaimer: I would not recommend adding newlines to file names as it may cause trouble and break many scripts.







share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    rename does not distinguish between files and folders.





    The shell is responsible for expanding the wildcard * into files and folders.





    • * will be expanded to all non-hidden files and folders.


    • */ will be expanded to all non-hidden folders.


    But I don't know of any way to expand to files only. You can use find -exec instead.



    only folders:





    rename 's/ /n/g' */


    or



    find . -maxdepth 1 -type d -exec rename 's/ /n/g' {} +


    Only files:



    find . -maxdepth 1 -type f -exec rename 's/ /n/g' {} +


    Note that find will also find hidden files unlike * (unless you turn on the dotglob shell option by running shopt -s dotglob).





    zsh seems to be able to match files only with wildcards.






    Disclaimer: I would not recommend adding newlines to file names as it may cause trouble and break many scripts.







    share|improve this answer






























      3














      rename does not distinguish between files and folders.





      The shell is responsible for expanding the wildcard * into files and folders.





      • * will be expanded to all non-hidden files and folders.


      • */ will be expanded to all non-hidden folders.


      But I don't know of any way to expand to files only. You can use find -exec instead.



      only folders:





      rename 's/ /n/g' */


      or



      find . -maxdepth 1 -type d -exec rename 's/ /n/g' {} +


      Only files:



      find . -maxdepth 1 -type f -exec rename 's/ /n/g' {} +


      Note that find will also find hidden files unlike * (unless you turn on the dotglob shell option by running shopt -s dotglob).





      zsh seems to be able to match files only with wildcards.






      Disclaimer: I would not recommend adding newlines to file names as it may cause trouble and break many scripts.







      share|improve this answer




























        3












        3








        3







        rename does not distinguish between files and folders.





        The shell is responsible for expanding the wildcard * into files and folders.





        • * will be expanded to all non-hidden files and folders.


        • */ will be expanded to all non-hidden folders.


        But I don't know of any way to expand to files only. You can use find -exec instead.



        only folders:





        rename 's/ /n/g' */


        or



        find . -maxdepth 1 -type d -exec rename 's/ /n/g' {} +


        Only files:



        find . -maxdepth 1 -type f -exec rename 's/ /n/g' {} +


        Note that find will also find hidden files unlike * (unless you turn on the dotglob shell option by running shopt -s dotglob).





        zsh seems to be able to match files only with wildcards.






        Disclaimer: I would not recommend adding newlines to file names as it may cause trouble and break many scripts.







        share|improve this answer















        rename does not distinguish between files and folders.





        The shell is responsible for expanding the wildcard * into files and folders.





        • * will be expanded to all non-hidden files and folders.


        • */ will be expanded to all non-hidden folders.


        But I don't know of any way to expand to files only. You can use find -exec instead.



        only folders:





        rename 's/ /n/g' */


        or



        find . -maxdepth 1 -type d -exec rename 's/ /n/g' {} +


        Only files:



        find . -maxdepth 1 -type f -exec rename 's/ /n/g' {} +


        Note that find will also find hidden files unlike * (unless you turn on the dotglob shell option by running shopt -s dotglob).





        zsh seems to be able to match files only with wildcards.






        Disclaimer: I would not recommend adding newlines to file names as it may cause trouble and break many scripts.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 15 at 17:00









        wjandrea

        9,25442663




        9,25442663










        answered Jan 15 at 16:17









        RoVoRoVo

        7,3661841




        7,3661841















            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents