Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UNIX - Copy files

Posted on 2011-09-30
11
Medium Priority
?
430 Views
Last Modified: 2012-05-12
let's say unix server name: prod_server

My home directory in prod_server is
/export/home/user1

after login I sudo to folder "dw"
for example sudo su - dw (then enter the password)

Now my pwd in prod_server is /export/home/dw

I like to copy files from /export/home/dw/file* to my home directory which is
/export/home/user1

How do I do that? Please advise
 
0
Comment
Question by:IT_ETL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36893007
cp file* /export/home/user1/
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36893056
It might well be that "dw" (the user you are now because of "sudo su - dw")
does not have write permission to your home directory.

In this case leave dw (by issuing exit), go to your home dir "/export/home/user1"
and issue "cp /export/home/dw/file* ."
because it's more likely that you (user1) have read permission to dw's home dir.

wmp
0
 

Author Comment

by:IT_ETL
ID: 36893889
I couldn't copy files from my home directory.

cp: cannot access /export/home/dw/orig_me20110901085115.lst
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36893921
From? I thought you were going to copy TO your home directory?

Anyway, did you try my first suggestion?

If this doesn't work either none of both users can access the other one's home.

You will have to do the copy as root (sudo su -). Use the "-p" flag of cp in this case.
0
 

Author Comment

by:IT_ETL
ID: 36894280
Yes, I want copy files from /export/home/dw to my home directory

My pwd is my home directory which is /export/home/user1. Could you post the exact command here including "sudo su" and "-p"?


0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 664 total points
ID: 36894324
If you (user1) are allowed to issue "sudo cp ..." (setting it up this way would have been a good idea, by the way), you can issue:

sudo cp /export/home/dw/orig* /export/home/user1/

If you're only allowed to issue "sudo su - ..." you must issue:

sudo su -
cp -p /export/home/dw/orig* /export/home/user1/
exit

Please examine the file permissions after copying.
It is probable that you (user1) will not have read access to them.
So adjust (after copying) the ownership so that the files will belong to you:

Either (if allowed):

sudo chown /export/home/user1/orig* user1

or:

sudo su -
chown /export/home/user1/orig* user1
exit
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36894375
Sorry, made a mistake! (It's late at night here ...).

sudo chown user1 /export/home/user1/orig*

or

chown user1 /export/home/user1/orig*
0
 
LVL 6

Accepted Solution

by:
Tomunique earned 668 total points
ID: 36896958
Ok.. here's an alternative, without changing the permisisons of your directories

sudo su - dw

mkdir /tmp/dwtemp    # make a temporary location

cp file* /tmp/dwtemp   # Copy files to temp
chmod 777 /tmp/dwtemp/*    /temp/dwtemp     #make sure others can mess with them

exit
# Now you're back to our original ID
cp /tmp/dwtemp/* .     #copy files from temp to your home

sudo su - dw              # Have to be owner to remove files from temp
rm -fr /tmp/dwtemp     # remove copies from temp

exit    # bye

Tom
0
 
LVL 4

Assisted Solution

by:Anacreo
Anacreo earned 668 total points
ID: 36907062
how about:

This should work in theory:
sudo dw tar -cvf - . | tar -xvf -

You could test it with this line before doing the above:
sudo dw tar -cvf - . | tar -tvf -

Which should produce a list of files it would be moving.
0
 
LVL 4

Expert Comment

by:Anacreo
ID: 36907066
Woops whoa...

Make sure you do:
sudo - dw tar -cvf - . | tar -tvf -

If you don't do the sudo - dw it would try and work from your current directory.
0
 
LVL 6

Expert Comment

by:Tomunique
ID: 36907629
@Anacreo  I think you've got a great idea there, but the syntax is wrong on the sudo command

And, we need to be in the dw home directory.

I'm pretty sure this will work

sudo -u dw tar -cf - -C /home/dw file* | tar -xf -

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Utilizing an array to gracefully append to a list of EmailAddresses
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question