# Pacman Cheatsheet
## Metadata
**Status**:: #x
**Zettel**:: #zettel/fleeting
**Created**:: [[2025-06-27]]
## Package Search
### Search Repositories
```bash
# Search for package in repositories (-s)
pacman -Ss search_term
# Search for installed packages (-s)
pacman -Qs search_term
# Show detailed info about a package (-i)
pacman -Si package_name
```
### Search Files
```bash
# List files owned by a package (-l)
pacman -Ql package_name
# Find which package owns a file (-o)
pacman -Qo /path/to/file
```
### Using pkgfile
```bash
# Install pkgfile (if not installed)
sudo pacman -S pkgfile
# Update pkgfile database
sudo pkgfile -u
# Search for package containing a file
pkgfile filename
# Search with regex
pkgfile -r 'regex_pattern'
```
## Package Management
### Remove Packages
```bash
# Remove package and its dependencies (-s) without saving configs (-n)
sudo pacman -Rsn package_name
# Remove package, its dependencies (-s), and all packages depending on it (-c) without saving configs (-n)
sudo pacman -Rscn package_name
```
### Cleanup Orphans
```bash
# Remove all orphaned packages (installed as dependencies but no longer needed)
sudo pacman -Rsn $(pacman -Qtdq)
```
## System Maintenance
### Update System
```bash
# Force refresh package databases (-Syy) then perform full system upgrade (-uu)
sudo pacman -Syyuu
```
### Clean Cache
```bash
# Clear all cached packages (-Scc)
sudo pacman -Scc
```
## Troubleshooting
### Remove Database Lock
```bash
# Remove pacman database lock file (use when pacman is stuck)
sudo rm /var/lib/pacman/db.lck
```