• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Linux] find 명령어를 이용해서 5개가 넘는 디렉토리 중 1개만 지우기

17 May 2021

Reading time ~1 minute

Linux] find 명령어를 이용해서 오래된 디렉토리 중 1개만 지우기

오래된 디렉토리을 5개만 남겨놓고 지우고 싶을때 사용합니다.

if [[ $(find /build/${PRJ_NAME}_* -type d | wc -l) -gt 5 ]]
then
  find /build/${PRJ_NAME}_* -type d | head -n 1 | xargs rm -rf
fi

command로 넣어도 되고, shell script로 사용해도 됩니다. :)



findlinuxcommand Share Tweet +1