I'm doing a find of all files with certain extension and then I copy them to a certain folder, but most of them are overwritten because they have the same name. How can I, with a Linux command, get the path of the file and replace it on the name file?

Right now I'm using this command:

find . -name "*.css" | xargs cp -t /folder/AllCssFiles/

so if I have two files on a certain path like this:


when I use the command I should get something like this on the AllCssFiles folder:

  /something/abc/file.css   (name of the file)
  • elaborate your file.css (name of the file) . Be more exact Nov 23, 2017 at 12:16

1 Answer 1


You can use -execdir and the command rename1.

find ./ -type f -name "*.css" -execdir rename -v "s/search/replace/" {} \;

if you are not sure, you can use rename with -n

  -n, -nono
           No action: print names of files to be renamed, but don't rename.

1 This is the syntax for perl-rename which is called rename on Debian-based systems, prename in some and perl-rename in others.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .