0

I found the number of files in /dev/shm/split/1/ to be 42806 using:

/bin/ls -lU /dev/shm/split/1/ | wc -l

What I can't seem to find anywhere online is how to select a certain range, say from 21404-42806, and use scp to securely copy those files. Then, for management purposes, I would like to move the files I copied to another folder, say /dev/shm/split/2/.

How do I do that using CentOS?

I tried:

sudo chmod 400 ~/emails/name.pem ; ls -1 /dev/shm/split/1/ | sed -n '21443,42806p' | xargs -i scp -i ~/emails/name.pem {} root@ipaddress:/dev/shm/split/2/ 

This produced:

no such file or directory

errors on all of the files...

technerdius
  • 253
  • 3
  • 6
  • 16

1 Answers1

1

ls itself lists files relative to the directory you give. This means your ls prints the filenames in the directory, but later on, scp doesn't have the path to them. You can fix this two ways:

Give the path to scp:

ls -1 /dev/shm/split/1/ | sed -n '21443,42806p' | xargs -i \
  scp -i ~/emails/name.pem /dev/shm/split/1/{} root@ipaddress:/dev/shm/split/2/ 

Change to that directory and it will work:

cd /dev/shm/split/1/; ls -1 | sed -n '21443,42806p' | xargs -i \
  scp -i ~/emails/name.pem {} root@ipaddress:/dev/shm/split/2/
Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • It is working as we speak. There was an extra \ in your code I removed between xargs and scp commands. Thank you so much! – technerdius Oct 26 '15 at 19:19
  • 1
    The `\` is dividing the command on two lines (basically escaping the newline character) so it is readable in this code block and you can actually copy-paste it to your command-line prompt (Good to know ;-) ) – Jakuje Oct 26 '15 at 19:42
  • No problem at all. Thank you once again for your assistance. :) – technerdius Oct 26 '15 at 20:32