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

  • SEARCH
  • Home
  • 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 8539555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:23:37+00:00 2026-06-11T11:23:37+00:00

I have a folder test in it there is 20 other folder with different

  • 0

I have a folder “test” in it there is 20 other folder with different names like A,B ….(actually they are name of people not A, B…) I want to write a shell script that go to each folder like test/A and rename all the .c files with A[1,2..] and copy them to “test” folder. I started like this but I have no idea how to complete it!

#!/bin/sh
for file in `find test/* -name '*.c'`; do mv $file $*; done

Can you help me please?

  • 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-11T11:23:38+00:00Added an answer on June 11, 2026 at 11:23 am

    This code should get you close. I tried to document exactly what I was doing.

    It does rely on BASH and the GNU version of find to handle spaces in file names. I tested it on a directory fill of .DOC files, so you’ll want to change the extension as well.

    #!/bin/bash
    V=1
    SRC="."
    DEST="/tmp"
    
    #The last path we saw -- make it garbage, but not blank.  (Or it will break the '[' test command
    LPATH="/////" 
    #Let us find the files we want
    find $SRC -iname "*.doc" -print0 | while read -d $'\0' i
      do
      echo "We found the file name... $i";
    
      #Now, we rip off the off just the file name.
      FNAME=$(basename "$i" .doc)
      echo "And the basename is $FNAME";
      #Now we get the last chunk of the directory
      ZPATH=$(dirname "$i"  | awk -F'/' '{ print $NF}' )
      echo "And the last chunk of the path is... $ZPATH"
    
      # If we are down a new path, then reset our counter.
      if [ $LPATH == $ZPATH ]; then
        V=1
      fi;
      LPATH=$ZPATH
    
      # Eat the error message
      mkdir $DEST/$ZPATH 2> /dev/null 
      echo cp \"$i\" \"$DEST/${ZPATH}/${FNAME}${V}\"
      cp "$i" "$DEST/${ZPATH}/${FNAME}${V}"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got main folder: c:\test And there I have 2 folders: Movies and Photos.
I have a class Test which is in lib folder and I want to
I have folder on which i want to apply security like the current user
I have three files in a folder 'test' one.php two.php print.html And i have
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
I have this test code that just saves an XML file to a folder.
I have a file watch directory named FileWatch C:\Users\MyFolder\FileWatch\Test The FileWatch folder is the
I have folder structure and I would like to create JSON objects based on
I have folder home/admin. In this folder there is index.php. When i access to
I have a folder with scripts with a name pattern of UPDATE[x.y.z] where x.y.z

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.