'유닉스'에 해당되는 글 5건

  1. 2010.05.07 vi 배경색 지정하기
  2. 2009.02.15 [UnixTip] 확장자(Suffix) 바꾸기..
  3. 2008.10.11 [UnixTip] awk에서의 정규표현식 match
  4. 2008.09.21 split 명령
  5. 2008.09.21 null copy
홈디렉토리의 .vimrc(unix기준)

또는

C:\Program Files\Vim\Vim7.2(버전)\vimrc_example.vim(윈도우 기본설치 기준)

파일에

let g:colors_name="torte"

추가한 후 저장.."torte"에 해당하는 내용은 개인 선택..
반응형
Posted by She쥐포s

유닉스엔 원칙적으로 확장자의 개념이 없다.
인간이 구분하기 위해 구분해 놓은 것에 불과하다.
편의상 구분해 놓은 구분자를 변경하는 방법에 관한 팁을 소개한다.

---------------------------------------------------------------------
확장자 바꾸기

여러 파일들의 확장자를 변경하고자 할 때 다음과 같은 방식을 이용할 수 없다.

    % mv *.abc *.def

대신 다음의 쉘 스크립트로 원하는 작업을 할 수 있다.

--------- 시작 ---------
#!/bin/sh
for f in *.abc; do
    mv $f `basename $f .abc`.def
done
--------- 끝 ---------

모든 .abc로 끝나는 파일을 찾아 $f를 파일명으로 바꿔가면서(for)

    mv FILENAME `basename $f.abc`.def

명령을 실행한다.

`basename $f .abc` 명령은 파일명중에서 .abc를 제외한 값을 반환한다.
따라서 위의 mv 명령은 다음과 같은 명령으로 완성된다.(file은 .abc를 제외한 파일명)

    mv file.abc file.def

    done

for 루프를 마친다.

csh이나 tcsh에서는 다음과 같이 하여 위의 작업을 할 수 있다.

    foreach f in ( *.abc )
        mv $f `basename $f .abc`.def
    end

--------- 원문 ---------

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

                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2932 - February 15, 2009
                   http://www.ugu.com/sui/ugu/show?tip.today

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

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

반응형
Posted by She쥐포s

어떤 명령을 실행한 결과에서 일정패턴을 찾아 그 결과중 일정부분을 찾으려고 했을때
다음과 같이 입력하는 경험을 해본적이 있을 것이다.
물론 나도 그랬으니까...

$ command | grep PATTERN | awk '{ print $3 }'

위의 문장은 awk의 특성을 이용하여 다음과 같이 줄여 쓸 수 있다.

$ command | awk '/PATTERN/{ print $3 }'

-------------------------<원문>-------------------------
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP
                       Unix Tip 3171 - October 11, 2008
                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

REGEXP MATCHING IN AWK

If you ever find yourself typing "command | grep pattern | awk '{print $3}'
you can shorten this by using the regexp matching in awk, like this:

command | awk '/pattern/{print $3}'

반응형
Posted by She쥐포s

2008. 9. 21. 18:45 Unix

split 명령


이제 앞으로 Floppy는 없어지겠지만 큰 사이즈의 파일을 원하는 사이즈로 나누려면 split 명령을 이용하면 된다.
예를 들어 byte 단위로 나누려면 -b 옵션을 글자수 단위로 나누려면 -c 옵션을 사용하면 된다.
따라서 Floppy에 넣을 수 있는  1400KB 단위로 나누려면 다음과 같이 하면 된다.

# split -b 1400000 FILENAME

이와 같이하면 1400000 byte의 파일이 xaa, xab, ... 등의 이름으로 파일이 생성된다.

다시 원래의 파일로 합치려면

# cat x* > ORIGINAL_FILENAME

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

                       Unix Tip 3150 - September 20, 2008

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

SPLIT FILES FOR FLOPPIES

To split a file up for floppies:

# split -b 1400000

The filenames will be xaa, xbb, etc.
To restore them:

# cat x* > original_filename

반응형
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
이전버튼 1 이전버튼

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

달력

 « |  » 2024.3
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
31

최근에 올라온 글

최근에 달린 댓글

글 보관함