SlideShare uma empresa Scribd logo
1 de 13
System Callmkdir NAME mkdir - create a directory SYNOPSIS        #include <sys/stat.h>        #include <sys/types.h> intmkdir(const char *pathname, mode_t mode); DESCRIPTION mkdir() attempts to create a directory named pathname. RETURN VALUE        On  success,  zero is returned.  On error, -1 is returned, and errno is set appropriately
System Call rmdir NAME rmdir - delete a directory SYNOPSIS        #include <unistd.h> intrmdir(const char *pathname); DESCRIPTION rmdir() deletes a directory, which must be empty. RETURN VALUE        On  success,  zero is returned.  On error, -1 is returned, and errno is set appropriately.
System Call unlink NAME        unlink - delete a name and possibly the file it refers to SYNOPSIS        #include <unistd.h> int unlink(const char *pathname); DESCRIPTION        unlink()  deletes  a  name  from the file system.  If that name was the        last link to a file and no processes have the file  open  the  file  is        deleted and the space it was using is made available for reuse.        If  the  name  was the last link to a file but any processes still have        the file open the file will remain in existence  until  the  last  file        descriptor referring to it is closed. 	If the name referred to a symbolic link the link is removed. RETURN VALUE        On  success,  zero is returned.  On error, -1 is returned, and errno is        set appropriately.
System Calllink NAME        link - make a new name for a file SYNOPSIS        #include <unistd.h> int link(const char *oldpath, const char *newpath); DESCRIPTION        link()  creates  a  new link (also known as a hard link) to an existing        file.        If newpath exists it will not be overwritten.        This new name may be used exactly as the old  one  for  any  operation;        both names refer to the same file (and so have the same permissions and        ownership) and it is impossible to tell which name was the  "original". RETURN VALUE        On  success,  zero is returned.  On error, -1 is returned, and errno is        set appropriately.
System Callrename NAME        rename - change the name or location of a file SYNOPSIS        #include <stdio.h> int rename(const char *oldpath, const char *newpath); DESCRIPTION        rename()  renames  a  file,  moving it between directories if required.        Any other hard links to the file (as created using link(2))  are  unaf- fected.  Open file descriptors for oldpath are also unaffected. 	If  newpath already exists it will be atomically replaced (subject to a        few conditions; see ERRORS below), so that there is no point  at  which        another process attempting to access newpath will find it missing. RETURN VALUE        On success, zero is returned.  On error, -1 is returned, and  errno  is        set appropriately.
System Callchdir NAME chdir, fchdir - change working directory SYNOPSIS        #include <unistd.h> intchdir(const char *path); intfchdir(intfd); DESCRIPTION chdir()  changes  the  current working directory of the calling process to        the directory specified in path. fchdir() is identical to chdir(); the only difference is that  the  directory is given as an open file descriptor. RETURN VALUE        On  success, zero is returned.  On error, -1 is returned, and errno is set        appropriately.
What is current directory? Each running program on Unix has a current directory of the process.  Internally, the process keeps a variable that store the inode number of the current directory.  Change to a new directory is to change the value of that variable
Algorithm of pwd Note the inode number for “.” call it n chdir .. (use chdir) Find the name of the link with inoden (use opendir, readdir, closedir) 	repeat (until reach the top of the tree) Note: In the root directory, “.” and “..” point to the same inode
Homework Write a program which receives a filename and return its inode number. ,[object Object]

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Linux intro 4 awk + makefile
Linux intro 4  awk + makefileLinux intro 4  awk + makefile
Linux intro 4 awk + makefile
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
 
UNIX Command Cheat Sheets
UNIX Command Cheat SheetsUNIX Command Cheat Sheets
UNIX Command Cheat Sheets
 
Linux commands
Linux commandsLinux commands
Linux commands
 
To Get To The Command Prompt In Windows Xp Go To
To Get To The Command Prompt In Windows Xp Go ToTo Get To The Command Prompt In Windows Xp Go To
To Get To The Command Prompt In Windows Xp Go To
 
Linux intro 5 extra: makefiles
Linux intro 5 extra: makefilesLinux intro 5 extra: makefiles
Linux intro 5 extra: makefiles
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Basic commands
Basic commandsBasic commands
Basic commands
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
Linux intro 3 grep + Unix piping
Linux intro 3 grep + Unix pipingLinux intro 3 grep + Unix piping
Linux intro 3 grep + Unix piping
 
Linux commands part -2
Linux commands part -2Linux commands part -2
Linux commands part -2
 
Introduction to linux day-3
Introduction to linux day-3Introduction to linux day-3
Introduction to linux day-3
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
Linux intro 2 basic terminal
Linux intro 2   basic terminalLinux intro 2   basic terminal
Linux intro 2 basic terminal
 
File management
File managementFile management
File management
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Unix slideshare
Unix slideshareUnix slideshare
Unix slideshare
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
11 unix osx_commands
11 unix osx_commands11 unix osx_commands
11 unix osx_commands
 

Destaque

Chapter 3
Chapter 3Chapter 3
Chapter 3lopjuan
 
Java servlets
Java servletsJava servlets
Java servletslopjuan
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 

Destaque (6)

Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Java servlets
Java servletsJava servlets
Java servlets
 
Core java course syllabus
Core java course syllabusCore java course syllabus
Core java course syllabus
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

Semelhante a Chapter 4 2

WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHBhavsingh Maloth
 
Linux_Commands.pdf
Linux_Commands.pdfLinux_Commands.pdf
Linux_Commands.pdfMarsMox
 
intro unix/linux 07
intro unix/linux 07intro unix/linux 07
intro unix/linux 07duquoi
 
Introduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examplesIntroduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examplesNoé Fernández-Pozo
 
SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1solgenomics
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line conceptsArtem Nagornyi
 
Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja Ranjan Raja
 
18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptxChenamPawan
 
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docxajoy21
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Wave Digitech
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdffedosys
 

Semelhante a Chapter 4 2 (20)

WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Unix3
Unix3Unix3
Unix3
 
Unix-module3.pptx
Unix-module3.pptxUnix-module3.pptx
Unix-module3.pptx
 
Linux cheat sheet
Linux cheat sheetLinux cheat sheet
Linux cheat sheet
 
Linux_Commands.pdf
Linux_Commands.pdfLinux_Commands.pdf
Linux_Commands.pdf
 
intro unix/linux 07
intro unix/linux 07intro unix/linux 07
intro unix/linux 07
 
Introduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examplesIntroduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examples
 
SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1
 
Directories description
Directories descriptionDirectories description
Directories description
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja
 
58518522 study-aix
58518522 study-aix58518522 study-aix
58518522 study-aix
 
18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx
 
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Unix1
Unix1Unix1
Unix1
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdf
 

Mais de lopjuan

Chapter 2
Chapter 2Chapter 2
Chapter 2lopjuan
 
Chapter 1
Chapter 1Chapter 1
Chapter 1lopjuan
 
Chapter 4 1
Chapter 4 1Chapter 4 1
Chapter 4 1lopjuan
 
Java applets
Java appletsJava applets
Java appletslopjuan
 
Chapter10
Chapter10Chapter10
Chapter10lopjuan
 
Web services
Web servicesWeb services
Web serviceslopjuan
 
Chapter7
Chapter7Chapter7
Chapter7lopjuan
 

Mais de lopjuan (7)

Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Chapter 4 1
Chapter 4 1Chapter 4 1
Chapter 4 1
 
Java applets
Java appletsJava applets
Java applets
 
Chapter10
Chapter10Chapter10
Chapter10
 
Web services
Web servicesWeb services
Web services
 
Chapter7
Chapter7Chapter7
Chapter7
 

Chapter 4 2

  • 1.
  • 2.
  • 3. System Callmkdir NAME mkdir - create a directory SYNOPSIS #include <sys/stat.h> #include <sys/types.h> intmkdir(const char *pathname, mode_t mode); DESCRIPTION mkdir() attempts to create a directory named pathname. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately
  • 4. System Call rmdir NAME rmdir - delete a directory SYNOPSIS #include <unistd.h> intrmdir(const char *pathname); DESCRIPTION rmdir() deletes a directory, which must be empty. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
  • 5. System Call unlink NAME unlink - delete a name and possibly the file it refers to SYNOPSIS #include <unistd.h> int unlink(const char *pathname); DESCRIPTION unlink() deletes a name from the file system. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse. If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed. If the name referred to a symbolic link the link is removed. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
  • 6. System Calllink NAME link - make a new name for a file SYNOPSIS #include <unistd.h> int link(const char *oldpath, const char *newpath); DESCRIPTION link() creates a new link (also known as a hard link) to an existing file. If newpath exists it will not be overwritten. This new name may be used exactly as the old one for any operation; both names refer to the same file (and so have the same permissions and ownership) and it is impossible to tell which name was the "original". RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
  • 7. System Callrename NAME rename - change the name or location of a file SYNOPSIS #include <stdio.h> int rename(const char *oldpath, const char *newpath); DESCRIPTION rename() renames a file, moving it between directories if required. Any other hard links to the file (as created using link(2)) are unaf- fected. Open file descriptors for oldpath are also unaffected. If newpath already exists it will be atomically replaced (subject to a few conditions; see ERRORS below), so that there is no point at which another process attempting to access newpath will find it missing. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
  • 8. System Callchdir NAME chdir, fchdir - change working directory SYNOPSIS #include <unistd.h> intchdir(const char *path); intfchdir(intfd); DESCRIPTION chdir() changes the current working directory of the calling process to the directory specified in path. fchdir() is identical to chdir(); the only difference is that the directory is given as an open file descriptor. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
  • 9. What is current directory? Each running program on Unix has a current directory of the process. Internally, the process keeps a variable that store the inode number of the current directory. Change to a new directory is to change the value of that variable
  • 10.
  • 11.
  • 12. Algorithm of pwd Note the inode number for “.” call it n chdir .. (use chdir) Find the name of the link with inoden (use opendir, readdir, closedir) repeat (until reach the top of the tree) Note: In the root directory, “.” and “..” point to the same inode
  • 13.
  • 14. This i node number is 1234
  • 15. Read pwd.c on page 13.