find and zip multiple file extensions while keeping the folder structure
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Ubuntu 16.04
I would like to backup all .txt, .cfg, and .ini files, while keeping their folder structure to a zip file in the backups folder.
I know there is an easier way to do this entire operation but this is what I have.
#!/bin/bash
wdir="/home/files"
backup_dir="/home/files/backup"
allcfg=$(find suan -name '*.cfg')
alltxt=$(find suan -name '*.txt')
allini=$(find suan -name '*.ini')
timeStamp="$(date +%Y--%b-%d--%k:%M--%P)"
backupfilename="$backup_dir/Backup-$timeStamp.zip"
#-- set some arrays ...
backupfiles=( "$allcfg" "$alltxt" "$allini" )
cd "$wdir"
zip -r "$backupfilename" "$backupfiles"
So I can see a nice output of the files it files but when it gets to the zipping part it errors out.
zip error: Nothing to do! (try: zip -r /home/files/backup/Backup-2018--Jul-04--21:37--pm.zip . -i suan/cfg/360controller.cfg
But that doesn't work either.
bash find zip
add a comment |Â
up vote
1
down vote
favorite
Ubuntu 16.04
I would like to backup all .txt, .cfg, and .ini files, while keeping their folder structure to a zip file in the backups folder.
I know there is an easier way to do this entire operation but this is what I have.
#!/bin/bash
wdir="/home/files"
backup_dir="/home/files/backup"
allcfg=$(find suan -name '*.cfg')
alltxt=$(find suan -name '*.txt')
allini=$(find suan -name '*.ini')
timeStamp="$(date +%Y--%b-%d--%k:%M--%P)"
backupfilename="$backup_dir/Backup-$timeStamp.zip"
#-- set some arrays ...
backupfiles=( "$allcfg" "$alltxt" "$allini" )
cd "$wdir"
zip -r "$backupfilename" "$backupfiles"
So I can see a nice output of the files it files but when it gets to the zipping part it errors out.
zip error: Nothing to do! (try: zip -r /home/files/backup/Backup-2018--Jul-04--21:37--pm.zip . -i suan/cfg/360controller.cfg
But that doesn't work either.
bash find zip
2
When you quoted the variables, the filenames individuality is lost. Try the array option or do everything withinfind
â Rakesh Sharma
Jul 5 at 2:05
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Ubuntu 16.04
I would like to backup all .txt, .cfg, and .ini files, while keeping their folder structure to a zip file in the backups folder.
I know there is an easier way to do this entire operation but this is what I have.
#!/bin/bash
wdir="/home/files"
backup_dir="/home/files/backup"
allcfg=$(find suan -name '*.cfg')
alltxt=$(find suan -name '*.txt')
allini=$(find suan -name '*.ini')
timeStamp="$(date +%Y--%b-%d--%k:%M--%P)"
backupfilename="$backup_dir/Backup-$timeStamp.zip"
#-- set some arrays ...
backupfiles=( "$allcfg" "$alltxt" "$allini" )
cd "$wdir"
zip -r "$backupfilename" "$backupfiles"
So I can see a nice output of the files it files but when it gets to the zipping part it errors out.
zip error: Nothing to do! (try: zip -r /home/files/backup/Backup-2018--Jul-04--21:37--pm.zip . -i suan/cfg/360controller.cfg
But that doesn't work either.
bash find zip
Ubuntu 16.04
I would like to backup all .txt, .cfg, and .ini files, while keeping their folder structure to a zip file in the backups folder.
I know there is an easier way to do this entire operation but this is what I have.
#!/bin/bash
wdir="/home/files"
backup_dir="/home/files/backup"
allcfg=$(find suan -name '*.cfg')
alltxt=$(find suan -name '*.txt')
allini=$(find suan -name '*.ini')
timeStamp="$(date +%Y--%b-%d--%k:%M--%P)"
backupfilename="$backup_dir/Backup-$timeStamp.zip"
#-- set some arrays ...
backupfiles=( "$allcfg" "$alltxt" "$allini" )
cd "$wdir"
zip -r "$backupfilename" "$backupfiles"
So I can see a nice output of the files it files but when it gets to the zipping part it errors out.
zip error: Nothing to do! (try: zip -r /home/files/backup/Backup-2018--Jul-04--21:37--pm.zip . -i suan/cfg/360controller.cfg
But that doesn't work either.
bash find zip
asked Jul 5 at 1:45
needtoknow
1286
1286
2
When you quoted the variables, the filenames individuality is lost. Try the array option or do everything withinfind
â Rakesh Sharma
Jul 5 at 2:05
add a comment |Â
2
When you quoted the variables, the filenames individuality is lost. Try the array option or do everything withinfind
â Rakesh Sharma
Jul 5 at 2:05
2
2
When you quoted the variables, the filenames individuality is lost. Try the array option or do everything within
find
â Rakesh Sharma
Jul 5 at 2:05
When you quoted the variables, the filenames individuality is lost. Try the array option or do everything within
find
â Rakesh Sharma
Jul 5 at 2:05
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
This is how the -r
recursive option on 7z
works, it's a recursive pattern search.
7z a -r "$backupfilename" *.ini *.cfg *.txt
7z
creates zip files just fine.
You could also do the multi-arg option on find
if you somehow don't have 7zip,
find suan ( -name *.cfg -o -name *.txt -o -name *.ini )
-exec zip -r "$backupfilename" +
@thill Excellent!
â needtoknow
Jul 6 at 3:40
add a comment |Â
up vote
0
down vote
Using find
and zip
:
find "$wdir" -type f '(' -name '*.cfg' -o -name '*.txt' -o -name '*.ini' ')'
-exec zip -r "$backupfilename" +
You may alternatively want to let your script cd
into "$wdir"
first and then use .
in the find
command, depending on what path you'd like to have saved in the archive.
This would find all relevant files and archive them in your backup file.
Alternatively with bash
, if there's not thousands of files:
set -s globstar nullglob dotglob
cd "$wdir" && zip -r "$backupfilename" **/*.ini **/*.cfg **/*.txt
The shell options that are set here enables the **
glob (which globs pathnames), makes unexpanded globs expand to the empty string and makes globs match hidden files.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
This is how the -r
recursive option on 7z
works, it's a recursive pattern search.
7z a -r "$backupfilename" *.ini *.cfg *.txt
7z
creates zip files just fine.
You could also do the multi-arg option on find
if you somehow don't have 7zip,
find suan ( -name *.cfg -o -name *.txt -o -name *.ini )
-exec zip -r "$backupfilename" +
@thill Excellent!
â needtoknow
Jul 6 at 3:40
add a comment |Â
up vote
2
down vote
accepted
This is how the -r
recursive option on 7z
works, it's a recursive pattern search.
7z a -r "$backupfilename" *.ini *.cfg *.txt
7z
creates zip files just fine.
You could also do the multi-arg option on find
if you somehow don't have 7zip,
find suan ( -name *.cfg -o -name *.txt -o -name *.ini )
-exec zip -r "$backupfilename" +
@thill Excellent!
â needtoknow
Jul 6 at 3:40
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
This is how the -r
recursive option on 7z
works, it's a recursive pattern search.
7z a -r "$backupfilename" *.ini *.cfg *.txt
7z
creates zip files just fine.
You could also do the multi-arg option on find
if you somehow don't have 7zip,
find suan ( -name *.cfg -o -name *.txt -o -name *.ini )
-exec zip -r "$backupfilename" +
This is how the -r
recursive option on 7z
works, it's a recursive pattern search.
7z a -r "$backupfilename" *.ini *.cfg *.txt
7z
creates zip files just fine.
You could also do the multi-arg option on find
if you somehow don't have 7zip,
find suan ( -name *.cfg -o -name *.txt -o -name *.ini )
-exec zip -r "$backupfilename" +
answered Jul 5 at 2:56
jthill
2,283715
2,283715
@thill Excellent!
â needtoknow
Jul 6 at 3:40
add a comment |Â
@thill Excellent!
â needtoknow
Jul 6 at 3:40
@thill Excellent!
â needtoknow
Jul 6 at 3:40
@thill Excellent!
â needtoknow
Jul 6 at 3:40
add a comment |Â
up vote
0
down vote
Using find
and zip
:
find "$wdir" -type f '(' -name '*.cfg' -o -name '*.txt' -o -name '*.ini' ')'
-exec zip -r "$backupfilename" +
You may alternatively want to let your script cd
into "$wdir"
first and then use .
in the find
command, depending on what path you'd like to have saved in the archive.
This would find all relevant files and archive them in your backup file.
Alternatively with bash
, if there's not thousands of files:
set -s globstar nullglob dotglob
cd "$wdir" && zip -r "$backupfilename" **/*.ini **/*.cfg **/*.txt
The shell options that are set here enables the **
glob (which globs pathnames), makes unexpanded globs expand to the empty string and makes globs match hidden files.
add a comment |Â
up vote
0
down vote
Using find
and zip
:
find "$wdir" -type f '(' -name '*.cfg' -o -name '*.txt' -o -name '*.ini' ')'
-exec zip -r "$backupfilename" +
You may alternatively want to let your script cd
into "$wdir"
first and then use .
in the find
command, depending on what path you'd like to have saved in the archive.
This would find all relevant files and archive them in your backup file.
Alternatively with bash
, if there's not thousands of files:
set -s globstar nullglob dotglob
cd "$wdir" && zip -r "$backupfilename" **/*.ini **/*.cfg **/*.txt
The shell options that are set here enables the **
glob (which globs pathnames), makes unexpanded globs expand to the empty string and makes globs match hidden files.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using find
and zip
:
find "$wdir" -type f '(' -name '*.cfg' -o -name '*.txt' -o -name '*.ini' ')'
-exec zip -r "$backupfilename" +
You may alternatively want to let your script cd
into "$wdir"
first and then use .
in the find
command, depending on what path you'd like to have saved in the archive.
This would find all relevant files and archive them in your backup file.
Alternatively with bash
, if there's not thousands of files:
set -s globstar nullglob dotglob
cd "$wdir" && zip -r "$backupfilename" **/*.ini **/*.cfg **/*.txt
The shell options that are set here enables the **
glob (which globs pathnames), makes unexpanded globs expand to the empty string and makes globs match hidden files.
Using find
and zip
:
find "$wdir" -type f '(' -name '*.cfg' -o -name '*.txt' -o -name '*.ini' ')'
-exec zip -r "$backupfilename" +
You may alternatively want to let your script cd
into "$wdir"
first and then use .
in the find
command, depending on what path you'd like to have saved in the archive.
This would find all relevant files and archive them in your backup file.
Alternatively with bash
, if there's not thousands of files:
set -s globstar nullglob dotglob
cd "$wdir" && zip -r "$backupfilename" **/*.ini **/*.cfg **/*.txt
The shell options that are set here enables the **
glob (which globs pathnames), makes unexpanded globs expand to the empty string and makes globs match hidden files.
edited Jul 13 at 9:53
answered Jul 13 at 9:47
Kusalananda
101k13199312
101k13199312
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453511%2ffind-and-zip-multiple-file-extensions-while-keeping-the-folder-structure%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
When you quoted the variables, the filenames individuality is lost. Try the array option or do everything within
find
â Rakesh Sharma
Jul 5 at 2:05