Unix command to move files for certain pattern

Posted on 2006-05-22
Last Modified: 2011-10-21
Hi expert

Under unix, what command I can use to move a list of file to a certain name

For example

files contains character "abc"

mv XXXabcXXX to XXXXXX (remove the "abc" of the file name)

Question by:4eyesgirl
    LVL 84

    Assisted Solution

    perl -e 'for( <*abc*> ){ ($to=$_)=~s/abc//; rename $_,$to or warn "$_, $to $!" }'

    Author Comment

    Can you explain to me what this does?  I don't know Perl that well

    LVL 51

    Accepted Solution

    # not as nice as perl, but just standard unix:
    ls *abc* | sed -e 's#\(.*\)abc\(.*\)#mv & \1\2#'|sh

    # for testing, just omit the final |sh

    Author Comment

    Thanks ahoffman and ozo, both solutions work!!! so I split the point equally.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
    Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now