Search⌘ K
AI Features

Exercise: Writing a Bash Script

Explore how to write a Bash script that searches for TXT files in the current directory and either copies or moves them to your home directory based on the given parameter. This lesson guides you through using the find command with options to limit recursive search and handle default actions in scripts.

We'll cover the following...

Exercise

Write a script that searches for files with the TXT extension in the current directory. The script ignores subdirectories. Copy or move all found files to the home directory.

When you call the script, you can choose whether to copy or move the files. If you do not specify the action, the script copies the files.

# Write your script here

Solution

The find utility searches for files recursively. It starts from the specified path and passes ...