xargs로 입력받은 argument들을 반복해서 처리해야 할때,

#!/bin/bash
for x in $@
  do
  tar -cvzf $x".tgz" $x"/"
done

위와 같은 shell script를 만들어둡니다. 위의 예제는 디렉토리 이름이 argument로 넘어올때, tar 압축을 해주게 합니다. 위의 shell script의 이름이 dmake_tar.sh 라고 하면, 다음 문장을 실행하면, 각 디렉토리 이름별로 압축이 됩니다.

find -maxdepth 1 -type d -regex "./.*" -printf "%f\\n" | xargs ./dmake_tar.sh
Friday, March 13th, 2009 at 16:31
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>