2007. 11. 3. 20:59 Unix

확장자 바꾸기

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP
 
                       Unix Tip 2334 - May 23, 2006
 
                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
확장자 바꾸기
 
여러 파일들의 확장자를 변경하고자 할때 다음의 명령어로는 수행할 수 없다.
 
       % mv *.abc *.def
 
하지만 다음 쉘 스크립트를 이용하여 원하는 작업을 하는데 사용할 수 있다.
 
***
 
다음 쉘 스크립트를 이용하면 확장자가 .abc인 파일(*.abc)을 모두
확장자가 .def인 파일(*.def)변경할 수 있다.
 
#!/bin/sh
for f in *.abc; do
    mv $f `basename $f .abc`.def
done
 
스크립트가 어떻게 작동하는지 살펴보자.
 
for f in *.abc; do
 
.abc로 끝나는 파일을 찾아 순서대로 파일명을 $F에 대입한다.
 
 mv $f `basename $f.abc`.def
 
`basename $f .abc`는 $f의 파일명을 받아 따라오는 .abc를 떼어내고,
.def를 앞의 결과에 덧붙이면 결과적으로 명령은 다음과 같이 된다.
 
"mv file.abc file.def"
 
done
 
위의 "for" 루프를 종료한다.
 
"csh" 또는 "tcsh"에서 위의 작업을 하려면 다음과 같이 할 수 있다.
 
foreach f in ( *.abc )
   mv $f `basename $f .abc`.def
end
 
----------------------------------------------------------
 
CHANGE THE SUFFIX
 
If you want to change the suffix of multiple files, you can't do:
 
       % mv *.abc *.def
 
However the following shell script can be used to do the required
opperation:
 
***
 
Change all *.abc file to *.def the following shell script would work:
 
#!/bin/sh
for f in *.abc; do
 mv $f `basename $f .abc`.def
done
 
How it works:
 
 for f in *.abc; do
 
Set up a look for all files ending in .abc, and each time around setup
$f as the filename
 
 mv $f `basename $f.abc`.def
 
`basename $f .abc` takes the filename in $f and removes any trailing
occurences of .abc, we then append .def to the result and the resulting
command becomes
"mv file.abc file.def"
 
  done
 
Ends the "for" loop above.
 
Under "csh" or "tcsh" a similar thing could be done with:
 
 foreach f in ( *.abc )
   mv $f `basename $f .abc`.def
 end
 
This tip generously supported by: pwain@liberate.com
반응형
Posted by She쥐포s
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP
 
                       Unix Tip 2332 - May 21, 2006
 
                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

데이터 영역 크기 제한하기
 
ulimit와 limit를 이용하여 "데이터 영역"의 크기를 제한할 수 있다.
 
ksh에서는:

$ ulimit -d KB단위크기
 
현재의 모든 리소스 제한을 보고 싶다면

$ ulimit -a
 
csh 또는 tcsh에서는:
$ limit datasize KB단위크기
 
현재의 모든 리소스 제한을 보고 싶다면
 
$ limit

예를 들자면:

$ ulimit -d 141073
$ ulimit -a

-----------------------------------------------------------
LIMIT THE SIZE OF DATA AREA
 
You can limit the size of "data area"
using ulimit and limit.

Under sh or ksh:
$ ulimit -d SIZE_IN_KB
 
Displays all current resource limits
$ ulimit -a

under csh or tcsh:
$ limit datasize SIZE_IN_KB
 
Displays all current resource limits
$ limit

For example:
$ ulimit -d 141073
$ ulimit -a
반응형
Posted by She쥐포s

2007. 11. 3. 20:47 Unix

여러파일 조작하기

여러 파일 조작하기
 
동시에 여러 파일에 대해 조작을 할 필요성을 느낀적이 있는가???
 
여기 그에 대한 해답(솔루션)이 있다.
 
예를 들어, 하나의 파일에 대해서 뿐만 아니라 일련의 파일에 대해서도
(grep을 이용하여) 문자를 찾고, awk 또는 펄스크립트등을 실행하는 등의
여러가지 작업을 수행할 필요가 있다면 unix 프롬프트상에서 다음의
명령어를 사용하라.
 
 $<: foreach i (<file_list>)
 ? echo $i
 ? grep <search_pattern> $i > tmp
 ? awk -f awk_script tmp >> report
 ? ....
 ? ....
 ? end
$<:
 
꺽쇄괄호안의 파일리스트는 다음의 두 종류가 올 수 있다.
 
* 특정한 이름을 지정
 
* 파일 이름의 목록을 포함하는 유닉스 변수. 예를 들면 "p"라는 변수는
다음에 보는 것처럼 "data"라는 문자로 시작하는 모든 파일을 지정할 수
있다.
 
   set p = (data*)
 
다른 예제를 들자면
 
   set g = `grep -l "Startpoint" * `
 
또는
 
   set all = *
(위의 내용은 현재 디렉토리의 모든 파일명을 "all"이라는 변수에 할당한다.
 
그리고 변수명을 "foreach"라는 명령어와 함께 사용한다면 다음과 같이
될 것이다.
 
$<:  foreach i ($all)
  .....
  .....
end
 
-----------------<원문>-------------------
OPERATING ON MULTIPLE FILES
 
Have you ever felt the need to perform a
set of operations on multiple files
simultaneously???
 
Here is a solution for that.
 
For instance, if it is required to perform
multiple operations like searching a string
(using grep), and executing an awk or perl
script etc, etc. on not just one file but a
set of files, use the following commands at
the unix prompt:
 
 $<: foreach i (<file_list>)
 ? echo $i
 ? grep <search_pattern> $i > tmp
 ? awk -f awk_script tmp >> report
 ? ....
 ? ....
 ? end
$<:
 
The files list in the brackets can be either
 
* Specifically mentioned
 
* A unix variable which contains a list of
file names.  For instance, the variable
"p" can be assigned all the files starting
with string "data" as follows:
   set p = (data*)
Other examples are:
   set g = `grep -l "Startpoint" * `
or
   set all = *
(This assigns all file names in the current
directory to the variable "all" )
 
And its usage with the "foreach" command will
be as follows:
 
$<:  foreach i ($all)
  .....
  .....
end
반응형
Posted by She쥐포s

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2744 - July  8, 2007

                   
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

출력결과 읽기

vi에서 다음을 입력하라:

:r !my_command

위 명령은 편집하고 있는 다음 라인에 입력한 명령의 출력결과가 입력될 것이다.

@@@@@@@@@@@@@@@[원문]@@@@@@@@@@@@@@@@

READ IN THE OUTPUT

While in VI, if you enter:

:r !my_command

Then you will insert the output of
the command you've entered on the
next line of the file that you're editing.

반응형
Posted by She쥐포s

아래글을 보고 Shell에 적용을 해 봤습니다.

DATE=`expr \`date +%d\` + 1 - 1`
echo $DATE

아니면 바로
expr `date +%d` + 1 - 1

흐흐흐

--------------<아래는 퍼온글입니다>------------------
우연히 발견했습니다.

echo date("m");

하시면 결과가 09 이렇게 나오죠(지금이 9월이니까)
그런데 여기서 앞의 0을 제거하는 방법중 가장 쉬운건....

echo date("m")+1-1;

하니까 0이 제거되는군요. 하하핫.

http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=3999

반응형
Posted by She쥐포s

ittoolbox 메일리스트의 unixadmin-l 메일리스트를 보다보니 다음과 같은 내용이 있어
가져왔습니다.

Command Line의 인수로 패스워드로 받는 경우 Shell에서는 패스워드를 숨길 수가
없어 다음과 같은 방식으로 처리합니다.

--------------------<원본>-------------------------
#!/usr/bin/sh
# 일반 유닉스에서 변수를 초기화(?)하는 듯
TEST1=

# 문자열을 입력받기 위한 프롬프트 출력
echo "Enter TEST1:"

# 화면 출력 off
stty -echo

# TEST1에 해당하는 값을 읽음
read TEST1

# 화면 출력 on
stty echo

# 화면에 인수 출력
echo "TEST1=${TEST1}"

# 끝!
exit
--------------------<원본끝>-----------------------

위의 내용을 Linux에서 사용하도록 변형

#!/bin/sh
TEST1=
# -n 옵션으로 한 줄에 표시

echo -n "Enter TEST1:"
stty -echo
read TEST1
echo ""
stty echo
echo "TEST1=${TEST1}"
exit

다음은 실행시의 화면(※ Enter TEST1: 이후에는 표시되지 않음)

사용자 삽입 이미지

반응형
Posted by She쥐포s
이전버튼 1 2 3 4 이전버튼

블로그 이미지
She쥐포s
Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함