Solved

UNIX - Copy files

Posted on 2011-09-30
11
421 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 166 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 167 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 167 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

717 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