ob-vaults/Phoenix/az_system/commands.md
2024-09-12 17:54:01 +03:30

255 lines
4.3 KiB
Markdown

status: #doc
Tags: #linux
links:
Date: 2023-11-07
___
# linux commands
## list
#### list with details
```sh
ls -ltrh
```
## make and destroy
### directory
#### make directory
```sh
mkdir
```
#### delete directory
```sh
rmdir
```
## find command locatiozn
```bash
whereis
```
## zip
### ziping
for 1 file
```zsh
zip zipfilename.zip what_to_zip_file
gzip zipfilename.zip what_to_zip_file
```
for folder
```zsh
zip -r zipfilename.zip what_to_zip_folder
gzip -r zipfilename.zip what_to_zip_folder
```
### unzip
```shell
unzip
gunzip
```
## user mangmet
### user
* see encrypted users password
```sh
cat etc/shadow
```
1. **useradd:**
- Adds a new user to the system.
```bash
sudo useradd username
```
2. **passwd:**
- Changes the password for a user.
```bash
sudo passwd username
```
3. **userdel:**
- Deletes a user account.
```bash
sudo userdel username
```
4. **usermod:**
- Modifies user account properties.
```bash
sudo usermod options username
```
5. **id:**
- Displays user and group information for a specified username.
```bash
id username
```
7. **passwd -e:**
- Expire a user's password immediately, forcing them to change it on the next login.
```bash
sudo passwd -e username
```
### usermod options
Certainly! Here's the text with the content changed to a numbered list:
1. **Changing the Username:**
```bash
sudo usermod -l newusername oldusername
```
2. **Changing the User ID (UID):**
```bash
sudo usermod -u newuid username
```
3. **Changing the Home Directory:**
```bash
sudo usermod -d /new/home/directory username
```
4. **Changing the Default Shell:**
```bash
sudo usermod -s /path/to/new/shell username
```
5. **Adding a Supplementary Group:**
```bash
sudo usermod -aG newgroup username
```
6. **Locking/Unlocking an Account:**
```bash
sudo usermod -L username # Lock the account
sudo usermod -U username # Unlock the account
```
7. **Expiring a User Account:**
```bash
sudo usermod -e YYYY-MM-DD username
```
8. **Forcing Password Change on Next Login:**
```bash
sudo usermod -e 1 username
```
9. **see expire date of user and password:**
```bash
sudo usermod -l newusername
```
### groups
Here are some common commands related to managing user groups in Linux:
1. **groupadd:**
- Adds a new group to the system.
```bash
sudo groupadd groupname
```
2. **groupdel:**
- Deletes a group from the system.
```bash
sudo groupdel groupname
```
3. **groupmod:**
- Modifies group properties.
```bash
sudo groupmod options groupname
```
4. **gpasswd:**
- Adds or removes users from a group.
```bash
sudo gpasswd -a username groupname # Add user to group
sudo gpasswd -d username groupname # Remove user from group
```
5. **groups:**
- Displays the groups a user belongs to.
```bash
groups username
```
6. **newgrp:**
- Switches the primary group.
```bash
newgrp groupname
```
7. **getent group:**
- Displays information about groups from the system databases and Name Service Switch sources.
```bash
getent group
```
### file
Managing file ownership and permissions is an important aspect of user management in Linux. Here are some commands related to user management for files:
1. **chown:**
- Changes the owner of a file.
```bash
sudo chown username:groupname file
```
2. **chgrp:**
- Changes the group ownership of a file.
```bash
sudo chgrp groupname file
```
3. **chmod:**
- Changes the permissions of a file.
```bash
sudo chmod permissions file
```
The `permissions` can be represented in octal or symbolic notation. For example:
```bash
sudo chmod 755 file # Give read, write, and execute to owner; read and execute to group and others
```
4. **ls:**
- Lists files and their permissions.
```bash
ls -l file
```
Example output:
```
-rwxr-xr-x 1 username groupname 1234 Nov 21 12:34 file
```
The first field represents the file type and permissions.
5. **umask:**
- Sets the default permissions for newly created files.
```bash
umask 022
```
This example sets the default permissions to `rw-r--r--` for newly created files.
---
# References