Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8045281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:29:54+00:00 2026-06-05T05:29:54+00:00

I’m looking to write a bash script that will recursively find all .less files

  • 0

I’m looking to write a bash script that will recursively find all .less files in a directory and create a .css file with the same name in a parent css directory using lessc. Visually it looks like this.

Before:

/css
/less
    a.less
    b.less
/whatever
    /css
    /less
        c.less
        d.less

After:

/css
    a.css
    b.css
/less
    a.less
    b.less
/whatever
    /css
        c.css
        d.css
    /less
        c.less
        d.less

What I’ve been able to figure out so far is that I can find all the files using:

find . -name *.less

And I can generate individual files using:

lessc foo.less > ../css/foo.css

My problem comes trying to pipe the results of the find into lessc. Per this question I can see how the results of find can be piped into cat, but the same approach isn’t working for me with lessc.

In general I’m just having trouble putting the pieces together. Any help would be appreciated.

Thanks.

Edit

This is what worked for me. Thanks @ghoti!

find . -name \*.less -print | sed -rne 's:(.*)/less/([^/]+).less$:lessc & > \1/css/\2.css:p' | sh
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:29:55+00:00Added an answer on June 5, 2026 at 5:29 am

    You’ve got all the ingredients. You just need the recipe. 🙂

    And there are multiple recipes.

    Normally, you can use find‘s -exec option to execute things based on what it finds. However, you’re limited in what you can name things. For example, if you were to use this:

    find . -name \*.less -exec lessc {} ../css/{}.css
    

    you would create files in a css directory in the parent from where find is running, and files would be named things like a.less.css, b.less.css, etc. That’s not good. You’d need to embed dirname and such into your command, and then things get impossible to manage, with too many quotes and backslashes.

    When I have to do pattern-matting AND changes like this, I often resort to pipes. Here’s what I’d do:

    find . -name \*.less -print | \
      sed -rne 's:(.*)/less/([^/]+).less$:lessc & > \1/css/\2.css:p'
    

    The find gets your files, as you’d expect. Then the sed script turns them into command lines. The output of this is a collection of lessc command lines which you can simply pipe into sh once you’ve verified that they look right.

    Here are the results.

    Before:

    [ghoti@pc ~/tmp1]$ find . -type f -print
    ./whatever/less/c.less
    ./whatever/less/d.less
    ./less/a.less
    ./less/b.less
    [ghoti@pc ~/tmp1]$ 
    

    Then the test run:

    [ghoti@pc ~/tmp1]$ find . -name \*.less -print | sed -rne 's:(.*)/less/([^/]+).less$:cat & > \1/css/\2.css:p'
    cat ./whatever/less/c.less > ./whatever/css/c.css
    cat ./whatever/less/d.less > ./whatever/css/d.css
    cat ./less/a.less > ./css/a.css
    cat ./less/b.less > ./css/b.css
    [ghoti@pc ~/tmp1]$ 
    

    Then the final run, and results.

    [ghoti@pc ~/tmp1]$ find . -name \*.less -print | sed -rne 's:(.*)/less/([^/]+).less$:cat & > \1/css/\2.css:p' | sh
    [ghoti@pc ~/tmp1]$ find . -type f -print
    ./css/b.css
    ./css/a.css
    ./whatever/less/c.less
    ./whatever/less/d.less
    ./whatever/css/d.css
    ./whatever/css/c.css
    ./less/a.less
    ./less/b.less
    [ghoti@pc ~/tmp1]$ 
    

    For my test, I replaced lessc with cat, since less isn’t installed on my workstation.

    Note that this will only work with simple filenames like the ones in your example. If you have spaces or possibly other “special” characters, it will break.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.