Zip files via SSH and copy it to another folder or server

If you files and directories in your server via SSH, just type the command below:
zip -r zipfilename.zip folder

Just replace the folder with the folder name you are targetting or use * if your currently in the folder.

If you want to quickly zip all files and folders individually in your server via SSH, just type the command below:
find . -type f -exec zip '{}.zip' '{}' \;

Replace the dot after “find” to zip the specific folder and all files and folders inside it.

If you want to Tar.gz instead of .ZIP, you can use the command below:
tar -cvzf filename.tar.gz /home/path

Now, to copy the zip file or files in a folder to another folder, use the command below:
cp /home/user1/public_html/yourzipfile.zip*.* /home/user2/public_html

Just replace the user1 and user2 respectively. Or just specify which folder you want to copy your zip file.

If you want to copy all the files inside a folder and the files and folders inside the folder of a folder (sub folder, sub-sub folder, sub-sub-sub folder, and so on), then use the command below:
cp -r /home/user1/public_html/*.* /home/user2/public_html/

If you want to copy the files or folder to another server, use the command below:
scp -r /home/user/public_html/*.* user@serverip:/home/user/public_html/

Just replace the server IP with your IP or domain. You will enter a password after typing the command

Do you love this article and you want to receive more interesting posts from Bryan Veloso? Why not subscribe to this blog via e-mail? It's easy! Just enter your e-mail address below and confirm your subscription by clicking the activation link that will be sent to your e-mail! Get your free subscription now!

Enter your email address:

This entry was posted in Geekery and tagged , , , . Bookmark the permalink.

One Response to Zip files via SSH and copy it to another folder or server

  1. Damsel in Distress says:

    Very useful. This saved me a lot of time.

Leave a Reply

Your email address will not be published. Required fields are marked *