# Finding Files & Archives (find, tar) — Linux Command Line Fundamentals

Source: https://www.geekswithgeeks.com/en/linux/linux-find-tar

> Locate files by name, size and age with find, and bundle or extract archives with tar and gzip.

## find

`find` walks a directory tree and filters by name, type, size or age.

```bash
find . -name "*.log"            # by name
find /var -type f -size +100M    # large files
find . -mtime -1                 # modified in last day
find . -name "*.tmp" -delete     # act on matches
```

## tar

`tar` bundles files into one archive; `-z` adds gzip compression. Remember: c create, x extract, t list, f file.

```bash
tar -czf backup.tar.gz projects/     # create
tar -tzf backup.tar.gz               # list
tar -xzf backup.tar.gz -C /tmp       # extract
```

Run `find` with `-print` first and only add `-delete` or `-exec` once the matches look right.

Quick check

**Quiz:** Which command extracts backup.tar.gz?

- [x] tar -xzf backup.tar.gz
- [ ] tar -czf backup.tar.gz
- [ ] tar -tzf backup.tar.gz
- [ ] gzip -c backup.tar.gz

*Answer:* tar -xzf backup.tar.gz. `x` extracts, `z` handles gzip and `f` names the file.
