폴더 A안에 있는 모든 서브폴더와 파일의 속성 변경하는 스크립트 작성하기

dl3zp3의 이미지

윈도 파티션에 있던 폴더를 리눅스 파티션으로 가져오면 모든 것의 속성이 rwxrwxrwx로 되어있죠.

폴더 A의 하부에 있는 모든 파일의 속성을 rw-r--r--로 변경하고 모든 디렉토리의 속성을 rwxr-xr-x로 변경하는 스크립트를 각각 bash 스크립트, zsh 스크립트, Python 기타 등으로 작성하면 어떻게 나올까요?

스크립트를 서로 비교해봅시다.

위와 동일하게 하되 sh 확장자를 가진 파일은 rwxr--r--가 되도록 하는 스크립트는?

jsj3579의 이미지

아련한 과제의 향기

dl3zp3의 이미지

특별히 과제는 아닌데요.
각각 스크립트 언어에서 loop, 시스템함수접근, 조건문 등이 어떻게 표현되는지 한꺼번에 비교하기 위한 질문입니다. Python을 잘 아는 사람이 Python용 스크립트를 답변으로 올리고 zsh을 아는 사람은 zsh스크립트를 올리면서 서로 비교하면 bash에서 zsh로 옮겨가고 싶은 사람이나 Python을 스크립트용으로 써보면 어떨까 하는 사람들이 각각의 답글을 읽고 빠르게 익힐 수 있습니다 비교를 할 수 있으니까요. 스크립트 언어를 한 개 알고 있지만 다른 스크립트언어에는 익숙하지 않은 사람들 모두의 숙제를 한꺼번에 풀어주는 질문이라고 저는 봅니다. Stackoverflow.com의 Rosetta Stone과 비슷한 취지입니다.

vacancy의 이미지


find 명령 몇 번이면 될텐데요. ;;

blueiur의 이미지

1. find . -type f | xargs chmod 644; find . -type d | xargs chmod 755
2. find . -name *.txt -type f | xargs chmod 755

이걸 쉘스크립트로 작성할 이유가 없겠죠?

auditory의 이미지

chmod -R go-w *
chmod -R ugo-x+X *

라고하면 되겠네요.

ymir의 이미지

잠시 머리 식힐겸.. ;;

#!/bin/sh
 
usage()
{
	echo "Usage : $0 dir_name";
	exit $1;
}
 
change_perm()
{
	if [ -z "$1" ] ; then
		return;
	fi
 
	for file in $1/*
	do
		if [ -f $file ] ; then
			if [ "${file:(-3)}" = ".sh" ] ; then
				chmod 0744 $file
			else
				chmod 0644 $file
			fi
		elif [ -d $file ] ; then
			chmod 0755 $file
			change_perm $file
		else
			:
		fi
	done
}
 
if [ $# -ne 1 -o ! -d "$1" ] ; then
	usage 1;
fi
 
change_perm $1;
 
exit 0

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.