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 2333 - May 22, 2006

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

GREP을 이용하여 빈줄 지우기

awk에 익숙하지 않지만 단순 아스키 파일에서 빈줄을 지우는 빠르고 쉬운 방법을
원하는 사람들은 'grep'과 결합하여 'cat'을 사용하는 것이 효과적인 방법이다.

cat file1 | grep -v '^$' >file2
mv -f file2 file1

----------------------------------------------------------------------

DELETING BLANK LINES USING GREP

For thos who are not familiar with
awk, but still want a quick and easy
way of removing blank lines from a
flat ascii file, remember that the
use of 'cat' in conjuction with
'grep' is just as effective.

cat file1 | grep -v '^$' >file2
mv -f file2 file1
반응형
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
PROBE-SCSI-ALL and IOSTAT
 
시스템이 온라인일때 모든 SCSI장비를 검색하려면 다음 명령을 실행하여
검색을 할 수 있다.
 
# iostat -En
 
이 팁은 SPARC 플랫폼상의 Solaris 2.6에서 사용할 수 있다.
 
---------------------------------------------------------------------
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP
 
                       Unix Tip 2331 - May 20, 2006
 
                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

PROBE-SCSI-ALL and IOSTAT
 
If you want to do probe-scsi-all
when the system is online, you
can do it by running the following
command:
 
# iostat -En
 
This is applicable for Solaris 2.6 on SPARC platform.
반응형
Posted by She쥐포s

telnet, ftp 서비스 잠금

telnet과 ftp 잠금

시스템으로의 외부로부터의 접근(inbound access)이 필요하지 않다면 다음과
같이 하여 사용자들의 telnet 또는 ftp 접근을 거부하라.

vi /etc/inetd.conf

telnet 또는 ftp로 시작하는 줄을 주석처리하라. 파일을 저장하고 편집을 마쳐라.
이제 다음의 명령어로 inetd 데몬을 정지 후 시작하라.

/etc/rc.d/init.d/inet stop
/etc/rc.d/init.d/inet start

(기종에 따라 /etc/init.d 가 될 수도 있다.)

이제부터는 아무도 (외부)네트웍에서 여러분의 서버로 telnet과 ftp를 할수 없다.

※ 역자註 : 요즘은 inetd super deamon을 사용하였으나 요즘은 xinetd를 사용하여
위의 팁은 현실과 맞지 않을 수 있다. xinetd는 다음과 같이 disable = yes (사용안함)
또는 disable = no (사용)을 설정하며

# default: off
# description: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#      
service 서비스명
{
        disable = yes
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}

다음의 명령으로 데몬을 재시작할 수 있다.

/etc/rc.d/init.d/xinetd stop
/etc/rc.d/init.d/xinetd start

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

                       Unix Tip 2323 - May 12, 2006

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

LOCK DOWN TELNET OR FTP

When inbound access isn't required into
a system deny users Telnet or FTP access
do the following:

vi /etc/inetd.conf

Comment the line starts with Telnet or
FTP.  Save the file and exit.

Stop and start the inetd daemon now by
following commands:

/etc/rc.d/init.d/inet stop
/etc/rc.d/init.d/inet start

(Your flavor may be /etc/init.d)

Now on nobody can telnet or FTP to your
server from outside network.

반응형
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
sed를 이용한 공백지우기

다음의 sed 명령어를 사용하여 파일에서 빈라인과 공백만을 포함한 라인을 제거할 수 있다.
 
sed -e '/^[     ]*$/d' InputFile >OutputFile

단일인용부호(') 사이에 있는 앞의 슬래쉬(/)는 sed에 의해 해석될 정규표현식의 범위를
지정한다.
닫는 단일인용부호 앞의 "d"는 sed에게 정규표현식에 해당하는 라인을 지우도록 한다.
 
정규표현식사이에서 캐럿(^)은 라인의 시작에 해당한다.
[]*는 여는 대괄호([)와 닫는 대괄호(])사이의 문자(또는 숫자)가 0번이상
나타나는 것을 나타낸다.
(위의 정규표현식에서는 대괄호 사이에 공백문자(스페이스)와 탭을 넣어야 한다)
달러기호($)는 라인의 끝에 해당된다.

세가지 정규표현식은 함께 어우러져 빈라인이나 공백이나
탭문자(어떠한 조합이든지)로만 이루어진 라인을 찾아낸다.
 
sed의 표준 작동은 표준출력으로 나타나므로 빈라인(또는 공백(스페이스, 탭)으로만
이루어진)을 제외한 모든 라인을 OutputFile로 보낼 것이다.

-----<원문입니다. 오역이 있을지도 모르니..>-----
I SED BLANK

Using sed, you can remove blank lines, and
lines that contain only whitespace, from a
file using the following:

sed -e '/^[     ]*$/d' InputFile >OutputFile

Within the single quotes ('), the forward
slashes (/) delimit the regular expression
that will be interpreted by sed.  The "d"
before the closing single quote, tells sed
to delete any lines that match the regular
expression.

Within the regular expression, the caret
(^) matches the beginning of a line.
The []* matches zero to many occurrences of
the character list between the open bracket
([) and the close bracket (]) (in the above
regular expression, you must insert a space
and a tab between the brackets).  The dollar
sign ($) matches the end of a line.

These three constructs together match any
blank line or any line that contains only
spaces and tabs (in any combination).

Since the standard operation of sed is to
echo lines to stdout, all lines except blank
lines (or lines that only contain whitespace)
will be sent to OutputFile.
반응형
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

2007. 11. 1. 18:58 Unix/Linux

Linux NIC 속도 설정

○ 하도 여러 사람들의 글이 많아서 내 나름 정리를 하고자... man page를 보고 끄적끄적

※ ethtool 사용법(주로 쓰이는 옵션 : 굵게)

# ethtool -s ethX [speed 10|100|1000] [duplex half|full] [port tp|aui|bnc|mii] [autoneg on|off] [phyad N] [xcvr internal|external] [wol p|u|m|b|g|g|s|d...] [sopass xx:yy:zz:aa:bb:cc] [msglvl N]

휴 길기도 하군..

※ 네트웍 설정에 넣기

/etc/sysconfig/network-scripts/ifcfg-ethX 파일에

ETHTOOL_OPTS="speed 1000 duplex full autoneg off"

추가

반응형
Posted by She쥐포s

리눅스 설정 방법

 

1. 네트워크 관련 설정 파일 설정

 ---------------------------------------------------------------------------

/etc/resolv.conf : nameserver

/etc/modules.conf : interface alias , duplex

/etc/sysconfig/network : default gateway , hostname

/etc/sysconfig/network-scripts/ifcfg-eth0 : ipaddr , netmask , broadcast

/etc/sysconfig/static-routes : static으로 설정되어 있는 routing table 정보

---------------------------------------------------------------------------

 

1. NICduplex상태 확인 및 설정

#ethtool eth0 : duplex및 속도 확인

#ethtool -s eth0 duplex full : duplex full로 설정

#ethtool -s eth0 speed 100 : speed 100으로 설정

 

/etc/modules.conf : 부팅시 설정하기 위해서 사용하는 file

alias  eth0  e100

alias  eth1  e100

options e100 e100_speed_duplex=4,4 // 1=10half;2=10full;3=100half;4=100full

* modules.conf에서 option duplex를 설정하는 방법은 NIC마다 다르므로 확인한 후 사용하여야 함.

위 예는 intel NIC를 설정하는것을 보인것임.

 

2. 수동으로 NIC 올리기

-기본값으로 UP / DOWN

#ifconfig eth0 plumb (사용)

#ifconfig eth0 up

#ifconfig eth0 down

#ifconfig eth0 unplumb(사용안함)

 

-값을 지정하여 올리기

#ifconfig eth0 211.41.84.222 netmask 255.255.255.0 broadcast 211.41.84.255 up

 

-인테페이스 사용/미사용

#ifconfig eth0 plumb (사용)

#ifconfig eth0 unplumb (미사용)

 

 

3. routing 수동 설정 방법

routing table에 설정할 내용

----------------------------------------------------

  NIC ip network주소에 대한 routing table

 local주소에 대한 routing table

 default gateway

 static routing table

----------------------------------------------------

#route add -net 211.41.84.0 netmask 255.255.255.0 dev eth0 : network주소에 대한 routing table등록

#route add -net 172.24.9.0 netmask 255.255.255.0 gw 172.24.64.1 dev eth1 : static route 등록

#route add default gw 211.41.84.234 dev eth0 : default gateway등록. /etc/sysconfig/network확인

 

#route add -host 211.41.84.111 gw xxx.xxx.xxx.xxx dev eth0 : 특정 호스트에 대한 routing table등록.

* netmask가 빠짐을 주의

 

/etc/sysconfig/static-routes : 그외 static으로 등록하여야 할 것(paran.com)

any net 172.24.9.0  netmask 255.255.255.0 gw 172.24.64.1 metric 1

any net 172.16.0.0  netmask 255.240.0.0   gw 172.24.64.1 metric 1

any net 10.0.0.0    netmask 255.0.0.0     gw 172.24.64.1 metric 1

any net 192.168.0.0 netmask 255.255.0.0   gw 172.24.64.1 metric 1

 

 

 

- 간단 요약 -

IP 설정 정보 확인
1. IP 주소
2. 넷마스크
3. G/W 주소
4. DNS 주소
5. 네트웍 주소


네트웍 설정
1. /etc/hosts

2. /etc/resolv.conf

3. 호스트 이름, 게이트웨이, 게이트웨이로 갈 장치 등을 설정
/etc/sysconfig/network 파일 수정
ex)  1  NETWORKING=yes
     2  HOSTNAME=kwsweb04
     3  GATEWAY=211.41.73.129
     4  GATEWAYDEV=eth0

4. 인터페이스 설정
/etc/sysconfig/network-scripts/ifcfg-eth0
ex)  1  DEVICE=eth0
     2  BOOTPROTO=static
     3  BROADCAST=211.41.73.191
     4  IPADDR=211.41.73.144
     5  NETMASK=255.255.255.192
     6  NETWORK=211.41.73.128
     7  ONBOOT=yes
각 인터페이스마다 설정한다.
5. /etc/rc.d/init.d/network restart
또는 간단히 service network restart


네트웍 설정 확인
# ping www.paran.com
# ifconfg -a | more
# mii-tool
ftp나 sftp 등으로 속도 테스트

※ 원문 : http://cafe.naver.com/quest4i/69

반응형
Posted by She쥐포s

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

최근에 올라온 글

최근에 달린 댓글

글 보관함