linux - rFronteddu/general_wiki GitHub Wiki
Shell
History
- Ctrl-R to initiate a reverse search
- history -c linux to clear all commands
- history -w linux to write history on file usually ~/.bash_history
Changing permissions
First specify which permission set you want to change (user, group, or other), then use a + to add a permission or a - to remove it.
- u (user/owner)
- g (group)
- o (others)
- a (all: user, group, and others)
Add (+) the execute (x) permission for the user (u) on a file (myfile):
chmod u+x myfile
Remove a permission, use the - operator.
To transfer ownership of a file to a different user/group, use chown/cgrp (change owner/group) command.
sudo chown patty myfile
The Set User/Group ID (SUID/SGID) allows a user/group to run a program as the owner of the program file rather than as themselves (S means same thing without execution right).
sudo chmod u+s myfile
There are three UIDs associated with every process:
- effective user ID - when launched, it runs with the same permissions as the user/group that ran it. If Bob ran the touch command, the process would run as him, and any files he created would be under his ownership.
- real user ID - ID of the user that launched the process. These are used to track down who the user who launched the process is.
- saved user ID - allows a process to switch between the effective UID and real UID, and vice versa. This is useful because we don't want our process to run with elevated privileges all the time; it's just good practice to use special privileges at specific times.
Most of the time, the real UID and the effective UID are the same, but in such cases as the passwd command, they will change.
Beyond the standard read, write, and execute permissions, Linux offers special permissions for advanced access control such as the sticky bit a permission setting that can be applied to a directory. When a directory has the sticky bit set, files within that directory can only be deleted or renamed by the file's owner, the directory's owner, or the root user.
Tar/untar
Archive and compress
tar czvf myarchive.tar.gz file1 file2 directory1
Reverse:
tar xzvf myarchive.tar.gz