> For the complete documentation index, see [llms.txt](https://sys.disetti.it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sys.disetti.it/system-administration/linux.md).

# Linux

## Delete file older than 30 days

```
find /path/to/files/ -type f -name '*.jpg' -mtime +30 -exec rm {} \
```

## Order directory by number of files

```
find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
```

## Order directory and files by size recursively

```
du -ah ./ | grep -v "/$" | sort -rh
```

## Lsof sort open file by size

```
lsof -s | awk '$5 == "REG"' | sort -n -r -k 7,7 | head -n 50
```

## List all user’s crontab in bash

```
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done
```

## List directory by inodes usage

```
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
```
