Solved

UNIX - Copy files

Posted on 2011-09-30
11
416 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
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
cp file* /export/home/user1/
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
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
Comment Utility
I couldn't copy files from my home directory.

cp: cannot access /export/home/dw/orig_me20110901085115.lst
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 166 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
@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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now