Directory contains all files (special files and ordinary files) and sub directories. UNIX uses hierarchical structure for organizing files and directories. The root directory is /(slash), and all other directories contained in it. The directory which you are working at present is called home directory.
The following are the various system calls that are used in directory operations in UNIX.
int mkdir(char *path, mode_t mode);
int creat(chat *path,mode_t mode);
int link(char *path,char *path2);
int unlink(char * path);
int rmdir(char *path);
int chdir(char *path);
char *getcwd(char *path);
DIR *opendir(char *path);
int closedir(DIR *dirp);
mkdir
This creates a new directory with no initial contents. It returns -1 on failure.
creat
This creates a new file, using a new inode. It also creates a new entry in the directory.
link
Link adds another name to an existing file.The link count in the inode is incremented. link does not make a new directory entry.
unlink
unlink system call is used to remove an entry from a directory. The link count in the inode is decreased.
chdir
This syste call is used to change the current directory.
getcwd:
|This system call is used to retrieve the string which contains the path of presenting working directory.
rmdir
This will remove the directory. But before deleting the directory make sure that the directory is empty i.e., remove all the files in the directory first then delete the directory.
(to be continued)
Tq
ReplyDelete