UNIX concepts: Difference between revisions

From Elvanör's Technical Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Default group =
= Files =
 
== Hard links, symbolic links ==
 
* A hard link is not the same as a symbolic link, since it is a direct entry into the same file. There is no "original" concept here, there is no directionality as with symlinks. If you move the file, the other files will still exist and point to the unique file on the hard drive.
* To check the hard link count of a file (sometimes useful), just use the standard '''ls -l''' command. The first number (after the file mask) represents the hard link count.
 
== Permissions ==


* You can change the default active group of your user via the newgrp command. This will open a new shell so is not always convenient. This is why using sudo is sometimes mandatory when you want to run a command as an user with a different group.
* When you use chmod, be careful that a means all, o means others and u means user. '''o does not mean owner.'''
* sg allows you to do like newgrp but with a single command that will be ran as a different active group. '''UPDATE:''' this command is apparently not standard. On Gentoo it is a simple symlink to newgrp.


= setgid =
== setgid ==


* Any file created in a directory with this flag set will be created with the group of the directory, not the usual normal group.
* Any file created in a directory with this flag set will be created with the group of the directory, not the usual normal group.


= umask =
== umask ==


* The default umask is the default set of permissions that files your current user will create will get. You can set it via the umask command (running this command without arguments gives you the current umask).
* The default umask is the default set of permissions that files your current user will create will get. You can set it via the umask command (running this command without arguments gives you the current umask).
* Note that the default umask (as well as the active group) is an environment setting. It is inherited by the parent process that spawned the current process.
* Note that the default umask (as well as the active group) is an environment setting. It is inherited by the parent process that spawned the current process.
* Obtaining the umask of a running process (not current one) [http://stackoverflow.com/questions/165212/linux-getting-umask-of-an-already-running-process can be done with gdb.] The returned value is in decimal (eg, 18 in decimal = 22 in octal).


= .a, .so, and .la files =
== .a, .so, and .la files ==


* Shared library are .so files; they dynamically link to other libraries if needed. I think .a files are libraries that do not link to other libraries (eg, statically compiled).
* Shared library are .so files; they dynamically link to other libraries if needed. I think .a files are libraries that do not link to other libraries (eg, statically compiled).
* .la files are just header files needed for gcc to compile against a .a file. These files are just plain text files that do not contain any code. In Gentoo those files should be avoided (if possible, all libraries should be compiled as .so files).
* .la files are just header files needed for gcc to compile against a .a file. These files are just plain text files that do not contain any code. In Gentoo those files should be avoided (if possible, all libraries should be compiled as .so files).


= Sticky bits =
== Sticky bits ==


* If a directory has the sticky bit in its permissions, this means that all its files can be deleted only by their owners.
* If a directory has the sticky bit in its permissions, this means that all its files can be deleted only by their owners.
Line 28: Line 35:


* The PIDs are generated by the Linux kernel; job ids are something related to bash (small integers identifying processes running). For instance pressing control+Z will show you a job id.
* The PIDs are generated by the Linux kernel; job ids are something related to bash (small integers identifying processes running). For instance pressing control+Z will show you a job id.
= Default group =
* You can change the default active group of your user via the newgrp command. This will open a new shell so is not always convenient. This is why using sudo is sometimes mandatory when you want to run a command as an user with a different group.
* sg allows you to do like newgrp but with a single command that will be ran as a different active group. '''UPDATE:''' this command is apparently not standard. On Gentoo it is a simple symlink to newgrp.


= Disown =
= Disown =

Latest revision as of 12:35, 14 January 2021

Files

Hard links, symbolic links

  • A hard link is not the same as a symbolic link, since it is a direct entry into the same file. There is no "original" concept here, there is no directionality as with symlinks. If you move the file, the other files will still exist and point to the unique file on the hard drive.
  • To check the hard link count of a file (sometimes useful), just use the standard ls -l command. The first number (after the file mask) represents the hard link count.

Permissions

  • When you use chmod, be careful that a means all, o means others and u means user. o does not mean owner.

setgid

  • Any file created in a directory with this flag set will be created with the group of the directory, not the usual normal group.

umask

  • The default umask is the default set of permissions that files your current user will create will get. You can set it via the umask command (running this command without arguments gives you the current umask).
  • Note that the default umask (as well as the active group) is an environment setting. It is inherited by the parent process that spawned the current process.
  • Obtaining the umask of a running process (not current one) can be done with gdb. The returned value is in decimal (eg, 18 in decimal = 22 in octal).

.a, .so, and .la files

  • Shared library are .so files; they dynamically link to other libraries if needed. I think .a files are libraries that do not link to other libraries (eg, statically compiled).
  • .la files are just header files needed for gcc to compile against a .a file. These files are just plain text files that do not contain any code. In Gentoo those files should be avoided (if possible, all libraries should be compiled as .so files).

Sticky bits

  • If a directory has the sticky bit in its permissions, this means that all its files can be deleted only by their owners.
  • The "/tmp" directory has this sticky bit, this means you cannot delete files in /tmp belonging to another user, even if you are in the same group.

Jobs

PID and Job Ids

  • The PIDs are generated by the Linux kernel; job ids are something related to bash (small integers identifying processes running). For instance pressing control+Z will show you a job id.

Default group

  • You can change the default active group of your user via the newgrp command. This will open a new shell so is not always convenient. This is why using sudo is sometimes mandatory when you want to run a command as an user with a different group.
  • sg allows you to do like newgrp but with a single command that will be ran as a different active group. UPDATE: this command is apparently not standard. On Gentoo it is a simple symlink to newgrp.

Disown

  • You can try to disown a process (which will make it continue running if the parent bash process / shell that launched it is killed) via the disown command (it's a Bash internal command, not a binary). Note however that the process can very well crash if you launched it on a shell since if you disown it its stdout will disappear. It's better to use screen in all cases.
  • You should give the -h option to disown if you want to kill the running shell that launched the process and keep the process running.