Hello, I am attempting to copy a series of files using a wildcard into a new subdirectory. however, I am clearly doing something wrong as it is not working. I want to copy all files in the directory that start with the letters kl but have other letters after this initial two letters into another directory.
here is what I have tried so far. I admit that I am not strong in Unix
Also once this is done I want an easy way to move these files from the remote unix server to my desktop.
Last edited by methyl; 02-15-2012 at 06:32 PM..
Reason: correct code tags an lay it out a bit
You didn't do anything wrong exactly, but there were just too many filenames to cram into one cp call. Handling that many filenames gets a bit more complicated. Too many arguments is too many arguments -- ls kl* or any other variations like that won't work either. You'll need to print a full listing with ls, filter what you want with grep, and read in a loop. Put them through a stream so we can read them one at a time in other words, instead of trying to cram them all into one line.
Notice how grep takes a different kind of expression than you'd do in the shell. It doesn't match the entire line, it can match part of the line anywhere, so we have to stick a ^ in the front to tell it "only look for kl at the beginning of the line". And we don't have to match the rest of it since knowing it has a 'kl' in front is good enough.
Then we read lines one by one and feed them into cp one by one. Remove the 'echo' once you've tested it and are sure it does what you want.
I want to copy all files in the directory that start with the letters kl but have other letters after this initial two letters into another directory.
No mention of subdirectories.
(My reference to "more robust" was of course referring to the examples in post #1).
Quote:
I want to copy all files in the directory that start with the letters kl but have other letters after this initial two letters into another directory.
The more times I read this sentence the more ambiguous it becomes. Is it the filenames which start with "kl" or the directory names which start with "kl" I wonder?
I've gone for the files and Corona688 has gone for the directories.
He used -r, which implied he needed it, meaning some had to be directories. He might have just put it on habitually.
Your command would recursively hunt down all files named 'kl*' even if it was nested 5-deep in the current folder, not just the current folder where he wanted it to look.
Quote:
I've gone for the files and Corona688 has gone for the directories.
I'm trying to do this exact same thing, so far I have created this to move files
i've named my script CP.sh
#!/bin/bash
cd /root/my-documents/NewDir/
for f in *.doc
do cp -v $f root/my-documents/NewDir $f{%.doc}
done
When i go to run this in the console i type, bin/sh/ CP.sh
but it... (7 Replies)
All,
I need to grab and rename common files from several unique directory structures. For example, the directory structures looks like:
/unique_dir/common/common/common/person_name_dir/common_file.txt
There are over 90,000 of these text files that I'd like to put in a single directory as... (5 Replies)
Hi All,
I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files.
To Do
From Directory : /myproject/MainDir
To Directory : /myproject/data
List of files need to copy is in the file: /myproject/filesList.txt
... (4 Replies)
Hi All,
I'm trying to list some files from my log directory
and files are like this
log.20110302_20.gz
log.20110302_21.gz
log.20110302_22.gz
log.20110302_23.gz
log.20110303_00.gz
log.20110303_01.gz
log.20110303_02.gz
............
log.20110311_22.gz
log.20110311_23.gz... (2 Replies)
I have a question regarding Perl scripting.
If I want to say open files that all look like this and assign them to a filehandle and then assign the filehandle to a variable, how do I do this?
The file names are
strand1.fa.gz.tmp
strand2.fa.gz.tmp
strand3.fa.gz.tmp
strand4.fa.gz.tmp
...... (6 Replies)
Hi All
I am having hundred over file in the below pattern.
AA050101.INI
BB090101.INI
.
.
ZX980101.INI
Need to rename these files with an extension .bak
AA050101.INI.bak
BB090101.INI.bak
.
.
ZX980101.INI.bak (5 Replies)
I am userB and have a dir
/temp1
This dir is owned by me.
How do I recursively copy files from another users's dir userA?
I need to preserve the original user who created files, original group information, original create date, mod date etc.
I tried
cp -pr /home/userA/* .
... (2 Replies)
hi
I want to copy all files from the current directory and move to .archive file.
Moreover,I want to add .bak to each file name, that will be copied.
How can I do that? (4 Replies)
How do I use cat (presumably with a sh script) to combine all the files in a directory without listing them individually.
Thank you for your patience with this very elementary question.:) (3 Replies)
Hi all,
Would like to rename all files using wildcards - if at all possible!
As an example I have the following files:
Nov01_df
Nov02_df
Nov03_df
......
Nov28_df
Nov29_df
Nov30_df
I'd like to have these renamed as "df??" where ?? is the number from the original file name.
Any... (5 Replies)