linux how to move listed files? [duplicate] - linux

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.

Related

How to exclude some extension files when copy a folder [duplicate]

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"

Copy files from find command output [duplicate]

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

Stuck trying to copy files to a new directory under specific guidelines

I'm trying to copy all files from a folder that start with a capital letter into another folder.
So far i've used the find command to actually find the files
find /examplefolder -type f -name "[[:upper:]]*"
and i'm able to find them no problem
I tried to just replace the find command with cp and that does not work then i tried to pipe into the cp command and I failed yet again
Use the -exec option for find
find /examplefolder -type f -name "[[:upper:]]*" -exec cp {} /my/new/shiny/folder/ \;
I was able to do it by piping in to cp with xargs and the -I argument
find /examplefolder -type f -name "[[:upper:]]*" | xargs -I % cp % /copied_directory

Move and rename the files - bash script

I'm new to unix shell/bash scripting . My requirement is as follows :
The current directory contains a lot of dynamic folders and the data file is available only in the last sub folder.
I need to move the data file to the home folder and rename the datafile's name as the current directory's name.
Could you please help in writing the bash script for the same.
--update--
I tried the following to move file to the parent directory:
find . -mindepth 2 -type f -print -exec mv {} . \;
After trying out many options , the following worked
find . -mindepth 2 -type f -print -exec mv {} . \;
dirFullPath=`pwd`
fileName=`echo $dirFullPath | awk -F"/" '{print $(NF)}'`
mv *.0 $fileName.tab
Any other better solutions is appreciated, Thanks.!!

Want to find any reference in any file to a certain string in linux [duplicate]

This question already has answers here:
how to find files containing a string using egrep
(7 answers)
Closed 8 years ago.
I am trying to search All .PHP files or ALL .SH files for any reference that contains:
'into tbl_free_minutes_mar'
I have command line access to the server but the files may be scattered in different directories.
For all directories everywhere,
find / -type f \( -name '*.php' -o -name '*.sh' \) \
-exec fgrep 'into tbl_free_minutes_mar' {} \+
For fewer directories elsewhere, just give a list of paths instead of /. To just list the matching files, try fgrep -l. If your file names might not always match the wildcards in the -name conditions, maybe scan all files.
find / -type f \( -name \*.php -o -name \*.sh \) -exec grep 'into tbl_free_minutes_mar' {} /dev/null \;
Change find / ... to to something less all-encompassing if you know the general area that you want to look in, e.g. find /home ...
Provided /base/path is the path where you want to start looking this will get you a list of files:
find /base/path -type f -iregex '.*\.\(php\|sh\)$' -exec grep -l 'into tbl_free_minutes_mar' '{}' \;

Resources