Task 04 — Rename *.txt to *.md
Write a script 04.sh that recursively renames every file whose name ends in .txt so it ends in .md instead. Other files and the directory layout stay unchanged.
Submit as
04.sh
Input
| Source | Format |
|---|---|
| CLI | ./04.sh <dir> — root directory to process |
| Filesystem | Tree under <dir>. Only regular files whose basename ends with .txt are renamed (suffix .txt → .md). Files like intro.bak, readme.md, image.png are untouched. |
Output
| Stream | Format |
|---|---|
| stdout | Not checked (usually empty) |
| stderr | Not checked |
| Exit code | 0 on success |
| Side effect | Renames on disk only. Example: docs/readme.txt → docs/readme.md. No .txt files remain under <dir>. |
Example
Before:
docs/
├── readme.txt
├── notes/
│ ├── intro.txt
│ └── intro.bak
└── sub/
└── spec.txt
./04.sh docs
After:
docs/
├── readme.md
├── notes/
│ ├── intro.md
│ └── intro.bak
└── sub/
└── spec.md
What the grader checks
- Exit code
0 - Zero files matching
*.txtunder the tree - Expected
.mdfiles exist at the renamed paths - Non-
.txtfiles (e.g..bak,.png) still present
Hints
find … -name '*.txt'${name%.txt}.md— safe rename; handle spaces withfind -print0