File System
October 16, 2019 · View on GitHub
File System
In this section we will dive into the basics of Unix based file systems. Particularly, you will discover notions of file descriptors, users / groups access permissions, special files etc.
Theory
- Read about typical file system structure in Unix Systems
- Discover unix file permissions and access modes
- :vertical_traffic_light:Node.js:vertical_traffic_light: Node.js File System
- :vertical_traffic_light:Golang:vertical_traffic_light: Working with Files in Go
- :vertical_traffic_light:Python:vertical_traffic_light: Working With Files in Python
Practical Task
- Create folder called
file_systemfolder in yourkottans-backendrepo - In
file_systemfolder:- create file called
secret.txt - grant read-write-execute permissions to owned user, read-only permission to owned group and no permissions to other users for file
secret.txt. Permission indicator for this file should be:-rwxr----- - commit and push your changes to remote
- create file called
- :vertical_traffic_light:Node.js:vertical_traffic_light: In your
file_systemfolder create filefile_system_task.js. In this file, implement a program with the following behavior:- Upon run (with
node file_system_task.js), program checks whether or not filecounter.txtexists. - If its not. Program creates new file
counter.txtwith write/read/execute access to all users. Then it writes single digit1into the file, closes it and exits with status code 0 (normal exit). - If it does exist. Program opens the file
counter.txt, reads its content and checks whether or not all the content of the file is valid integer. If it's valid integer, program increments counter by one, writes new digit into the file (replaces previous one), closes the file and exits with status code 0 (normal exit). If its not valid immediately exists with status code 1 (abnormal exit).
- Upon run (with
- :vertical_traffic_light:Golang:vertical_traffic_light: In your
file_systemfolder create filefile_system_task.go. Within this file, implement program with the following behavior:- Upon run (with
go run file_system_task.go, consider that yourfile_system_task.goshould havemainfunction to be executable), program checks whether or not filecounter.txtexists. - If its not. Program creates new file
counter.txtwith write/read/execute access to all users. Writes single digit1into the file, closes it and exits with status code 0 (normal exit). - If it does exist. Program opens the file
counter.txt, reads its content and checks whether or not all the content of the file is valid integer. If it's valid integer, program increments counter by one, writes new digit into the file (replaces previous one), closes the file and exits with status code 0 (normal exit). If its not valid immediately exists with status code 1 (abnormal exit).
- Upon run (with
- :vertical_traffic_light:Python:vertical_traffic_light: In your
file_systemfolder create filefile_system_task.py. Within this file, implement program with the following behavior:- Upon run (with
python3 file_system_task.py), program checks whether or not filecounter.txtexists. - If its not. Program creates new file
counter.txtwith write/read/execute access to all users. Writes single digit1into the file, closes it and exits with status code 0 (normal exit). - If it does exist. Program opens the file
counter.txt, reads its content and checks whether or not all the content of the file is valid integer. If it's valid integer, program increments counter by one, writes new digit into the file (replaces previous one), closes the file and exits with status code 0 (normal exit). If its not valid immediately exists with status code 1 (abnormal exit).
- Upon run (with
- In your
kottans-backendrepoREADME.md:- add header
## File System - embed the links to your
secret.txtfile andfile_system_tasksource code file.
- add header
- You did lot already! If you honestly finished all the previous steps then go ahead
and share it with others –
post a message in course channel:
File System — #doneand add the link to your repo. This step is important, as it helps mentors to track your progress!
Extra materials
- :vertical_traffic_light:Node.js:vertical_traffic_light: Node.js docs on
fsmodule - :vertical_traffic_light:Golang:vertical_traffic_light: Reading files in various use cases. Golang tutorial series. No. 35.
- :vertical_traffic_light:Node.js:vertical_traffic_light: Руководство по Node.js, часть 9: работа с файловой системой
- :vertical_traffic_light:Python:vertical_traffic_light: Awesome
pathlibpackage
Done?
➡️ Go forward to Runtime, Ecosystem and I/O
⤴️ Back to Contents