Copy files with extension .sh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy files with extension .sh
# 1  
Old 09-20-2013
Copy files with extension .sh

Hi all...

I am trying to copy all my shell script to some directory using following command, I want to simplify it by not using awk..please some one help me....


Code:
find -name "*.sh" | awk -F"/" '{a=$NF;gsub(".sh",x,a);cmd="cp"" " $0" ""/home/akshay/MY_ALL/"a"_"++i".sh";system(cmd)}'

# 2  
Old 09-20-2013
i have not tried this, but you can do something like

Code:
for i in `find -name "*.sh"`; do cp $i <destination>; done

# 3  
Old 09-20-2013
Do you want a matching tree, or all in one dir (who wins on name collisions?). Do we need to worry about the command line length? They say any fool can code, but it takes some thought to write requirements. For one dir (last wins):
Code:
find * -name '*.sh' -type f | xargs -n101 echo | while read mf
do
cp $mf <destination>
done

Narrative: Find the files one per line, use xargs to echo them out in larger groups (up to 101) on one line, cp each multi-file group to the destination. This has 99+% economy of scale on cp calls but still starts cp long before find is done.

For same subtree:
Code:
find * -name '*.sh' -type f | cpio -pd <destination>

If you are copying within the same device (mount), don't want to rewrite them and care about space, you can hard link with 'ln' in place of 'cp'.

Last edited by DGPickett; 09-20-2013 at 03:50 PM..
# 4  
Old 09-21-2013
Thanks DGPickett

I would like to run script from
Code:
 /home/user

reason behind this is I can copy all script to new directory including duplicates., that is why in #1 I used
Code:
 ++i

so that it should not overwrite any file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

3. Shell Programming and Scripting

Python - glob () - How to grep same files with different extension files

Hi I Have a directory and i have some files below abc.txt abc.gif gtee.txt ghod.pid umni.log unmi.tar How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

4. UNIX for Dummies Questions & Answers

Copy files with same name but different extension from 2 different directory

Hi all, i have 2 directory of files, the first directory(ext1directory) contain files of extension .ext1 and the second directory(allextdirectory) contains files of multiple extensions (.ext1,.ext2,.ext3,..) so i want to copy the files from directory 2(allextdirectory) that have the same name... (8 Replies)
Discussion started by: shelladdict
8 Replies

5. UNIX for Dummies Questions & Answers

copy all files matching the request and change the extension at the same time

Hi everyone When I'm starting my script I'm giving to it two parameters: script.sh ext1 ext2 I need to copy all files in a directory fitting ext1, to the same folder, with the same names, but with the changed extension to ext2. Till now I've just managed to do it for only 1 file, but I... (16 Replies)
Discussion started by: vacuity93
16 Replies

6. UNIX for Dummies Questions & Answers

How to list files with no extension together with *.prog files?

Hi, I know that to list files with no extension, we can use.. ls -1 | grep -v "\." And to list .prog files, we can use.. ls -1 *.prog or ls -1 | grep '.prog$' (4 Replies)
Discussion started by: adshocker
4 Replies

7. UNIX for Dummies Questions & Answers

cp times.csv{,.bak} -> makes a copy with *.bak extension. How this works?

Hi cp times.csv{,.bak}makes a copy with *.bak extension. How this works? Whats the gimmick here? Can't google special characters (1 Reply)
Discussion started by: slashdotweenie
1 Replies

8. Shell Programming and Scripting

copy files with new extension in same directory

I've been able to find all the extensionless files named photos using the command: find /usr/local/apache/htdocs -name photos -print0 I need to copy those files to the name photos.php in their same directory. I've found a bunch of xarg examples for moving to other directories but I wasn't... (7 Replies)
Discussion started by: dheian
7 Replies

9. HP-UX

Files without extension

I am brand new to hp unix systems. I see some files without extension on this system. If I type name of the file it shows me so many detail but does not take me back to command prompt. What are these files and how do I come back to command prompt? Please help (1 Reply)
Discussion started by: rajahindustani
1 Replies

10. UNIX for Advanced & Expert Users

File extension search and copy

Hi need to know if we can write a shell script to find files for a particular format;s ie both .csv and .txt in a particular folder and then copy them to a new folder on a dialy basis. Does anyone know how this can be accomplished? Thanks, Sandeep (20 Replies)
Discussion started by: bsandeep_80
20 Replies
Login or Register to Ask a Question