Linux2010. 4. 19. 17:13
리눅스에서 cd는 디렉토리를 변경하고,
pwd는 현재 작업 디렉토리를 보여준다.

그걸 api 수준에서 보자면
cd는 chdir() 이고
pwd는 getcwd() 이다.

long getcwd(char *buf, unsigned long size);

#include <unistd.h>
int chdir(const char *path);
int fchdir(int fd);

[링크 : http://linux.die.net/man/3/getcwd]
[링크 : http://linux.die.net/man/3/chdir]


2010.04.20 추가

코드샘플
#include "unistd.h"

void main()
{
	int ret;
	char buff[256];
	
	getcwd(buff, 255);
	printf("%s\n",buff);
	
	ret = chdir("/etc");

	getcwd(buff, 255);
	printf("%s\n",buff);	
}

Posted by 구차니
Linux2010. 4. 10. 18:11
wget은 머의 약자일려나.. 혹시.. ftp의 get 명령어를 Web에서 한다고 wget 이려나?

아무튼, wget은 Ubuntu 9.10에서 2010-04-10 에 1.11.4 버전을 유지하고있다.
$ wget -V
GNU Wget 1.11.4

Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
Currently maintained by Micah Cowan <micah@cowan.name>.
gnu 에서는 1.12 가 최신인데 짝수버전은 피하는 성격상 11.4를 넣은것으로 생각된다.

[링크 : http://www.gnu.org/software/wget/]
[링크 : http://ftp.gnu.org/gnu/wget/]


그리고, wget이 필요로 하는 라이브러리는 다음과 같다.
$ ldd /usr/bin/wget
        linux-gate.so.1 =>  (0xb78c7000)
        libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb78ac000)
        librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb78a3000)
        libssl.so.0.9.8 => /lib/i686/cmov/libssl.so.0.9.8 (0xb785c000)
        libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0xb7716000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb75d1000)
        /lib/ld-linux.so.2 (0xb78c8000)
        libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb75b8000)
        libz.so.1 => /lib/libz.so.1 (0xb75a2000)

파일은 대략 237K 이다.(보기보다 덩치가 큰녀석이다!)
$ ll /usr/bin/wget
-rwxr-xr-x 1 root root 242516 2009-10-07 00:12 /usr/bin/wget

busybox 에서는 cookie 관련 내용은 빠져있는 것으로 생각된다.
wget

    wget [-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document file]
        [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]
        [-U|--user-agent agent] url

    Retrieve files via HTTP or FTP

    Options:

            -s      Spider mode - only check file existence
            -c      Continue retrieval of aborted transfer
            -q      Quiet
            -P      Set directory prefix to DIR
            -O      Save to filename ('-' for stdout)
            -U      Adjust 'User-Agent' field
            -Y      Use proxy ('on' or 'off')

[링크 : http://www.busybox.net/downloads/BusyBox.html]

Posted by 구차니
Linux2010. 4. 8. 22:28
FC6 기준으로
/usr/share/doc/MAKEDEV-3.23/devices-2.6+.txt
파일이 존재하며

커널에서 상당부분 정해진 값으로 고정된 것으로 보인다.

type               major,minor

crw-r----- 1 root kmem   1,   1  4월  2 20:04 mem
crw-rw-rw- 1 root root   1,   3  4월  2 20:04 null
crw-r----- 1 root kmem   1,   4  4월  2 20:04 port
crw-rw-rw- 1 root root   1,   5  4월  2 20:04 zero
crw-rw-rw- 1 root root   1,   7  4월  2 20:04 full
crw-rw-rw- 1 root root   1,   8  4월  2 20:04 random
cr--r--r-- 1 root root   1,   9  4월  2 20:04 urandom
crw------- 1 root root   111  4월  2 20:04 kmsg
crw------- 1 root root   112  4월  2 20:04 oldmem

brw-r----- 1 root disk   1,   0  4월  2 20:04 ram0
brw-r----- 1 root disk   1,   1  4월  2 20:04 ram1
brw-r----- 1 root disk   1,   2  4월  2 20:04 ram2
brw-r----- 1 root disk   1,   3  4월  2 20:04 ram3
brw-r----- 1 root disk   1,   4  4월  2 20:04 ram4
brw-r----- 1 root disk   1,   5  4월  2 20:04 ram5
brw-r----- 1 root disk   1,   6  4월  2 20:04 ram6
brw-r----- 1 root disk   1,   7  4월  2 20:04 ram7
brw-r----- 1 root disk   1,   8  4월  2 20:04 ram8
brw-r----- 1 root disk   1,   9  4월  2 20:04 ram9
brw-r----- 1 root disk   110  4월  2 20:04 ram10
brw-r----- 1 root disk   111  4월  2 20:04 ram11
brw-r----- 1 root disk   112  4월  2 20:04 ram12
brw-r----- 1 root disk   113  4월  2 20:04 ram13
brw-r----- 1 root disk   114  4월  2 20:04 ram14
brw-r----- 1 root disk   115  4월  2 20:04 ram15

  1 char    Memory devices
          1 = /dev/mem        Physical memory access
          2 = /dev/kmem        Kernel virtual memory access
          3 = /dev/null        Null device
          4 = /dev/port        I/O port access
          5 = /dev/zero        Null byte source
          6 = /dev/core        OBSOLETE - replaced by /proc/kcore
          7 = /dev/full        Returns ENOSPC on write
          8 = /dev/random    Nondeterministic random number gen.
          9 = /dev/urandom    Faster, less secure random number gen.
         10 = /dev/aio        Asyncronous I/O notification interface
         11 = /dev/kmsg        Writes to this come out as printk's

  1 block    RAM disk
          0 = /dev/ram0        First RAM disk
          1 = /dev/ram1        Second RAM disk
            ...
        250 = /dev/initrd    Initial RAM disk {2.6}

이 파일을 열어보면 major, minor 별로 장치의 설명이 나와있다.

[링크 : http://unix.co.kr/bbs/board.php?bo_table=LSN_qa&wr_id=185207&page=]
Posted by 구차니
Linux2010. 4. 5. 18:23
by 하나 차이지만, 큰 차이가 있는 녀석이다.

gethostname()은 자기 자신의 이름을 얻는 함수이고
gethostbyname()은 다른 녀석의 ip를 얻는 함수이다.

#include <unistd.h>
int gethostname(char *name, size_t len);
int sethostname(const char *name, size_t len);

#include <netdb.h>
struct hostent *gethostbyname(const char *name);

#include <sys/socket.h>       /* for AF_INET */
struct hostent *gethostbyaddr(const void *addr, int len, int type);

# cat /usr/include/netdb.h
/* Description of data base entry for a single host.  */
struct hostent
{
  char *h_name;                 /* Official name of host.  */
  char **h_aliases;             /* Alias list.  */
  int h_addrtype;               /* Host address type.  */
  int h_length;                 /* Length of address.  */
  char **h_addr_list;           /* List of addresses from name server.  */
#define h_addr  h_addr_list[0]  /* Address, for backward compatibility.  */
};

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/3/gethostbyname]
[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/gethostname]

'Linux' 카테고리의 다른 글

wget  (4) 2010.04.10
/dev의 major minor에 대하여  (0) 2010.04.08
chown 사용방법(사용자와 그룹 바꾸기)  (0) 2010.04.03
터미널을 통한 데이터 통신에서 0x11이 사라졌어요  (0) 2010.04.02
ls 용량별로 정렬하기  (0) 2010.04.01
Posted by 구차니
Linux2010. 4. 3. 21:37
chown 은 원래 이름만 보자면 파일이나 디렉토리의 소유자를 변경하는 유틸리티인데
사용용법에 따라서는 chgrp를 통괄하는 유틸리티이다.

SYNOPSIS
       chown [OPTION]... [OWNER][:[GROUP]] FILE...
       chown [OPTION]... --reference=RFILE FILE...

[링크 : http://linux.die.net/man/1/chown]

SYNOPSIS
       chgrp [OPTION]... GROUP FILE...
       chgrp [OPTION]... --reference=RFILE FILE...

[링크 : http://linux.die.net/man/1/chgrp]

chown -R user dir
chgrp -R group dir

명령을
chown -R user:group dir
로 한번에 끝낼수 있다.
Posted by 구차니
Linux/Ubuntu2010. 4. 3. 21:31
우분투에서 아파치를 설치하면 아래와 같은 기본설정 파일이 생성된다.
htdocs는 /var/www 이고 root:root 권한을 가진다.
drwxr-xr-x  7 root root  4096 2010-04-03 21:18 www

하지만 apache2는 www-data:www-data 권한으로 서버가 실행되고
웹서버는 /var/www에 대하여 other 권한으로 파일을 access 하게된다.
/var/www를 www-data:www-data 로 변경하는게 무난한 방법이 될 듯하다.

# cat /etc/apache2/apache2.conf
144 # These need to be set in /etc/apache2/envvars
145 User ${APACHE_RUN_USER}
146 Group ${APACHE_RUN_GROUP}

# cat /etc/apache2/envvars
  1 # envvars - default environment variables for apache2ctl
  2
  3 # Since there is no sane way to get the parsed apache2 config in scripts, some
  4 # settings are defined via environment variables and then used in apache2ctl,
  5 # /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
  6 export APACHE_RUN_USER=www-data
  7 export APACHE_RUN_GROUP=www-data

'Linux > Ubuntu' 카테고리의 다른 글

Ubuntu 10.04 LTS!  (0) 2010.05.07
udevinfo -> udevadm  (0) 2010.05.03
우분투에 Apache / PHP / Mysql 설치하기  (0) 2010.04.02
fprintf man page가 왜 없지?!  (0) 2010.03.26
apt 명령어 정ㅋ벅ㅋ  (0) 2010.03.04
Posted by 구차니
Linux/Ubuntu2010. 4. 2. 23:16
설치 패키지
apache2
mysql-client-5.1
php5

위에 세가지를 선택하면 아래와 같이 줄줄이 엮여서 설치된다.



아파치 설정
/etc/apache2/apache2.conf (환경설정파일 경로)
/var/www (기본 설치시 htdocs 경로)

Mysql
기본암호는 설치시에 물어봄
/etc/mysql/my.cnf (환경설정파일 경로)
/var/lib/mysql (데이터경로)

PHP
$ cat index.php
<?
    phpinfo();
?>

[링크 : http://coffeenix.net/board_view.php?bd_code=1684]
[링크 : http://www.yamuzin.com/zbxe/758]
[링크 : http://www.sitepoint.com/forums/showthread.php?t=658149]
[링크 : https://help.ubuntu.com/community/ApacheMySQLPHP]

'Linux > Ubuntu' 카테고리의 다른 글

udevinfo -> udevadm  (0) 2010.05.03
apache2 환경설정  (0) 2010.04.03
fprintf man page가 왜 없지?!  (0) 2010.03.26
apt 명령어 정ㅋ벅ㅋ  (0) 2010.03.04
우분투에서 /etc/sysconfig/network 에 대응하는 파일  (0) 2010.02.16
Posted by 구차니
Linux2010. 4. 2. 16:18
console로 열린 터미널에서 일부의 속성만을 변경해서 사용중이었는데
다른건 전송이 되는데 0x11 데이터가 제대로 받아지지 않는 문제가 발생했다.

일단 엔터 치기 전에는 입력이 받아지지 않는건
'캐노니컬 모드(canonical mode)'로 인한 것이기 때문에 ~ICANON 으로 해결을 했지만

0x11 은 DC1(Data Control 1 - XON) 으로 캐노니컬과는 별개이기 때문에 0x11 데이터가 손실되었다.
터미널은 워낙 내용이 방대해서.. 간단하게 해결책만 제시하자면

ffmpeg의 소스중 일부를 인용
 712                 new_set.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
 713                                       |INLCR|IGNCR|ICRNL|IXON);
 714                 new_set.c_oflag |= OPOST;
 715                 new_set.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
 716                 new_set.c_cflag &= ~(CSIZE|PARENB);
 717                 new_set.c_cflag |= CS8;
 718                 new_set.c_cc[VMIN] = 1;
 719                 new_set.c_cc[VTIME] = 0;


       IXON   Enable XON/XOFF flow control on output.
       IXOFF  Enable XON/XOFF flow control on input.

[링크 : http://linux.die.net/man/3/tcgetattr]

결론 : 아마도 이랬을 것입니다
Posted by 구차니
Linux2010. 4. 1. 14:12
ls 자체적으로 정렬기능을 제공한다.
하지만, 디렉토리별이라서, 전체에 대해서 정렬을 하지는 못한다.

       -S     sort by file size

       --sort=WORD
              extension -X, none -U, size -S, time -t, version -v, status -c, time -t, atime -u, access -u, use -u

[링크 : http://linux.die.net/man/1/ls]

[링크 : http://thedaneshproject.com/posts/sort-files-by-size/]
Posted by 구차니
Linux2010. 3. 31. 11:38
fileno() 는 fp를 fd로 변환해주고
fdopen()은 fd를 fp로 변환해준다.

int fileno(FILE *stream);
FILE *fdopen(int fildes, const char *mode);

[링크 : http://linux.die.net/man/3/fileno]
[링크 : http://linux.die.net/man/3/fdopen]

아무튼 원하는 파일이나, stdin/out/err에 대한 fd를 얻어온뒤
fcntl() 함수를 이용하여 변경하면 된다.

fctnl(fd, F_SETFL, O_NONBLOCK);
(테스트 안해봣음!)

int fcntl(int fd, int cmd, long arg);

F_SETFL
    Set the file status flags to the value specified by arg. File access mode (O_RDONLY, O_WRONLY, O_RDWR) and file creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) in arg are ignored. On Linux this command can only change the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags.

[링크 : http://linux.die.net/man/2/fcntl]
[링 크 : http://www.falinux.com/win/study/06/devicedriver11.html]

Posted by 구차니