Bash CleanMyMac ๋Œ€์•ˆ ๐Ÿงผ

2655 ๋‹จ์–ด bashhacktoberfest
์ง€๊ธˆ์ฏค์ด๋ฉด ์•„์‹œ๊ฒ ์ง€๋งŒ ์ €๋Š” Bash๋ฅผ ์ •๋ง ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค!

์ง€๊ธˆ๊นŒ์ง€ hacking our morning routine ๋ฐ after work git check ๋งŒ๋“ค๊ธฐ์™€ ๊ฐ™์€ Bash๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ช‡ ๊ฐ€์ง€ ์žฌ๋ฏธ์žˆ๋Š” ๊ฒƒ์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

๋งŽ์€ ๊ธฐ์‚ฌ์—์„œ Carbon์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋Ÿฌํ•œ ๋ฉ‹์ง„ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
์•„์ฃผ ๋ฉ‹์ง„ ์•ฑ์ด์ง€๋งŒ ๋‚ด ๋‹ค์šด๋กœ๋“œ ํด๋”๋Š” ์ด๋Ÿฌํ•œ ๊ฒƒ๋“ค๋กœ ๊ฐ€๋“ ์ฐจ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด Bash๊ฐ€ CleanOurMacs๋ฅผ ์–ด๋–ป๊ฒŒ ๋„์šธ ์ˆ˜ ์žˆ์„๊นŒ์š”?


๋ฐฐ์‰ฌ ํด๋ฆฐ ํŒŒ์ผ



Note: This script can be very dangerous since it uses Bash to remove files. Please be cautious!


txt ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ œ๊ฑฐํ•˜๋ ค๋Š” ํŒŒ์ผ์„ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ ํŒŒ์ผ์€ ์™€์ผ๋“œ์นด๋“œ(*)๋ฅผ ํฌํ•จํ•˜๊ฑฐ๋‚˜ ํŠน์ • ๋ฌธ์ž์—ด๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋‹ค์Œ์œผ๋กœ ์‹œ์ž‘: carbon
  • ์™€์ผ๋“œ์นด๋“œ: carbon*.png

  • ๊ทธ๋Ÿฐ ๋‹ค์Œ ์Šคํฌ๋ฆฝํŠธ๋กœ ์ด๋™ํ•˜์‹ญ์‹œ์˜ค!

    while read line; do
        find . -name "$line" -exec rm -rf {} \;
    done < ~/www/cleanMyPc/files.txt
    echo 'All done';
    


    ์™€์šฐ, ๊ทธ๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค!

    ์šฐ๋ฆฌ๋Š” files.txt ์˜ ํ–‰์„ ๋ฐ˜๋ณตํ•˜๊ณ  ๊ฐ ํ–‰์— ๋Œ€ํ•ด find ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ํŠน์ • ์ด๋ฆ„์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  -exec rm -rf๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.
    rm๋Š” remove๋ฅผ ๋‚˜ํƒ€๋‚ด๊ณ  rf๋Š” recursive force๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

    ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰



    ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” ์ฒ˜์Œ์—๋Š” ๋ชจ๋“  ํŒŒ์ผ์„ ์Šค์บ”ํ•˜๋„๋ก ์ž‘๋™ํ–ˆ์ง€๋งŒ ๋ณด์•ˆ์ƒ์˜ ์ด์œ ๋กœ ํŠน์ • ํด๋”๋งŒ ์Šค์บ”ํ•˜๋„๋ก ์กฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ ํ„ฐ๋ฏธ๋„์„ ์—ฝ๋‹ˆ๋‹ค
  • ์›ํ•˜๋Š” ํด๋”๋กœ ์ด๋™: cd Downloads
  • ๋ช…๋ น ์‹คํ–‰~/path/to/script/bash.sh
  • ์งœ์ž”, ๋‹ค ๋๋‚ฌ์–ด

  • ๋งค์šฐ ๊ฐ„๋‹จํ•œ ์Šคํฌ๋ฆฝํŠธ์ด์ง€๋งŒ ์ปดํ“จํ„ฐ์—์„œ ํŠน์ • ํŒŒ์ผ์„ ์ฐพ๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•˜๋Š” ๋ฐ ์œ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    GitHub์—์„œ ์ด ํ”„๋กœ์ ํŠธ ์ฐพ๊ธฐ

    ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์—ฐ๊ฒฐํ•ฉ์‹œ๋‹ค!



    ์ œ ๋ธ”๋กœ๊ทธ๋ฅผ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋‚ด ์ด๋ฉ”์ผ ๋‰ด์Šค๋ ˆํ„ฐ๋ฅผ ๊ตฌ๋…ํ•˜๊ณ  Facebook์— ์—ฐ๊ฒฐํ•˜๊ฑฐ๋‚˜

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ