2011. 2. 12. 08:38

NAME


  • sleep – Sleep for the specified number of seconds


SYNOPSIS


#include <unistd.h>

unsigned int sleep(unsigned int seconds);


DESCRIPTION


  • sleep()를 이용하면 현재 동작중인 프로세스를 지정한 초(seconds)만큼 정지 시킨다.
  • sleep()는 SIGALRM을 이용해서 구현되 되었으므로 alarm()와 섞어서 쓰는건 좋지 않다.
  • 하나 이상의 alarm을 사용하게 될경우 먼저 설정되었던 alarm은 무효화 되어 버리기 때문이다.


RETURN VALUE


성공 0, 실패 -1반환, 적당한 errno값 설정.


EXAMPLE


지정한 n(초)가 경과될 때마다 소리를 낸다. (beeper.c)

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

 

int main(int argc, char *argv[]) {

    int sleeptime;

 

    if (argc != 2) {

        fprintf(stderr, "Usage:%s n\n", argv[0]);

        return 1;

    }

    sleeptime = atoi(argv[1]);

    fprintf(stderr, "Sleep time is %d\n", sleeptime);

    for ( ; ; ) {

        sleep(sleeptime);

        printf("\007");

        fflush(stdout);

    }

}

 

'API 및 라이브러리 > C 라이브러리 함수' 카테고리의 다른 글

의사 난수 생성(pseudo-random number) : srand(), rand()  (1) 2011.10.08
strdup(3)  (0) 2010.09.14
strstr(3)  (1) 2010.09.11
system(3)  (0) 2009.12.19
getusershell(3)  (0) 2009.12.19
Posted by devanix
2011. 2. 8. 08:13

NAME


du – estimate file space usage


SYNOPSIS


du [OPTION]... [FILE]...

du [OPTION]... --files0-from=F


DESCRIPTION


  • du는 "Disk Usage"의 약어로서 파일 및 디렉토리의 사용량을 확인하는 명령어.
  • df가 파티션(파일시스템)단위의 디스크사용량을 점검한다면,
    du는 특정 디렉토리 또는 파일을 단위로하여 그 용량을 확인하는 명령어.
  • 즉, 현재디렉토리의 용량뿐 아니라 현재 디렉토리의 서브디렉토리 및 파일들가지 모두 함께 사용량을 계산하여 표시. (기본 용량표시단위는 Kbyte)
  • 특정 디렉토리 확인( "du [디렉토리명]" )

devanix@xubuntu10:~$ du /etc

4 /etc/dbus-1/event.d

140 /etc/dbus-1/system.d

4 /etc/dbus-1/session.d

160 /etc/dbus-1

…..

- /etc 디렉토리에 존재하는 모든 파일들(서브디렉토리내의 파일들까지 포함)의 용량과 함께 파일명을 표시.

- 용량단위는 kbyte 단위.

- 수많은 파일들이 존재하는 디렉토리는 한 화면에 모두 표시.


OPTION


  • -s, --summarize (display only a total for each argument)
    • 특정 디렉토리의 전체 사용량 점검.
    • 지정된 디렉토리 내에 존재하는 모든 파일과 서브디렉토리들의 용량을 모두 합친 전체용량(summary)을 표시.

root@xubuntu10:~# du -s /etc

13116 /etc

- /etc/가 사용하는 전체 용량은 13116kbyte.

 

  • -h, --human-readable (print sizes in human readable format (e.g., 1K 234M 2G))
    • K, M, G단위는 용량의 크기에 따라서 적당하게 표시.(사람이 좀 더 읽기 편하게 표시)

root@xubuntu10:~# du -h /etc

4.0K /etc/dbus-1/event.d

140K /etc/dbus-1/system.d

4.0K /etc/dbus-1/session.d

160K /etc/dbus-1

…..

- "-sh"옵션을 사용하여 전체용량을 모두 합해서 용량단위까지 붙여서 출력.

 

  • -a, --all (write counts for all files, not just directories)
    • 현재 디렉토리 아래의 모든 파일과 디렉토리 사용 정보를 보여준다.

devanix@xubuntu10:/data/test$ du

8 .

devanix@xubuntu10:/data/test$ du -a

0 ./bbb

0 ./ddd

0 ./aa

0 ./ccc

4 ./aaa

8 .

  • -B, --block-size=SIZE (use SIZE-byte blocks)
    • 지정한 size를 블록 사이즈로 사용한다.
  • -b, --bytes (equivalent to `--apparent-size --block-size=1')
    • 바이트(bytes) 크기로 보여준다.
  • -k (like --block-size=1K)
    • 보여지는 단위를 1Kbyte형태로 보여준다.
  • -c, --total (produce a grand total)
    • 모든 파일의 디스크 사용정보를 보여주고 합계를 보여준다.
  • -D, --dereference-args (dereference only symlinks that are listed on the command line)
    • 계산 되는 파일이나 , 경로가 심볼릭 링크이면 그 원본의 값을 보여준다.
  • -H (equivalent to --dereference-args (-D) )
    • 1024단위의 비율로 보여준다.
  • -l, --count-links (count sizes many times if hard linked)
    • 만약 계산되는 파일 중에 하드 링크되어 있는 파일이 있다면 , 그것을 그대로 계산한다.
  • -L, --dereference (dereference all symbolic links)
    • 모든 심볼릭 링크를 따른다.
  • -S, --separate-dirs (do not include size of subdirectories)
    • 디렉토리의 총 사용량을 보여줄 때, 하위 디렉토리의 사용량은 제외한다.
  • -x, --one-file-system (skip directories on different file systems)
    • 현재 파일 시스템의 파일 사용량만을 보여준다.
  • -X, --exclude-from=FILE (exclude files that match any pattern in FILE)
    • 지정한 파일과 일치하는것은 제외한다.

 

'Linux > General Commands' 카테고리의 다른 글

df - (파일시스템 단위의 디스크 남은 사용량 출력)  (0) 2011.02.05
yes(1)  (0) 2010.05.29
tee(1)  (0) 2010.05.29
wc(1)  (0) 2009.04.14
echo(1)  (0) 2009.04.13
Posted by devanix
2011. 2. 5. 17:41

NAME


df – report file system disk space usage


SYSNOPSIS


df [OPTION]... [FILE]...

which : /bin/df


DESCRIPTION


  • df는 "Disk Free"의 약어로 디스크사용량을 출력.
    • 현재 사용중인 파일시스템의 전체용량, 사용한 용량, 사용가능한 용량, 사용 율, 마운트정보 확인.
    • df명령어는 /etc/fstab 파일에서 파일시스템정보를 참조하고, /etc/mtab에서 마운트된 정보를 참조.
    • byte, Kbyte, Mbyte, Gbyte의 용량단위로 전체 파일시스템의 디스크사용량을 한눈에 확인.
      (기본표시 용량단위는 KB(Kilo Byte)
    • 서버 장애의 주된 원인이 될 수 있는 File System Full(파일시스템용량이 꽉 참)을 방지하기 위하여 시스템관리자의 주된 없무 중 한가지가 주기적인 파일시스템 사용량 점검.


OPTION


  • 기본 사용 ("df", 현재 서버의 디스크사용량을 파티션별로 확인)

devanix@xubuntu10:~$ df

Filesystem  1K-blocks    Used   Available  Use%  Mounted on

/dev/sdb1         76896288    2721732    70268356        4%     /

none                    507152         256       506896         1%     /dev

none                    512748         664       512084         1%    /dev/shm

none                    512748          92       512656          1%   /var/run

none                    512748           0       512748          0%    /var/lock

none                 76896288  2721732    70268356          4%    /var/lib/ureadahead/debugfs

첫번째 필드(Filesystem)

- 파일시스템 장치명(device name).

두번째 필드(1K-blocks)

- 파일시스템에 할당된 용량.

세번째 필드(Used)

- 사용된 용량.

네번째 필드(Available)

- 사용 가능한(사용되지 않고 남아 있는) 용량.

다섯째 필드(Use%)

- 사용 율(즉, 전체 할당된 용량에 대한 사용된 용량의 백분율)

여섯째 필드(Mounted on)

- 각 파일시스템이 마운트된 마운트포인트(위치, 디렉토리)를 표시

 

  • -a, --all (include dummy file systems), 모든 파일시스템을 대상으로 점검.
    • 크기가 0인 모든 파일시스템에 대한 사용량을 확인.(원래 크기가 0인 파일시스템은 보여주지 않는다)
  • -i, --inodes (list inode information instead of block usage), inode 단위로 사용량 정보를 표시.
    • 블록(block)대신에 inoce 단위로 사용량 정보를 표시.
  • -k (like --block-size=1K), 용량을 Kbyte 단위로 표시 (Default)
  • -m (like --block-size=1M), 용량을 Mbyte 단위로 표시.
  • -h, --human-readable (print sizes in human readable format (e.g., 1K 234M 2G))
    • 사람이 보기 쉽도록 최적의 용량단위를 알아서 표시.

devanix@xubuntu10:~$ df -h

Filesystem   Size   Used   Avail   Use%   Mounted on

/dev/sdb1         74G     2.6G       68G        4%     /

none               496M      256K    496M        1%    /dev

none               501M      664K    501M        1%    /dev/shm

none               501M       92K     501M        1%    /var/run

none               501M          0      501M        0%    /var/lock

none                  74G     2.6G       68G        4%    /var/lib/ureadahead/debugfs

 

  • -T, --print-type (print file system type), 파일시스템의 종류와 함께 표시.

devanix@xubuntu10:~$ df -T

Filesystem    Type   1K-blocks    Used   Available   Use%   Mounted on

/dev/sdb1       ext3         76896288     2721740      70268348         4%     /

none        devtmpfs           507152           256         506896        1%     /dev

none             tmpfs            512748           664         512084        1%     /dev/shm

none             tmpfs            512748            92         512656        1%     /var/run

none             tmpfs            512748             0         512748         0%    /var/lock

none         debugfs         76896288    2721740      70268348         4%   /var/lib/ureadahead/debugfs

 

  • -t, --type=TYPE (limit listing to file systems of type TYPE), 특정 파일시스템의 종류만을 대상으로 출력.
    • -t 옵션 뒤에 파일시스템의 종류명을 지정하면 그 파일시스템의 종류를 가진 파일시스템에 대해서만 사용량을 표시. (예 : "df –t ext3")

devanix@xubuntu10:~$ df -t ext3

Filesystem   1K-blocks   Used    Available   Use%    Mounted on

/dev/sdb1           76896288  2721740       70268348         4%       /

devanix@xubuntu10:~$ df -t ext4

Filesystem   1K-blocks   Used    Available   Use%    Mounted on

/dev/sdb2           36510204    739492       33915992         3%      /data

  • -x, --exclude-type=TYPE (limit listing to file systems not of type TYPE), 특정 파일시스템을 제외하고 출력.
    • -t 옵션과는 반대의 경우로서 특정 파일시스템 타입을 제외한 파일시스템에 대해서만 출력.
      (예 : "df –x ext3")

 

  • --total (produce a grand total), 총합계를 출력.

devanix@xubuntu10:~$ df --total

total   192348176   6183984   176497072    4%

 

'Linux > General Commands' 카테고리의 다른 글

du – (디렉토리, 사용자별 단위의 디스크 사용량 점검)  (0) 2011.02.08
yes(1)  (0) 2010.05.29
tee(1)  (0) 2010.05.29
wc(1)  (0) 2009.04.14
echo(1)  (0) 2009.04.13
Posted by devanix