2007. 11. 3. 21:25 Unix

큰 파일 찾기(2)

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

                       Unix Tip 2376 - July  4, 2006

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

큰 파일 찾기(2)

파일시스템에서 큰 파일을 찾기 위해서는 다음의 명령어를 사용하라.

find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

FINDING MORE LARGE FILES

To find out the large files
on a file system.

find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
반응형
Posted by She쥐포s
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2374 - July  2, 2006

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

리눅스에서의 줄 번호

만일 파일내용과 줄 번호를 원한다면(인쇄할 때)(?)
리눅스에서는 "nl" 명령어를 사용할 수 있다.

$ nl file.c > file.c.num

많은 옵션을 위해서는 man 페이지를 보라.
보통 nl은 공백이 아닌 줄만 줄번호를 붙인다.

강제로 모든 줄에 번호를 주려면 -ba 옵션을 사용하라

$ nl -ba file.c >file.c.all_num

@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
LINE NUMBERS IN LINUX

If you want a file with line
numbers (say for printing).
You can use the "nl" command
in linux.

$ nl file.c > file.c.num

See man for more options.
Normally nl gives line numbers
only for non blank lines.

To force it to give it to all lines
use -ba option:

$ nl -ba file.c >file.c.all_num
반응형
Posted by She쥐포s

2007. 11. 3. 21:24 Unix

unix man 페이지 변환

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

                       Unix Tip 2373 - July  1, 2006

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

unix man 페이지 변환

(또 다른 접근법)

unix man 페이지를 텍스트 포맷으로 변환하기 위해서는 'man' 자체의 기능을
사용할 수 있다.(man man을 확인하라)

PAGER 환경변수를 'cat'으로 설정하라. 그 후 다음을 실행하라

'man command_name > command_name.txt'

예를 들어 csh에서 lsman 페이지를 텍스트 파일로 보려면
'setenv PAGER cat'실행하고

man ls > ls.txt

주의 : PAGER 환경변수를 해제하는 것(unsetenv PAGER)을 잊지마라,  그렇지
않으면 매번 man 명령어를 실행할 때마다  'more' 또는 'less'를 하기 위해서
파이프를 사용해야 할 것이다.
 
譯者 註 : 내 생각에는 man 페이지의 내용을 텍스트 파일로 만드는 데는 다음의
명령이 최고인 것 같다.(난 주로 bash를 사용한다.)
 
man ls | col -b > ls.txt
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

CONVERTING UNIX MAN PAGES

(Another approach)

To convert Unix Man pages
to text format, you can make
use of one feature of 'man'
itself.  (check out man man)

Set environment variable
PAGER to 'cat'.  Then run:

'man command_name > command_name.txt'

eg. in csh, to see man ls in a text file
setenv PAGER cat
man ls > ls.txt

NOTE: Do not forget to
unsetenv PAGER, else you will
have to pipe every man command
to 'more' or (my favourite) 'less'.
반응형
Posted by She쥐포s
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2371 - June 29, 2006

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

IP 주소를 알아내는 또 다른 방법
 
이전의 팁은 ifconfig의 출력을 이용하여 시스템의 IP 주소를 알아 내는 방법을
나타냈다. 하지만 ifconfig의 출력이 시스템마다 다르다.

Solaris에서는

ifconfig -a | grep "inet" |  grep -v "127.0.0.1" | awk '{print $2;}'

HP-UX에서는

ifconfig foo | grep "inet" | awk '{print $2;}'

여기서 foo는 인터페이스, 일반적으로 lan0, lan1등을 나타낸다.
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

ANOTHER GET YOUR IP ADDRESS

A previous tip listed how
to get the IP address for your
system using the output from
ifconfig. However the output
from ifconfig is different
across systems.

For Solaris use:

ifconfig -a | grep "inet" |  grep -v "127.0.0.1" | awk '{print $2;}'

For HP-UX use:

ifconfig foo | grep "inet" | awk '{print $2;}'

Where foo is the interface, generally lan0, lan1 etc.
반응형
Posted by She쥐포s

2007. 11. 3. 21:22 Unix

전체 파일시스템 체크

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

                       Unix Tip 2366 - June 24, 2006

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

전체 파일시스템 체크

많은 경우 파일 시스템이 너무 꽉 찬경우가 있다.
파일시스템에서 어떤 파일이 큰 파일인지 확인하기 위해서는 다음의 명령어를 사용할
수 있다.

find / -xdev -size +1024 -ls | sort -r +b

명령어로 너무 커진 파일을 정리할 수 있다.
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
CHECKI FOR FULL FILESYSTEMS

Many times we have a file
systems which is too full.
To quickly find out which
are the large files in there
we could use:

find / -xdev -size +1024 -ls | sort -r +b

So we can clean up some
files which have grown too big.
반응형
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2360 - June 18, 2006

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
gzip, znew, compress

HP Unix에서 "compress" 명령은 약 50~60%를 압축한다. "gzip"은 80%까지 파일을
압축한다. HP Unix에는 compress 파일(*.Z(註: 대문자))을 zip파일(註: *.gz)로
변환해주는 명령이 있다. "znew"는 자동으로 compress 파일(*.Z)을 gunzip파일(*.gz)로
변환해 준다.
 
예:
$ znew test.Z
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
gzip, znew, compress
 
In HP Unix "compress" command will compress
around 50 to 60%.  "gzip" will compress the
file upto 80%. There is a command available
in HP's unix to convert a compress file to
a zip file. "znew" will automatically
convert compressed files(*.Z) to gunzip
files(*.gz).

Example:
$ znew test.Z
반응형
Posted by She쥐포s

2007. 11. 3. 21:16 Unix

bc 명령어

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

                       Unix Tip 2344 - June  2, 2006

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

BC(AD 이전이 아님??)

우리들의 옛 친구이자 종종 잊혀지는 bc를 가동하라.

% bc

산술식을 입력하라.

20+20

그러면 결과값을 리턴할 것이다.

40

하지만 최고의 사용법은(?), 모든 변환의 필요에 따라 "obase"와
"ibase"명령을
사용하는 것이다.
 
예를 들어 다음을 입력하라

obase=16

그리고 다음을 입력하라.

255

그러면 결과는 "FF"가 될 것이다.

다음, 다음 내용을 입력한다면

obase=2

다음에 .(또는 마침표)를 입력하라, 이는 "마지막 숫자"임을 나타낸다.

위의 식은 "11111111"을 리턴할 것이다, 이는 255 2진수 표현이다.

16진수를 10진수로 바꿀 필요가 있다면 단순히 "ibase=16"과 "obase=10"를 입력하라.
 
재미있게 사용하길~!
-------------------------------
※ 역자 설명
 
- bc의 명령어중 4개의 특별 변수
  1. scale
        소숫점이하에 사용할 자릿수(기본값 0)
  2. ibase
        입력되는 수의 변환 기반을 정의(기본값 10)
  3. obase
        출력되는 수의 변환 기반을 정의(기본값 10)
  4. last
        맨 마지막 인쇄된 숫자 값
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
BC AND NOT BEFORE AD

Fire up our old friend and often forgotten bc.

% bc

Enter your arthimetic expression

20+20

Will return

40

but the best part is, use the
"obase" and "ibase" commands for all
your conversion needs.

For example, type:

obase=16

then type:

255

This will output "FF".

Next, if you type:

obase=2

Then a dot (or period), it stands for
"the last number")

It will return "11111111", that's 255 in binary!

If you need hex to dec,
just type "ibase=16" and "obase=10"

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

                       Unix Tip 2343 - June  1, 2006

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

파일 사이즈별로 나열하기

파일 사이즈 별로 정렬된 목록을 보고 싶다면 다음의 명령을 사용할 수 있으며,
명령은 파일을 역순(Z, Y, X, ...)으로 나열한다. 만약 같은 일을 하위디렉토리까지
해야 한다면 두번째 명령을 사용할 수 있다.

ls -l | grep ^- | sort -nr -k 5 | more

ls -lR | grep ^- | sort -nr -k 5 | more
 
@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@
 
LISTING FILES BY SIZE

If you want to have a listing of the
files sorted by size, you can use the
following command(s), it will list
the files in decrease order. if you
need to do the same thing recursively,
you could use the second one.

ls -l | grep ^- | sort -nr -k 5 | more

ls -lR | grep ^- | sort -nr -k 5 | more
반응형
Posted by She쥐포s

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

달력

 « |  » 2024.5
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

최근에 올라온 글

최근에 달린 댓글

글 보관함