0

I have a long list of folder as follow:

001_bat_3513
002_mon_3213
003_bat_3515
004_btt_3540
005_bat_4513
055_bpt_8523
056_bot_3513
058_bat_1513
.
.

From this list: How can I copy the folders ( and all its content) that has the part " bat" in its name?

2

You can use shell globbing for this:

cp -rp *bat*/ /destination/

Here *bat*/ will expand to directories having bat in their names.

Or using find, which will work even if there are so many files that you get an error because the command line is too long:

find . -maxdepth 1 -type d -name '*bat*' -exec cp -rpt /destination {} +
  • Thank you very much . Kindly one more question. how can i rename all the folders by removing the first three numbers from it is name? – user88036 Jul 16 '16 at 14:35
  • @goro Thats easy. Could you please ask it as a new question with your expected file names? – heemayl Jul 16 '16 at 14:36
  • New question or just edit this one? – user88036 Jul 16 '16 at 14:37
  • @goro No, this one is already answered. You should mark it as accepted and ask any new query as a new one..check the site FAQ. – heemayl Jul 16 '16 at 14:38
  • @don_crissti Yeah..edited.. – heemayl Jul 16 '16 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy