?
Solved

UNIX - Copy files

Posted on 2011-09-30
11
Medium Priority
?
424 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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!

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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
Course of the Month12 days, 20 hours left to enroll

777 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