1835268 Members
2446 Online
110078 Solutions
New Discussion

File copy

 
Rushank
Super Advisor

File copy

I want to copy few files from here to there.
These files all are start with tw* But my problem is I don't want few files those are having .txt extension but they also are starts with tw*
cp tw* to destination dir would copy all the files starts with tw , but I don't want one with .txt
How do I do this.


8 REPLIES 8
Sandip Ghosh
Honored Contributor

Re: File copy

Prepare a list of files and then give "|grep -v *.txt. It will give the list of the file you want to copy. Thegive the copy command.

Sandip
Good Luck!!!
Pete Randall
Outstanding Contributor

Re: File copy

Rushank,

find / \( -name 'tw*' -a ! -name '*.txt' \) -exec rm {} \;

would do it for you.

Pete

Pete
Helen French
Honored Contributor

Re: File copy

This might be another solution:

# cd dir
# find . \( -name 'tw*' ! -name '*.txt' \) -depth | cpio -pdlmuva dest_dir

The 'expression' checks the condition and copy the files matches to the dest_dir
Life is a promise, fulfill it!
MANOJ SRIVASTAVA
Honored Contributor

Re: File copy

Hi Rushank


do a

ls tw* | grep -v txt > list

cp 'cat list' < destiantion >


Manoj Srivastava
S.K. Chan
Honored Contributor

Re: File copy

This could work too .. for example ..

# cd /tmp
# find . \( -name 'tw*' -a ! -name '*.txt' \) -exec cp {} /test \;

Mladen Despic
Honored Contributor

Re: File copy

cp `ls -d tw* | grep -v 'txt$'` "destination_directory"
Mladen Despic
Honored Contributor

Re: File copy

In my previous example, the files "tw*" ending in "txt" are filtered out. If you want to include the dot in front of "txt", try this:

cp `ls -d tw* | grep -v '\.txt$'` "destination_directory"
harry d brown jr
Honored Contributor

Re: File copy


find /tmp -type f -name "tw*" | grep -v "\.txt$" | xargs -i cp {} /var/tmp

Will copy files, that start with "tw" and aren't ".txt" files, from /tmp to /var/tmp.

Pete,

I'm not sure he want's to remove the original (the -exec rm {} clause).

live free or die
harry
Live Free or Die