2

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:

/something/abc/file.css
/anyting/xyz/file.css

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

  /something/abc/file.css   (name of the file)
  /anyting/xyz/file.css
  • elaborate your file.css (name of the file) . Be more exact – RomanPerekhrest Nov 23 '17 at 12:16
2

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.