'linux'에 해당되는 글 12건

  1. 2008.11.04 리눅스에서 디렉토리 이름 변경시 주의사항 2
  2. 2008.10.29 File 길이 알아내기 2
Linux2008. 11. 4. 14:43
졸지에 낙시글이 되것 같아. 디렉토리 이름 변경하는 방법 급조 -ㅁ-
리눅스에서는 엄밀하게 디렉토리 이름 바꾸는 방법은 존재하지 않습니다.
리눅스의 모든 것들은 파일로 관리 되기 때문이죠.

그런 이유로 리눅스에서 디렉토리 이름을 변경하려면 mv
다른 이름으로 디렉토리를 옮기면 됩니다.

예) test_1 디렉토리를 test_opps로 바꾸기
$ mv test_1 test_oops

---------------------------------------------
오늘 작업을 하다가 신기한 현상을 발견했다.

리눅스에서 컴파일 하고, 윈도우에서 samba와 cvs로 관리하는 시스템인데,
리눅스 에서 열어 놓은 디렉토리를 윈도우에서 다른 이름으로 변경하고
리눅스에서 열린 디렉토리의 이름으로 cvs checkout을 했다.(그러니까 백업본을 가져왔다)

그리고 나서 소스를 변경하고 다시 컴파일 하는데, 변경사항이 없음?!?!?!
먼가 이상해서 경로를 빠져 나왔다가 다시 들어 가니 그 제서야 제대로 컴파일이 된다.

결론만 말하자면, linux에서 directory는 이름으로 확인하는것이 아니라 inode로 확인하므로,
다른 곳에서 디렉토리를 수정했을 경우, 반드시 cd 명령어로 다시 경로를 이동해서 사용하자!!


삭제 테스트
step 1. 임의의 디렉토리를 만든다. (귀찮으니 tt라고 하자)
           [user@hostname ~] $ mkdir tt

step 2. 임의의 디렉토리로 들어간다.
           [user@hostname ~] $ cd tt

step 3. 임의의 디렉토리의 inode를 확인해본다.
           [user@hostname tt] $ ls -ali
           11044597 drwxrwxr-x 2 user hostname 4096 Nov  4 14:38 .
            3866626 drwxrwxrwx 9 user hostname 4096 Nov  4 14:38 ..

step 4. 임의의 디렉토리를 다른 콘솔이나 윈도우의 다른 창에서 삭제한다.

step 5. 다시 inode를 출력해본다.
           [user@hostname tt] $ ls -ali
           total 0

step 6. 현재 경로를 알아본다.
           [user@hostname tt] $ pwd
           /home/user/tt

'Linux' 카테고리의 다른 글

파일 존재 유무 확인하기(how to check existence of file on C,linux)  (2) 2008.12.16
execl() - excute a file  (0) 2008.12.08
fork : Not Enough Memory  (2) 2008.12.08
mkfs - ext2 & ext3  (4) 2008.11.21
SRM - Secure RM  (0) 2008.11.10
Posted by 구차니
Programming/C Win32 MFC2008. 10. 29. 15:24
굳이 c언어에서 파일의 길이를 알아내려면

  fseek(file,0,SEEK_END);
  len = ftell(file);
  rewind(file);

명령어의 조합으로 알아 낼수 있지만.. 느린거 같기도 하고. 그래서 다른 방법을 찾아 보았더니
linux에서는 stat 라는 함수가 있는데, 이것을 이용하면 파일의 상태를 얻어 올 수 있다.

char filename[];
struct stat statinfo;
stat(filename, &statinfo);
len = statinfo.st_size;

그리고 fstat로도 해봤는데
fp = fopen();
fstat(fp,&statinfo);
으로는 안되었다. 아무래도 타입이 다르거나 아니면 FILE 구조체의 다른 변수를 사용해야 할듯 하다.
이미 열어 놓은 파일이라면 fstat로 하는게 훨씬 빠르게 작동이 가능할 듯 하다.


#include <
sys/stat.h>

int stat(const char *path, struct stat *buf);
int fstat(int filedes, struct stat *buf);
int lstat(const char *path, struct stat *buf);

struct stat {
    dev_t     st_dev;     /* ID of device containing file */
    ino_t     st_ino;     /* inode number */
    mode_t    st_mode;    /* protection */
    nlink_t   st_nlink;   /* number of hard links */
    uid_t     st_uid;     /* user ID of owner */
    gid_t     st_gid;     /* group ID of owner */
    dev_t     st_rdev;    /* device ID (if special file) */
    off_t     st_size;    /* total size, in bytes */
    blksize_t st_blksize; /* blocksize for filesystem I/O */
    blkcnt_t  st_blocks;  /* number of blocks allocated */
    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */
};

[출처 : http://linux.die.net/man/2/stat]

 

Posted by 구차니