unix - Find and tar files on Solaris -
unix - Find and tar files on Solaris -
i've got little problem bash script. i'm newbie in unix world, find hard deal exercise. have find files on solaris server specific name, modified in specific time , archive them in 1 .tar file. first 2 points easy, i'm having nightmare trying archive it. thing is, archive whole tree of file (with file @ end) .tar file, need file. code looks this:
find ~ -name "$maska" -mtime -$dni | xargs -t -l 1 tar -cvf $3 -c
where $maska name of file, $dni refers modification time , $3 archive name. found out -c switch, let's me jump folder desired file is, when utilize xargs, seems jump there , nil else.
so question is:
1) there possibility of achieving goal way?
please remember, don't work on gnu tar. , have utilize commands: tar, find.
edit: i'd specify more problem. when utilize script for, example, file a, should since point shown in script (it's ~ ) , find should in 1 tar file.
what got right (i'm in /home/me/scripts):
-bash-3.2$ ./script.sh 1000 backup /home/me/program/test/a/ 0k /home/me/program/test/a/a.c 1k /home/me/program/test/a/a.out 8k
so script has done packing. next want see packed file, so:
-bash-3.2$ tar -tf backup /home/me/program/test/a/ /home/me/program/test/a/a.c /home/me/program/test/a/a.out
and that's problem. tar file have paths in it, if untar it, instead of getting file wanted archive, replace them in old places. visualisation:
-bash-3.2$ ls script.sh* script.sh~* backup -bash-3.2$ tar -xvf backup x /home/me/program/test/a, 0 bytes, 0 tape blocks x /home/me/program/test/a/a.c, 39 bytes, 1 tape blocks x /home/me/program/test/a/a.out, 7928 bytes, 16 tape blocks -bash-3.2$ ls script.sh* script.sh~* backup
that's problem.
so want pack desired file (a in illustration above) in 1 tar file without paths, untar in directory run script.sh.
maybe can this:
#!/bin/bash find ~ -name "$maska" -mtime -$dni -print0 | while read -d $'\0' file; d=$(dirname "$file") f=$(basename "$file") echo $d: $f # show directory , file debug purposes tar -rvf tarball.tar -c"$d" "$f" done
i don't have solaris box @ hand testing :-)
unix find solaris tar
Comments
Post a Comment