Last active
September 28, 2015 17:28
-
-
Save fridim/1471937 to your computer and use it in GitHub Desktop.
a small script to create archive (no option, can pass a file, a folder, a link ..)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Most of the time, you just want a .tar.gz of a folder, regardless of | |
# where you are. This is a small script that does it and put the result | |
# in /tmp. If you have xsel installed, it copied to your clipboard the | |
# destination file. | |
set -e | |
file="$1" | |
if [ ! -e "$file" ]; then | |
echo "File does not exist." >&2 | |
exit -1 | |
fi | |
if [ -L "$file" ]; then | |
file=$(readlink -f "$file") | |
fi | |
orig_size=$(du -sh "$file"|cut -f 1) | |
if [ -d "$file" ]; then | |
cd "$(dirname "$1")" || exit 1 | |
filename="$(mktemp -d)/$(date +%Y%m%d)_$(basename "$file").tar.gz" | |
tar czf "$filename" "$(basename $file)" | |
else | |
filename="$(mktemp -d)/$(date +%Y%m%d)_$(basename "$file").gz" | |
gzip -c "$file" > "$filename" | |
fi | |
echo "$orig_size ---> $(du -sh "$filename"|cut -f 1)" | |
echo | |
echo "Your tarball : $filename" | |
if command -v xsel>/dev/null; then | |
echo -n "$filename"|xsel | |
fi | |
exit 0 |
flagos
commented
Dec 14, 2011
via email
ouai ok, c'est vrai que c'est juste un script pour le user, c'est pas
fait pour être appelés par d'autres scripts de maniere bourrine
c'est plus de la déformation professionnelle de me voir désesperer
devant des scripts qui bossent dans /tmp et qui s'étonnent de tomber
sur des fichiers déja existants :-)
Le 14 décembre 2011 10:34, Guillaume Coré
reply@reply.github.com
a écrit :
Yop,
Oui, je connaissais mktemp. Mais bon faut voir ca peut être moins pratique quand on parcourt l'arbo depuis son client mail pour trouver le .tar.gz.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1471937
##
Tapé depuis mon clavier
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment