Solved

UNIX - Copy files

Posted on 2011-09-30
11
418 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
EXCHANGE 2007, SCRIPTS 67 79
unix example issues 18 92
vi editor showing strange character when i hit spacebar everytime 2 67
mobaxterm not able to change directory 28 164
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

825 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