First install the zip utility if it isn't already installed on your system. But before this, let's begin by updating the local package index by using the following command:
sudo apt update
Now run the following command to install the zip utility:
sudo apt install zip
Now to zip a directory at the same location you can simply use the following command:
zip -r myarchive.zip mydir
For example, if your current working directory is /var/www and you want to zip a folder named assets inside of it, you can simply use the following command:
zip -r assets.zip assets
Alternatively, you can provide the absolute path of the file/folder like this:
zip -r /var/www/assets.zip /var/www/assets
Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash / is an absolute path.
Moreover, to store zip file at other location, you can use the following syntax:
zip -r /path/to/destination_folder/myarchive.zip /path/to/mydir
For example, if your current working directory is /var/www and you want to zip a folder named assets and save it in the folder named backup at the same location, you can use:
zip -r backup/myarchive.zip mydir
Or, if you want to use absolute path you can run the following command.
zip -r /var/www/backup/myarchive.zip /var/www/mydir
Use the
zip
CommandFirst install the zip utility if it isn't already installed on your system. But before this, let's begin by updating the local package index by using the following command:
Now run the following command to install the zip utility:
Now to zip a directory at the same location you can simply use the following command:
For example, if your current working directory is
/var/www
and you want to zip a folder namedassets
inside of it, you can simply use the following command:Alternatively, you can provide the absolute path of the file/folder like this:
Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash
/
is an absolute path.Moreover, to store zip file at other location, you can use the following syntax:
For example, if your current working directory is
/var/www
and you want to zip a folder namedassets
and save it in the folder namedbackup
at the same location, you can use:Or, if you want to use absolute path you can run the following command.