How to copy only the files of a folder(including subfolder's files), but not the folder itself in shell

38,019

Solution 1

Try:

scp /path/to/file/* user@server:/path/to/files/

it will complain about not copying directories.

If you want to copy the files in the directories under /path/to/, you can do:

scp /path/to/*/* user@server:/path/to/files/

Solution 2

Simply use the GLOBIGNORE='*/.:*/..:dirname1:dirname2' to exclude the specified directories from the * glob? And then:

scp -r /path/to/file/* user@server:/path/to/files/
Share:
38,019

Related videos on Youtube

Ricky
Author by

Ricky

Newbie in the world of unix.

Updated on September 18, 2022

Comments

  • Ricky
    Ricky over 1 year

    In Openssh, On the client, the content of path/to/file must be copied to Server. All files in /path/to/file on the client must be copied to /path/to/files on the server. Note: only copy files, no folders! and files of subfolders. please give the command.

    • Ricky
      Ricky over 10 years
      scp –r user@server:/path/to/file/* /path/to/file.. but the result is that desired_folder is not a regular file. and in this folder i want all the files to be copied. but not the desired_folder.
    • Anthon
      Anthon over 10 years
      maybe you should read the man page for scp and not just add random options. -r means recursively copy entire directories, kind of strange to add that to scp if that is not what you want.
    • Ricky
      Ricky over 10 years
      yes.. thats okey. i had removed that. but still it is not being copied.what about the result that its not a regular file.
  • Ricky
    Ricky over 10 years
    but in above command the folder is also being copied,that is not desired man
  • Ricky
    Ricky over 10 years
    but i want the files of the directories to be copied.