Marvel-Themed Linux touch Practices: 10 Exercises
Practice 1: Creating a Single File
Objective: Learn to use the touch command to create a file.
Instructions:
1. Open your Linux terminal.
2. Navigate to the Marvel directory using cd Marvel.
3. Create a file named Avengers.txt by typing touch Avengers.txt.
4. Use ls to confirm the file has been created.
Practice 2: Creating Multiple Files
Objective: Use touch to create multiple files at once.
Instructions:
1. Inside the Marvel directory, type:
touch IronMan.txt Thor.txt Hulk.txt.
2. Use ls to list the files and verify their creation.
3. Think of these as assembling the team’s profiles.
Practice 3: Updating Timestamps
Objective: Use touch to update the modification time of an existing file.
Instructions:
1. Inside the Marvel directory, create a file: touch InfinityGauntlet.txt.
2. View the file's timestamp using ls -l InfinityGauntlet.txt.
3. Wait a few minutes, then run touch InfinityGauntlet.txt again.
4. Check the timestamp to see it updated.
Practice 4: Using touch with Nonexistent Directories
Objective: Understand what happens when trying to create files in nonexistent
directories.
Instructions:
1. Inside the Marvel directory, type:
touch Villains/Thanos.txt (the Villains directory does not exist).
2. Observe the error message.
3. Create the Villains directory with mkdir Villains and retry the command.
Practice 5: Creating Hidden Files
Objective: Use touch to create hidden files.
Instructions:
1. Inside the Marvel directory, create a hidden file:
touch .ShieldSecrets.txt.
2. Use ls to list files (note that the hidden file does not appear).
3. Use ls -a to display the hidden file.
Practice 6: Simulating Mission Logs
Objective: Create timestamped mission log files.
Instructions:
1. Inside the Marvel directory, create a log file:
touch "MissionLog-$(date +%Y-%m-%d).txt".
2. Use ls to verify the log file's name includes today’s date.
3. Create another log file for yesterday by specifying the date:
touch "MissionLog-$(date -d 'yesterday' +%Y-%m-%d).txt".
Practice 7: Creating Files in Nested Directories
Objective: Use touch to create files in nested directories.
Instructions:
1. Inside the Marvel directory, create a nested directory structure:
mkdir -p Phase1/IronMan.
2. Create a file inside the nested directory:
touch Phase1/IronMan/TechSpecs.txt.
3. Use ls Phase1/IronMan to verify the file creation.
Practice 8: Using touch with Specific Permissions
Objective: Understand file permissions when using touch.
Instructions:
1. Inside the Marvel directory, create a file:
touch WakandaSecrets.txt.
2. View the file’s permissions with ls -l WakandaSecrets.txt.
3. Change the permissions using chmod 600 WakandaSecrets.txt.
4. Verify the changes with ls -l WakandaSecrets.txt.
Practice 9: Testing touch with Nonexistent Files
Objective: Verify the behavior of touch when files already exist.
Instructions:
1. Inside the Marvel directory, create a file:
touch StarkIndustries.txt.
2. Run touch StarkIndustries.txt again.
3. Verify that the file’s content remains unchanged but its timestamp updates.
Practice 10: Combining touch with Other Commands
Objective: Use touch in combination with other commands for automation.
Instructions:
1. Inside the Marvel directory, create a file:
touch AvengersInitiative.txt.
2. Write a message into the file:
echo "New recruits needed" > AvengersInitiative.txt.
3. Use cat to display the file’s contents: cat AvengersInitiative.txt.