Using cp for copying multiples files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using cp for copying multiples files
# 1  
Old 03-29-2010
Bug Using cp for copying multiples files

Hi all,

I've got this question about using cp for copying multiples files from the same source directory to another directory, considering that my working directory ain't the same of the source directory.

Let me give you a simple example what I'm talking about:

Suppose the following files here:

/usr/home/rod/file1.txt
/usr/home/rod/file2.pdf

Now, suppose that:

$pwd
/

And what I would like to know is:

is there a way of using cp for copying file1.txt and file2.pdf without having to type the absolute path for each of those files?

I was thinking of something like:

cp /usr/home/rod/{file1.txt, file2.pdf} /tmp

By doing that, file1.txt and file2.pdf would be copied to the destination folder /tmp, and then I wouldn't need to type the absolute path twice, avoiding the traditional approach like:

cp /usr/home/rod/file1.txt /usr/home/rod/file2.pdf /tmp

Please, note that my working directory, i.e, the output of the pwd command, is different of the directory where the files I want to copy are.

In my previous example, pwd returns /

Also, shell might be bash or csh.

Any help?
Thanks in advance.

Best regards,

rod~
# 2  
Old 03-29-2010
Only in bash". Execute the commands in a subshell.

Code:
(
cd /usr/home/rod
cp file1.txt file2.pdf /tmp
)

Never found a reason to use "csh".
# 3  
Old 03-29-2010
Hi methyl
Thanks for replying me.

I mentioned about csh because sometimes I use FreeBSD and csh is its default shell.
I understand what you suggested me to do and that works fine.
However, I'm still wondering if there is a 'more direct' way of doing that task... lol
Thanks again.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

Copying files

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)
Discussion started by: MKTM_93_SIMP
7 Replies

3. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

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)
Discussion started by: linuxadmin
4 Replies

4. Shell Programming and Scripting

awk on multiples files

Ques from newbie I want to total column X from large number of files, and view totals for each file separately with the filename. I have tried: for i in `ls -1 *.pattern`; do cat "$i" | awk '{SUM += $4} END { printf("%8d\t%8d\n", $i,SUM) }'; done does not work. appreciate your help (5 Replies)
Discussion started by: analyst
5 Replies

5. Shell Programming and Scripting

Extracting/condensing text from multiple files to multiples files

Hi Everyone, I'm really new to all this so I'm really hoping someone can help. I have a directory with ~1000 lists from which I want to extract lines from and write to new files. For simplicity lets say they are shopping lists and I want to write out the lines corresponding to apples to a new... (2 Replies)
Discussion started by: born2phase
2 Replies

6. Shell Programming and Scripting

Copying Files

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)
Discussion started by: thelakbe
2 Replies

7. UNIX for Advanced & Expert Users

copying of files by userB, dir & files owned by userA

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)
Discussion started by: Hangman2
2 Replies

8. Solaris

Copying Files and

I am new user to solaris and installed solaris operating system on full Harddisk 120Gb. I am unable to copy music files to desktop and /home directory. One thing happened while registering is- i entered login-root and its password. The message prompted your system is crashed. Is it because of... (1 Reply)
Discussion started by: patilmukundraj
1 Replies

9. UNIX for Dummies Questions & Answers

Email multiples attachment files

I have a program the will split a large file into smaller files. It works great. I, however, have problem of email these file out to other people: I may have 1 or more files afer SPLIT datafileaa datafileab datafileac manually: mailx -s "data" email@email.com<datafileaa mailx -s... (5 Replies)
Discussion started by: bobo
5 Replies

10. UNIX for Dummies Questions & Answers

Copying files

I like to know the command structure of copying files/directories from a unix box using telnet session to a windows box. (4 Replies)
Discussion started by: alpheusm
4 Replies
Login or Register to Ask a Question