1

I have a folder called "employee" and within that folder there are sub-folders with each employee name.

employee
>> amar
>> akbar
>> anthony

Each of these folders contain 1 or 2 files. There are around 50 employees. I want to copy all those files into a new folder "/home/employee_files" without the sub-folders. In other words, all the files should be available when I list "ls /home/employee_files"

shantanuo
  • 3,579
  • 8
  • 49
  • 66

3 Answers3

3
$ cp employee/*/* /home/employee_files/
quanta
  • 51,413
  • 19
  • 159
  • 217
0
find /home/attachments/ -type f -exec cp {} /home/attachments_all/ \;

Beware that if two files have the same name, you'll only end up with one of them.

An alternate approach is to copy files to a name that is a hash of their contents.

#!/bin/bash
cp "$1" /home/attachments_all/`sha1sum "$1" | cut -f 1 -d ' '`

That will give you a unique copy of each file regardless of what it was named before. You can alter the script to provide you an index file.

Jeff Ferland
  • 20,547
  • 2
  • 62
  • 85
-2
find /home/attachments/ -name "*.*" -exec scp {} /home/attachments_all/ \;
shantanuo
  • 3,579
  • 8
  • 49
  • 66