This question already has answers here:
Bash command-line to rename wildcard
(2 answers)
Closed 7 months ago.
I want to rename files of the type file_name (1).extension to file_name.extension. How can i use rename to delete the " (1)" string ?
you can use the find [path_to_dir] -type f -name "*file_extension*" -exec sh -c 'x="{}"; mv "$x" "${x}_renamed"' \;
In my case, i find all .txt files in a folders, and rename it to filename_renamed.
find . -type f -name '*txt*' -exec sh -c 'x="{}"; mv "$x" "${x}_renamed"' \;
Related
This question already has answers here:
Exclude files in a shell script that has a certain pattern
(2 answers)
Closed 3 months ago.
I need copy folderA to folder_B, but I want exclude all *.xml when copy.
How can I use a linux cmd to implement the requirement in ternimal?
I was asked to find a different way than cp -rf sourcedir/!(*.xml) dest_dir/
Suggesting to use find command:
cp $(find sourcedir -type f -not -name "*.xml") dest_dir
Suggesting to try and tune the find command:
find sourcedir -type f -not -name "*.xml"
This question already has an answer here:
Solution to error 'find: missing argument to -exec' with find -exec cp {} TARGET_DIR + [closed]
(1 answer)
Closed 5 months ago.
i am using below command to enlist the direcoties with name containing linuxS_x86 .
" find src/ -type d -name 'linuxS_x86' "
it is giving correct output also.
Now i want to copy the files from the all the directories enlisted with above command .
Please help me out ..?
use find with -exec
find src/ -type d -name 'linuxS_x86' -exec cp -rf {} <some destination> \;
{} is the placeholder to pass a single file name to -exec called command, and \; is to finish -exec.
or else you could use ls instead of find. Then pass found files to xargs to do cp command.
ls linuxS_x86/* | xargs -n 1 -I{} cp {} ./bbb
This question already has answers here:
Find and copy files
(5 answers)
Closed 3 years ago.
I tried to redirect the result in a directory but it won't let me do it. What am I doing wrong ?
find Documents/ -type f -regextype posix-egrep -regex ".+\.(doc|err|out)$" > Poubelle/
bash: Poubelle/: Is a directory
What I'm trying to do is move the listed files in Poubelle.
Thank you in advance
Like #Barmar said in the comments you need to use exec command with mv and cp.
you can try using below command :
Moving files to Dir :
find Documents/ -type f -regextype posix-egrep -regex ".+\.(doc|err|out)$" -exec mv {} Poubelle/ \;
Copying files to Dir :
find Documents/ -type f -regextype posix-egrep -regex ".+\.(doc|err|out)$" -exec cp {} Poubelle/ \;
And you can also use rsync. A simpler form is :
rsync source destination
For other options read here.
This question already has answers here:
Rename multiple files based on pattern in Unix
(24 answers)
Closed 3 years ago.
I have several files with the extension *.php in different subfolders in the folder /root/Hello. I try to rename all .php files to .html but I want to keep the structure i.e. the path to the file should remain identical.
I found all files with the following command:
find /root/Hello -name "*.php"
But I don't know how I can rename all files with *.php to *.html and keep the structure I think I must use:
-exec
But I don't which argument I should use with -exec
use find:
find /path -depth -name "*.php" -exec sh -c 'mv "$1" "${1%.php}.html"' _ {} \;
This question already has answers here:
Moving multiple files having spaces in name (Linux)
(3 answers)
Closed 7 years ago.
I have a find command which returns two files. Is there anyway of then copying those files to another directory? My find command is below if that will help.
find "$TEST" -iname "DTWD_????.JPG" -printf "%f\n"
New to linux, thanks.
You just need to use the -exec argument
find "$TEST" -iname "DTWD_????.JPG" -printf "%f\n" -exec mv -t '/home' '{}' +