6

I need to create a file with the following permission

srw-rw-rw- 1 own group 0 Feb  6 22:12 myfile

I know chmod 666 would create the 'rw's, but what command to use to create the first s?

2 Answers 2

7

As vjayalakshmi points out, the first character is the file type (normal, directory, fifo, socket, etc). chmod +s just sets the setuid/setgid bits. These bits imply executability, which is why ls puts the 's' where the 'x' would usually go - it tells you two things with one character (executable, plus set user/group id), giving you the -rwsrwsrw- result you are seeing after trying +s with chmod. IOW, chmod does exactly what it's name implies - it sets the file access modes, which have nothing to do with file type.

Normally, to create a socket you'd want to do it in a program (i.e. use the socket(2) system call).

If you really want to create a socket from the command line (and, of course, depending on what you are trying to do), you can try using the nc command. Also, Tcl has a socket command - see http://www.tcl.tk/man/tcl8.4/TclCmd/socket.htm for more info.

3
  • Yes according to documentation. nc would create a socket file. My machines doesn't have nc. I might need to install nc-1.84-22.el6.x86_64 to get it.
    – johnsam
    Feb 8, 2015 at 18:20
  • nc is also called netcat
    – bitinerant
    Dec 15, 2018 at 13:52
  • How to set permissions srw-rw-rw- using chmod(<digit><digit><digit>) ? Sep 25, 2020 at 23:49
4

The first bit in the file permission is about the file type. The file that you are creating should be of entry type socket to have that s character in the first bit. Refer this link http://www.cyberciti.biz/faq/explain-the-nine-permissions-bits-on-files/

The Entry Type

There are total 10 bits -rw-r--r--: The file mode printed under the -l option consists of the entry type (1st bit) and the permissions (9 bits). The entry type character describes the type of file, as follows:

  • Regular file. b Block special file (stored in /dev). c Character special file (stored in /dev). d Directory. l Symbolic link. p FIFO. s Socket. w Whiteout.
1
  • Yes. I think It is a Unix Domain Socket.
    – johnsam
    Feb 7, 2015 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.