Linux Find Command -Successfull

I have completed Find command Saturday & Sunday also The same task is unassigned and assigns back the same task.

find /var/www/html/beta -name ‘*.php’ -exec cp --parents {} /beta ;

3 Likes

Hi @sjeyendran I did the same way as u suggested but it gave me the following error:

find: missing argument to `-exec’

Please advice

find /var/www/html/beta -name '*.php' -exec cp --parents {} /beta \;

2 Likes

@player001…I tried the above command but the output shows permission denied…Even though i changed the permission but still getting same error…

Because you are trying to find from non root user. Try to use sudo or switch into root user.

Below worked for me

find /var/www/html/ecommerce -type f -name '*.js' -exec cp --parents {} /ecommerce \;

To Validate 
find /var/www/html/ecommerce -type f -name '*.js' | wc -l
find /ecommerce -type f -name '*.js' | wc -l

Hi @player001 @Inderpreet

I used a script to solve this task like below

sudo find /var/www/html/media -name ‘*.css’ > /home/banner/file.txt

cd /home/banner

vi copy_script.sh
#!/bin/bash
for file in $( cat /home/banner/file.txt)
do
sudo cp --parents $file /media
done

and then executed this script file

./copy_script.sh

then i checked the destination

cd /media

and there i found /media/var

when i tried to find recursively like

ls -R /media

every .css file is available along with parent directory structure.

unfortunately i was not confident enough to finish task with above approach, later i tried without script

sudo find /var/www/html/media -name ‘*.css’ -exec cp --parents {} /media ;

and the task is successful !!

but now i wish to know if the script method will pass or fail the task, if anyone checked the script can explain if that method will pass or fail the test it would be very nice.