Copying the files after filter

Hi Guys,

i want copy the all files another direcotry after filtering the command.
and tried as like below...it's not working.

   ls -ltr|awk '{print $9}'|grep "images\|\.htm"|cp *.* /home/oracle 

Thanks

ls -lrt | awk '{ print $NF}' | egrep ".jpeg|.htm" | xargs -n1 -i cp {} /home/oracle

Note , to search for images, I used .jpeg here, change it as per your requirement.

Thanks...

Sorry for the confusion, i want filter the .images directory ( Direcory name like this index_1154.images) direcory and .htm files in the list of directory.
i did wrong in the above filter. Please can you correct me.

You mean, you want to "search for a directory name and copy it" ? if so,

ls -lrt | awk '{ print $NF}' | egrep ".images|.htm" | xargs -n1 -i cp -R {} /home/oracle

try find command if you want jpeg or html files being moved to /home/oracle.

find ./images -type f \( -name "*.jpg" -o -name "*.html" \) -exec 'cp' '{}' '/home/oracle/' 

@panyam thank for feeback..

in a directory it contains list of directories names, .htm and .txt files. and i want filter the directories like name as (index_3898.images,index_3899.images so on......).

I need to filter the .images directories and .htm files and moved to /home/oracle
means moved to entrie direcotry and.html files to /home/oracle

Thanks,

Did you try with the command I have given in my previous post. Is it not working?

Try:

find . -name "*.images" -o -name "*.htm" -exec cp -R {} /home/oracle \;

@panyam and @CarloM, i tried both command not working.
coping only .htm file and not copied .images directories...

Sorry, I missed a grouping:

find . \( -name "*.images" -o -name "*.htm" \) -exec cp -R {} /home/oracle \;

Still i am facing same issue.. Let me explain again...

  ls -ltr 
drwxr-xr-x 2 oracle dba  4096 Mar  6 16:52 test_4680.images
drwxr-xr-x 2 oracle dba  4096 Mar  6 16:52 index_4697.images
drwxr-xr-x 2 oracle dba  4096 Mar  6 16:52 test_4698.images
drwxr-xr-x 2 oracle dba  4096 Mar  6 16:52 test_4699.images
drwxr-xr-x 2 oracle dba  4096 Mar  6 16:52 test_4701.images
-rw-r--r-- 1 oracle dba  7203 Mar  5 15:42 test_2389.htm
-rw-r--r-- 1 oracle dba  6691 Mar  5 15:42 test_2312.htm
-rw-r--r-- 1 oracle dba  8355 Mar  5 15:42 test_2205.htm
-rw-r--r-- 1 oracle dba  7435 Mar  5 15:42 test_2187.htm
-rw-r--r-- 1 oracle dba  7424 Mar  5 15:42 test_1327.htm
-rw-r--r-- 1 oracle dba  7424 Mar  5 15:42 test_1328.txt
-rw-r--r-- 1 oracle dba  7424 Mar  5 15:42 test_1328.doc 

i want filter only .images directory and .htm files?

---------- Post updated at 08:28 AM ---------- Previous update was at 08:25 AM ----------

Really sorry.. i didn't notice those files... it's working all ...
Thanks lot guys. ROCK

At least this worked for me :

 for fil in `ls -lrt | awk '{ print $NF}'  | egrep ".images|.html"`; 
 do 
 cp -R $fil /home/oracle
 done
1 Like

@panyam,Great...............

That is useless use of ls

Using bash built-ins:

for file in *.{images,html}
do
   cp -R "$file" /home/oracle/
done
1 Like