Wednesday, 15 January 2014

linux - Un-archiving single file hanging -



linux - Un-archiving single file hanging -

i trying unarchive big directory. here works untar entire thing:

$ sudo tar -xjf itunes20140618.tbz --verbose x itunes20140618/ x itunes20140618/genre_artist x itunes20140618/imix_type ...etc...

however, if seek , un-archive single file, correctly so, command hang indefinitely. in addition, doesn't print of output when using --verbose statement. here example:

$ sudo tar -xjf itunes20140618.tbz itunes20140618/imix --verbose [ nil prints...it hangs. un-tar single file ]

tar doesn't have central table of contents; each file concatenated, 1 after other, it's continuing scan file. take long extract 1 file whole archive. per mark plotnick's comment below, on gnu tar, can utilize --occurrence=1 have stop scanning after finds file.

for os x , other places have tar doesn't back upwards --occurrence=1 argument, solution monitoring process watches appearance of file, , 1 time remains same size couple of seconds, kills tar process. here's bash function provide that:

untaronefile () { options=$1 archivename=$2 filename=$3 if [[ -f "$archivename" ]]; rm -rf "$filename" 2> /dev/null tar "$options" "$archivename" "$filename" & pid=$! size=0 quitcount=0 oldsize=0 while true; [[ -f "$filename" ]] && size=$(ls -l "$filename" | cutting -c 27- | sed 's/^ *//' | cutting -f 1 -d ' ') if (( $oldsize > 0 )); if (( $oldsize == $size )); (( quitcount++ )) else quitcount=0 fi fi (( $quitcount == 4 )) && break oldsize=$size sleep 0.5 done kill $pid else echo "archive file not found." fi }

error checking not robust, if give legit info, works. usage is:

untaronefile -jxvf tararchivefile.tar.bz file/you/want/to/extract

linux unix tar

No comments:

Post a Comment