cp Command not finding files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp Command not finding files
# 1  
Old 01-28-2012
cp Command not finding files

I am completely stumped. I am attempting to run the cp command in the following context:

Code:
cp '/home/spinner0205/directory/directory/*.log' '/home/spinner0205/otherdirectory/combined.txt'

The "directory" contains anywhere from 5-50 something.log files.

I want to copy the contents of these files and combine them into one file (combined.txt) in "otherdirectory". It immediately complains though that it cannot find any *.log file to copy.

Code:
cp: cannot stat `/home/spinner0205/directory/directory/*.log': No such file or directory

If it makes any difference I can run the mv command with this same context and it works perfectly. (moving all *.log files to another directory)

(and yes the files do exist, I'm staring at them right now Smilie)
# 2  
Old 01-28-2012
Code:
for i in /home/spinner0205/directory/directory/*.log
do
   cat $i >> /home/spinner0205/otherdirectory/combined.txt
done

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 01-28-2012
When using single quotes, the shell takes your * as a literal value.

So, don't use single quotes. (In this case.)

Next, use cat to conCATenate files:
Code:
cat /home/spinner0205/directory/directory/*.log >/home/spinner0205/otherdirectory/combined.txt


Last edited by edehont; 01-28-2012 at 11:21 PM..
This User Gave Thanks to edehont For This Post:
# 4  
Old 01-28-2012
Shell will not expand *.log if is within single quote. Below should do the job
Code:
cat /home/spinner0205/directory/directory/*.log > /home/spinner0205/otherdirectory/combined.txt

To avoid too long a command line when the shell expands, you may want to cd to that directory to do the copy:
Code:
cd /home/spinner0205/directory/directory
cat *.log > /home/spinner0205/otherdirectory/combined.txt

This User Gave Thanks to chihung For This Post:
# 5  
Old 01-29-2012
Silly me. No more single quotes and switched to cat. All is well. Thanks everyone.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Finding a file with ls command

/volumes/NEWS_MASTERS/News Masters/AGA143 SCHWEIZER SETUP AM v2.mxf /volumes/NEWS_MASTERS/News Masters/AGA143 SCHWEIZER SETUP AM v3.mxf /volumes/NEWS_MASTERS/News Masters/AGA143 SCHWEIZER SETUP EM v2.mxf /volumes/NEWS_MASTERS/News Masters/AGA143 SCHWEIZER SETUP EM v3.mxf the above 4 files... (2 Replies)
Discussion started by: sbrady
2 Replies

2. UNIX for Dummies Questions & Answers

Finding the modified timestamp of files from the piped output of du command

Version Info +++++++++++++++ RHEL 5.4 Since ls command lists file sizes in Bytes which can be long I use du command like below. I have run the du command for the below files as shown below. But I want pipe this output to ls command just to see the modified timestamp for these files. ... (7 Replies)
Discussion started by: kraljic
7 Replies

3. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

4. Shell Programming and Scripting

Finding older files using find command

Hi All, I want to find files which are older than 15 days. I have written a command as below, find -mtime +15 -print I understand (System date - last modified time of a file) should be greater than or equal to 15 days. This command returns files which are 15 days old.. i.e... (1 Reply)
Discussion started by: nshan
1 Replies

5. Shell Programming and Scripting

finding multiple files using find command

I am trying to search for 2 files using the find command as below find -name file1.txt -a -name file2.txt It doesn't give a result although the files exist in the folder, however when i try the following find -name file1.txt -o -name file2.txt It does give me the result. ./file2.txt... (4 Replies)
Discussion started by: vivek_damodaran
4 Replies

6. Shell Programming and Scripting

Need Help in Finding Files ::

Hi All , i am in progress of creating a script which should find a file a.txt , in a particular root directory . This should actually Search all the Sub directories and copy those files and FTP it to a server . Need a Input how to Proceed on this Thankyou guys (6 Replies)
Discussion started by: raghav1982
6 Replies

7. Shell Programming and Scripting

finding files

Hi guys just wondering if there is a way to scan the whoel file system and find files that have not been used over a number of days, using the script (5 Replies)
Discussion started by: musicmancanora
5 Replies

8. Shell Programming and Scripting

Help with finding files

Ok, here it is: I have a system that logs certain files every day. Every time a new day dawns, the system will create a folder with the name that is respective to the day's date (12-06-07) and start putting new files in that folder. I have another system that needs these files. I am going to:... (1 Reply)
Discussion started by: bbbngowc
1 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

10. Solaris

finding files

Hi, I am trying to find all files ending in a particular file extension, ie all files ending with .pdf find / -name *.pdf But this doesnt seem to work, ie it doesnt find the files, is there a better way of doing this? I am using solaris 9 (4 Replies)
Discussion started by: frustrated1
4 Replies
Login or Register to Ask a Question