AI Hints
Home›Linux Tutorial›Folders and Wildcards
Linux · Lesson 30 of 120

Practice: Tidy Downloads

Wildcards for real.

⏱ 2 min read▶ Video at 37:15🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Let's tidy the messy downloads folder for real, using folders and wildcards. Here's the task. Make three folders, photos, invoices, and notes. Move each kind of file into its folder. Pause and try it first.

Practice: Tidy Downloads
From the video: Practice: Tidy Downloads
  • Tidy the downloads folder
  • photos, invoices, notes
  • Pause and try first

Sorting the files

First, MK dir makes the three folders in one go. Then three MV commands, each with a wildcard. Every JPG goes into photos. Every invoice goes into invoices. We use invoice dash star here, so the pattern can't match the new invoices folder itself. And every notes file goes into notes. Look how much is left. Just two files.

Terminal
mkdir photos invoices notes
mv *.jpg photos
mv invoice-* invoices
mv notes*.txt notes
ls
invoices  notes  photos  setup.deb  song.mp3

Checking the result

Tree shows the result. Each folder holds exactly the files we expected. Eight files sorted, with just four short commands. That's the power of wildcards.

Terminal
tree
.
├── invoices
│   ├── invoice-feb.pdf
│   └── invoice-jan.pdf
├── notes
│   ├── notes1.txt
│   ├── notes10.txt
│   └── notes2.txt
├── photos
│   ├── photo1.jpg
│   ├── photo2.jpg
│   └── photo3.jpg
├── setup.deb
└── song.mp3

4 directories, 10 files

Summary

With MK dir, MV, and wildcards, you tidied a whole folder in seconds. Next, reading the contents of files.

Key takeaways
  • mkdir the folders
  • mv with wildcards
  • tree to check
Next up: cat: Reading Files — printing a file