I want to tar some Python files and send it across a server. I do:

find /some/path -iname "*.py"  -exec tar czfv python_files.tar {} +

Followed by:

pv python_files.tar| ssh some_user@some_server 'cat | tar xz -C /some/path/on/server'

Unfortunately when I SSH on the server I see the full directory structure has been sent across the server and I find my python files like that:


What I want is my files to be at the root:


What is the missing piece?

  • 3
    What do you want to do when you have files with the same name in different subfolders? Commented Mar 20, 2019 at 11:02

2 Answers 2


as per man tar (a long reading)

--transform=EXPRESSION, --xform=EXPRESSION
Use sed replace EXPRESSION to transform file names.

I used

find . -name \*.py -print | xargs tar cf tmp7/test-py.tar --transform=s:./.*/:: -

all files were on same level.

sed expression

  • s:./.*/:: : (greedy) replace ./.*/ by nothing.


find . -name \*.py -print | sed -e s:./.*/:: | awk 'a[$1]++ { print ; }'

will print dupplicate filename.


Like the solution from user Archemar, only applied when extracting the tar. Substituting .*/ with the empty string.

pv python_files.tar| ssh some_user@some_server 'cat | tar xz --transform=s,.*/,, -C /some/path/on/server'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .