UNIXC001 檔案操作 之 檔案管理案例

2021-10-11 21:15:47 字數 3176 閱讀 7344

t_file.h

#ifndef t_file_h

#define t_file_h

#include

#include

#include

#include

#endif

t_stdio.h

#ifndef t_stdio_h_

#define t_stdio_h_

#include

#define e_msg(string, val) dowhile(0)

#endif

sudo

cp t_file.h t_stdio.h /usr/include/

r_file.c

// #include 

// #include

// #include

// #include

#include

#include

intmain

(int argc,

char

* ar**)

$ ls -l *

-rw-rw-r-- 1 moonx moonx 0 12月 10 20:01 tt

-rw-r--r-- 1 moonx moonx 0 12月 10 20:07 tx

--w--w--w- 1 moonx moonx 0 12月 11 16:02 ty

$ gcc r_file.c

$ a.out tt

file

open success... tt

$ a.out tx

file

open success... tx

$ a.out ty

open: permission denied

$ a.out t1

open: no such file or directory

wt_file.c

#include

#include

intmain

(int argc,

char

* ar**)

$ gcc wt_file.c 

$ ./a.out hello

file

open success... hello

$ ls hello -l

-rw-r--r-- 1 moonx moonx 0 12月 11 16:46 hello

$ echo 111 > hello

$ ./a.out hello

file

open success... hello

$ cat hello

we_file.c

#include

#include

intmain

(int argc,

char

* ar**)

$ gcc we_file.c 

$ a.out hello

open: file exists

$ rm hello

$ a.out hello

file

open success... hello

$ ls hello

hello

$ ls -l hello

-rw-r--r-- 1 moonx moonx 0 12月 11 17:48 hello

//將原始檔中的內容複製到目標檔案當中

//函式的返回值表示實際拷貝的位元組數

intcp_file

(int s_fd,

int d_fd)

}return total;

}// ar**[1]表示原始檔的名字, ar**[2]表示目標檔案的名字

// 重定向檔名通過ar**[1]

intmain

(int argc,

char

*ar**)

moonx@moonx:

~/desktop/c/c++$ gcc direct.c

moonx@moonx:

~/desktop/c/c++$ .

/a.out 11

this is a test...

moonx@moonx:

~/desktop/c/c++$ cat 11

this is a test.

..

UNIXC001 資料夾操作

drwxrwxr x 2 moonx moonx 4096 12月 26 09 12 test 資料夾裡x代表可通過的意思 chmod a x test cd test bash cd test permission denied chmod a x test cd test touch filea...

2 檔案 檔案操作

def fileno self,args,kwargs real signature unknown 返回檔案控制代碼在核心中的索引值,以後做io多路復用時可以用到 def flush self,args,kwargs real signature unknown 把檔案從記憶體buffer裡強制重...

1 檔案測試 2 檔案操作

1 檔案測試函式 2 檔案操作 新建檔案 fopen filename,w 以 寫 的方式開啟乙個不存在的檔案,就會新建該檔案 檔案刪除 unlink 檔案複製 copy filename,aaa bb.txt 盡量使用 和相對路徑,因為linux只認 也沒有磁碟分割槽,而windows 和 都認 ...