When using C to operate Linux directory, encountered a few mkdir small problems, by the way, in the operation of files or directories on Linux, the most likely problems are permission issues, are obvious Mistakes, so these problems are easily exposed and resolved during the development phase. After all, it is not just a Linux platform development, so I will forget it after a few days.
The function prototype of mkdir (includes #include <sys/stat.h>):
int mkdir(const char *path, mode_t mode);
Parameters:
path——directory name, such as abc, /var/www/abc, etc.
mode——directory permissions
Return value:
returns 0 for success, -1 for error, and sets the errno value.
Of course, you can also use macro parameters similar to S_IRWXU, S_IRUSR..., after all, it is difficult to remember, but not as good as the 0421 in octal. The combination style is: owner-group-others, different people are divided into three rules read-write-execute (r-w-x), all licenses are 7.
1. Use mkdir("test",777) when programming.
Try it out:
mkdir("test",0777);
written as mkdir ("test", 777) may not be executed. But vaguely remember, there used to be no mistakes in the previous use of 777, specifically forgot, anyway, it is absolutely correct to write according to the norm.
2, umask command to use
Also assume that your program directory is under /root/abc/, then if your program wants to create a directory under /var/www when executing, there is Maybe you always create a 0777 directory that is always created as a 0755 directory, then try the umask(0) command.
The umask is only valid for the current directory. The default umask value is 0022, so you cannot create a directory of 0777 directly in another location.
It is 0777-0022=0755
3, how to create a user group folder
/etc/passwd and /etc/group to find UID and gid< Br>
mkdir /var/ugroup
We can use chown directly to change the file owner.
chown root:newuser /var/ugroup
Modify permissions
chmod 740 /var/ugroup/*
4, check the permissions of the directory after creation Command:
Locate to the user group directory, execute:
ls -all
will display something like:
drwxrwxr-x
such a result (0775).
There is no new concept in this article. We just use command line tools to repeat what we have done
See many online how to ask how to configure the linux system nat Internet, now write an article here
You can try it, but dont do bad things. Fortunately, I need a password to modify m
Linux supports sharing open files between different processes. To illustrate file sharing, lets firs
VirtualBox installation configuration and new virtual machine
Error:storage class specified for parameter problem
Linux SSHD client Chinese garbled solution
How to fix Linux can not start failure
Single-chip drive LED, digital tube, lcd display
Novice Academy: Ways to Add Linux to Windows Domain
Common anode and common cathode LED driving method
Linux source command and its usage introduction
Basic application tutorial for iptables firewall on Linux
Linux system learning method entry experience
Fedora install virtualbox kernel error
Linux operating system partitioning tool Fdisk tool introduction
Detailed Windows 8 new features! are you ready?
How to add and delete input methods under Win8 system
Win7 system play red alert 2 how to display full screen?
How to disable/disable IE browser function in Win7 system
Eight maintenance knowledge of Windows operating system
How to find out the missing input method icon on the taskbar
Windows Phone 7 players can play online in real time
Is the homepage of Win10 Preview 9860 really hard to use?