Create directory tree in linux using C plusplus
Example is not correct at all when it handle "status"
it should be:
#include <bits/stdc++.h> #include <iostream> #include <sys/stat.h> #include <sys/types.h> using namespace std; int main() { int status; status = system("mkdir -p TP/My_Folder/test"); // Creating a directory if (status != 0) std::cerr << "Error : " << strerror(errno) << std::endl; else std::cout << "Directories are created" << std::endl; }
What is default permission of command "system("mkdir -p TP/My_Folder/test");"?
The answer is 755 or drwxr-xr-x
What is drwxr-xr-x?
It looks like 4 groups: d rwx r-x r-x
d: directory (file is "-")
rwx: owner can read/write/execute
r-x: group user can read/execute
r-x: other user can read/execute
Bonus: "-" is permission not set
What is "755"
ref: https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/
0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute
Example: Try to create some directories and show default permission by command "ls"
Bonus ++: You may concern about command chmod options as below
Example:
1. Allow one file is run by user(owner)
chmod u+x runablefile.sh
2. Allow full permission with one file for group of user
chmod g+rwx groupfull.txt
The man page of chmod covers that.
u stands for user.
g stands for group.
o stands for others.
a stands for all.
The answer is 755 or drwxr-xr-x
What is drwxr-xr-x?
It looks like 4 groups: d rwx r-x r-x
d: directory (file is "-")
rwx: owner can read/write/execute
r-x: group user can read/execute
r-x: other user can read/execute
Bonus: "-" is permission not set
What is "755"
ref: https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/
0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute
Example: Try to create some directories and show default permission by command "ls"
Bonus ++: You may concern about command chmod options as below
Example:
1. Allow one file is run by user(owner)
chmod u+x runablefile.sh
2. Allow full permission with one file for group of user
chmod g+rwx groupfull.txt
The man page of chmod covers that.
u stands for user.
g stands for group.
o stands for others.
a stands for all.
Comments
Post a Comment