디렉토리에 많은 파일이 있고, 다음과 같은 명령을 실행할 때

$ grep "ABC" *

"0403-027 The parameter list is too long"

메세지를 낸다면


$ ls | xargs grep "ABC"

명령을 이용하여 에러 메세지를 피할 수 있다.

반응형
Posted by She쥐포s
* 리스트 확인

bash-2.03# unzip -l 142397-01.zip

Archive:  142397-01.zip
 Length    Date    Time    Name
 ------    ----    ----    ----
      0  10-23-09  00:09   142397-01/
     76  07-21-09  07:13   142397-01/.diPatch
    214  07-21-09  07:13   142397-01/patchinfo
   2664  10-23-09  00:09   142397-01/README.142397-01
      0  07-21-09  07:57   142397-01/SUNWlibsasl/
      0  07-21-09  07:57   142397-01/SUNWlibsasl/reloc/
      0  07-21-09  07:57   142397-01/SUNWlibsasl/reloc/usr/
      0  07-21-09  07:57   142397-01/SUNWlibsasl/reloc/usr/lib/
      0  07-21-09  07:57   142397-01/SUNWlibsasl/reloc/usr/lib/sparcv9/
 129680  07-21-09  07:41   142397-01/SUNWlibsasl/reloc/usr/lib/sparcv9/libsasl.so.1
 113152  07-21-09  07:41   142397-01/SUNWlibsasl/reloc/usr/lib/libsasl.so.1
    560  07-21-09  07:57   142397-01/SUNWlibsasl/pkginfo
    627  07-21-09  07:57   142397-01/SUNWlibsasl/pkgmap
      0  07-21-09  07:57   142397-01/SUNWlibsasl/install/
    565  07-21-09  07:13   142397-01/SUNWlibsasl/install/patch_preinstall
  12100  07-21-09  07:13   142397-01/SUNWlibsasl/install/postinstall
   4300  07-21-09  07:13   142397-01/SUNWlibsasl/install/patch_postinstall
   8023  07-21-09  07:13   142397-01/SUNWlibsasl/install/preinstall
   2044  07-21-09  07:13   142397-01/SUNWlibsasl/install/patch_checkinstall
   4104  07-21-09  07:13   142397-01/SUNWlibsasl/install/u.none
   7102  07-21-09  07:13   142397-01/SUNWlibsasl/install/i.none
   3426  07-21-09  07:13   142397-01/SUNWlibsasl/install/copyright
   6488  07-21-09  07:13   142397-01/SUNWlibsasl/install/checkinstall
  18488  06-03-09  04:12   142397-01/LEGAL_LICENSE.TXT
 ------                    -------
 313613                    24 files

* 파일 추출
bash-2.03# unzip 142397-01.zip 142397-01/README.142397-01

Archive:  142397-01.zip
  inflating: 142397-01/README.142397-01
bash-2.03#
반응형
Posted by She쥐포s

2008. 9. 21. 17:47 Unix/Shell

null copy

○ null copy
        File의 Size를 0으로 만드는 작업으로 일반적으로 로그파일이 커졌을 때 해당 파일의 사이즈를 초기화하는 목적
        등으로 사용됨.

○ 방법
        1. cat /dev/null > FILENAME
                 /dev/null 파일을 직접 파일에 Redirection한다.
                일반적인 경우 사용됨.
                 예)
                    # cat /dev/null > /var/log/messages

        2. > FILENAME
                직접 Redirection해서 파일에 쓴다.
                Bourne Shell, Korn Shell에서 사용됨
                예)

                    # > /var/log/messages


참고 원문
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 3151 - September 21, 2008

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

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

NULL IT FAST

Here is the fastest way to truncate a file to zero
bytes in a bourne or korn shell.

$ > /var/log/messages

This is a good method, if the file has to be truncated,
but is opened by another process. For example, if you
want to truncate /var/log/messages, which is held
open by syslogd...

반응형
Posted by She쥐포s
o 쉘도라도 닷 컴
    - 좋은 코딩의 예
    - 스크립트 예제
    - 쉘관련 링크
    - Tip과 Trick 등 여러가지 읽을거리가 많이 있다.

http://www.shelldorado.com
반응형
Posted by She쥐포s

쉘 스크립트에서 sqlplus 스크립트를 이용하기

쉘 스크립트안에서 sqlplus 스크립트를 실행하는 방법에 대한 팁이다.
이 팁은 데이터베이스 값을 쉘 변수로 전달하는 방법과 쉘 스크립트를
좀더 다이나믹하게 만들어주는 예이다. 어떤 사람들에게는 기초적인
것일수 있으나 다른 사람들에게 도움이 되기 바란다. 문법은 다음과 같다:

#!/bin/sh
dummyvar=`sqlplus -s username/password  <<end
set pagesize 0 feedback off ver off heading off echo off
select  sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script

이 예제는 오라클에서 시스템의 날짜를 받아오는 것이지만 여러분들이
데이터베이스에서 원하는 정보를 가져와 쉘 변수에 넣도록 select
스크립트를 확장하는 방법에 대한 아이디어를 얻을 수 있다.

@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2578 - January 23, 2007

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

SHELL SCRIPTING A SQLPLUS SCRIPT

Here is a tip on how to run sqlplus scripts within a shell script.
It is an example of how to pass database values into shell variables
and to make shell scripts more dynamic. This maybe elementary to some
folks but hope it helps others.....Here is the syntax:

#!/bin/sh
dummyvar=`sqlplus -s username/password  <<end
set pagesize 0 feedback off ver off heading off echo off
select  sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script

This will retrieve the system date from Oracle but you get the idea
that you can expand the select script to get whatever you want from
the database and place it in a shell variable where you can make
decisions on it.

반응형
Posted by She쥐포s

---------------- Start of Script ----------------
#!/bin/sh

CUR_DATE=`date +%Y%m%d`

mkdir "$CUR_DATE"
---------------- End of Script ----------------
1. date 명령의 옵션을 이용해 현재의 날짜를 구하여
2. CUR_DATE라는 변수에 저장
3. CUR_DATE라는 이름으로 디렉토리 생성

※ 위의 내용을 응용하여 독립적인 스크립트로서가 아니고 다른 스크립트와
    함께 사용하면 더욱 유용할 수 있다.(예 : 백업을 날짜별로 받을 경우.. 등)

반응형
Posted by She쥐포s
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2390 - July 18, 2006

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
대문자 파일명을 소문자로
 
스크립트는 현재 디렉토리에 있는 모든 파일명을 대문자에서 소문자로 변경하는데
사용할 수 있다.
 
나는 이 스크립트를 윈도우 시스템에서 유닉스 기반의 웹서버에 업로드하려고 할 때
파일 이름이 원하지 않게 대문자로 변경되었을 경우 사용한다.

###########################

for uppercase in `ls`
do
 for lowercase in `ls $uppercase|tr [A-Z] [a-z]`
 do
    mv $uppercase $lowercase 2>/dev/null
 done
done

############################
譯者 註)
1번줄 : ls의 결과를 "uppercase"라는 변수로 받아 for문
2번줄 : 主반복문 실행
3번줄 : "uppercase" 변수를 tr을 통해 대문자를 소문자로 변환후
        "lowercase" 변수에 저장
4번줄 : 하위반복문 실행
5번줄 : "uppercase" 변수 내용을 "lowercase" 변수 내용으로 변환
        원문의 스크립트가 잘못되어있다. 주의요망
6번줄 : 하위반복문 종료
7번줄 : 主반복문 종료
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
FILNAMES UPPER TO LOWER

This script can be used to
renames all the file in
current directory with
UPPERCASE letters to lowercase.

I uses it because some time when
I try to upload some files from
a Windows system to a unix based
web server, the files somehow gets
converted to UPPERCASES, which is
undesirable.

###########################

for uppercase in `ls`
do
 for lowercase in `ls $uppercase|tr [A-Z] [a-z]`
 do
    mv $lowercase $uppercase 2>/dev/null
 done
done

############################
반응형
Posted by She쥐포s

2007. 11. 3. 21:20 Unix/Shell

마지막 변수의 값

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

                       Unix Tip 2358 - June 16, 2006

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

마지막 변수의 값

korn 쉘 스크립트에서 이전의 마지막 변수의 값을 얻는 방법이다.

eval last=\${$#}

그러면 $last 이전에 사용된 마지만 변수가 된다.
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

VALUE OF LAST PARAMETER

Get the value of the last parameter
passed into a korn shell script.

eval last=\${$#}

Now $last is the last parameter passed in.
반응형
Posted by She쥐포s
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2346 - June  4, 2006

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

비효율 코드와 개선 코드

나는 사람들의 코드가 비효율적인 것을 볼때마다 진절머리가 난다.(※ 원작자의 생각임) 
여기에 가장 흔한 실수 3가지와 같은 작업을 하기 위한 좀 더 나은 방법을 적어본다.
 
비효율 코드: cat somefile | grep something
개선    코드: grep something somefile
이         유 : 두개의 프로그램(catgrep) 대신 하나의 프로그램(grep) 실행

비효율 코드: ps -ef | grep something | grep -v grep
개선    코드: ps -ef | grep [s]omething
이         유 : 세개의 명령(ps와 두개의 grep) 대신에 두개의 명령(psgrep)을 실행 
 
---------------------------------------------------------------------
(역자 註: grep에서 정규표현식을 지원하는데 []를 쓸 경우 grep -v grep
              효과를 내는 듯함.
 
다음은 GNU grep 2.5.1a 버전 이후부터 추가된 기능임. 상세사항은 manpage참조
        추가기능1 : -o 또는 --only-matching (only match)
        추가기능2 : --colo(u)r[=WHEN], WHEN=never, always, auto
                         이 옵션은 GREP_COLOR에 지정될 수 있음
        추가기능3 : -P(Perl 정규표현식 사용). 이 기능은 소스를 재컴파일해야함)
---------------------------------------------------------------------

비효율 코드: cat /dev/null > somefile
개선    코드: > somefile
이         유 : 한개의 명령(cat)과 입출력 redirection대신에 redirection만 실행

비록 비효율적인 방법이 같은 결과를 낼 지라도 개선된 방법이 훨씬 더 빠르다.
이 방법이 하찮게 보일지 모르지만 큰 파일이나 루프를 다룰 때 그  이득을 볼
수 있을 것이다.
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
THE BAD AND THE GOOD

I cringe anytime I see someone code inefficiently.  Here are
three of the most common mistakes, followed by a better way to
do the same thing.

Bad:    cat somefile | grep something
Better: grep something somefile
Why:    You're running one program (grep) instead of two (cat
and grep).

Bad:    ps -ef | grep something | grep -v grep
Better: ps -ef | grep [s]omething
Why:    You’re running two commands (grep) instead of three (ps
and two greps).

Bad:    cat /dev/null > somefile
Better: > somefile
Why:    You're running a command (cat) with I/O redirection,
instead of just redirection.

Although the bad way will have the same result, the good way is
far faster.  This may seem trivial, but the benefits will really
show when dealing with large files or loops.
반응형
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
이전버튼 1 2 이전버튼

블로그 이미지
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

최근에 올라온 글

최근에 달린 댓글

글 보관함