Skip to main content

Practice task

6.1 Task Overview​

Now that you've learned the basics, complete this comprehensive task that combines all the skills you've practiced. This task will test your ability to navigate directories, manage files, create scripts, and handle permissions.

6.2 Task Requirements​

Starting location: Your home directory

Complete the following tasks in order:

  1. Setup Phase:

    • Create a new directory called assessment_task
    • Inside it, create three subdirectories: data, scripts, and output
    • Navigate to the data directory
  2. File Management Phase:

    • Create a text file called student_info.txt containing your name and course
    • Copy this file to create student_backup.txt
    • Move student_backup.txt to the output directory
    • Create another file called notes.txt with any content you like
  3. Scripting Phase:

    • Navigate to the scripts directory
    • Create a script called file_manager.sh that:
      • Displays the current date and time
      • Shows the current working directory
      • Lists all files in the parent data directory
      • Asks the user for their favorite programming language
      • Creates a file in the output directory named after their response (e.g., python.txt)
    • Make the script executable
    • Run the script and test it works
  4. Permissions Phase:

    • Create a file called restricted.txt in the data directory
    • Set its permissions to 600 (owner read/write only)
    • Verify the permissions are set correctly
  5. Final Verification:

    • Navigate back to assessment_task root directory
    • List the contents of all subdirectories to verify your work
    • Create a final script called cleanup_check.sh in the scripts directory that displays a summary of all files and directories you've created

6.3 Expected Directory Structure​

When complete, your directory structure should look like this:

~/assessment_task/
├── data/
│ ├── student_info.txt
│ ├── notes.txt
│ └── restricted.txt (permissions: 600)
├── scripts/
│ ├── file_manager.sh (executable)
│ └── cleanup_check.sh
└── output/
├── student_backup.txt
└── [language].txt (created by your script)

6.4 Sample Solution​

Below is the complete sequence of commands to accomplish this task:

Click here to view the sample solution for Setup Phase
# Setup Phase
cd ~
mkdir assessment_task
cd assessment_task
mkdir data scripts output
cd data
Click here to view the sample solution for File Management Phase
# File Management Phase
echo "Student Name: [Your Name]
Course: [Your Course]" > student_info.txt
cp student_info.txt student_backup.txt
mv student_backup.txt ../output/
echo "These are my notes for the Linux tutorial." > notes.txt
Click here to view the sample solution for Scripting Phase
# Scripting Phase
cd ../scripts
cat > file_manager.sh << 'EOF'
#!/bin/bash
# File Manager Script
# This script demonstrates file operations and user interaction

echo "=== File Manager Script ==="

# Display current date and time
echo "Current date and time: $(date)"

# Show current working directory
echo "Current directory: $(pwd)"

# List files in the parent data directory
echo "Files in data directory:"
ls -la ../data/

# Ask user for favorite programming language
echo "What is your favorite programming language?"
read fav_language

# Create file in output directory named after their response
echo "You chose: $fav_language" > "../output/${fav_language}.txt"
echo "Created file: ${fav_language}.txt in output directory"

echo "=== Script completed ==="
EOF

chmod +x file_manager.sh
./file_manager.sh
Click here to view the sample solution for Permissions Phase
# Permissions Phase
cd ../data
touch restricted.txt
chmod 600 restricted.txt
ls -l restricted.txt
Click here to view the sample solution for Final Verification
# Final Verification
cd ..
echo "=== Directory Contents ==="
echo "Data directory:"
ls -la data/
echo "Scripts directory:"
ls -la scripts/
echo "Output directory:"
ls -la output/
Click here to view the sample solution for Create Final Summary Script
# Create final summary script
cd scripts
cat > cleanup_check.sh << 'EOF'
#!/bin/bash
# Cleanup Check Script
# This script provides a summary of all created files and directories

echo "=== Assessment Task Summary ==="
echo "Task completed on: $(date)"
echo ""

echo "Directory structure created:"
echo "assessment_task/"
echo "├── data/"
for file in ../data/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
perms=$(ls -l "$file" | cut -d' ' -f1)
echo "│ ├── $filename ($perms)"
fi
done

echo "├── scripts/"
for file in .*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
if [ -x "$file" ]; then
echo "│ ├── $filename (executable)"
else
echo "│ ├── $filename"
fi
fi
done

echo "└── output/"
for file in ../output/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
echo " ├── $filename"
fi
done

echo ""
echo "Total files created: $(find ../ -type f | wc -l)"
echo "Total directories created: $(find ../ -type d | wc -l)"
echo "=== Summary Complete ==="
EOF

# Change the file permissions to execute
chmod +x cleanup_check.sh
./cleanup_check.sh

# Return to assessment_task root
cd ..
pwd

Note: When you run file_manager.sh, you'll be prompted to enter your favorite programming language. The script will create a file with that name in the output directory.


Summary​

Congratulations! You've completed this Linux tutorial. You've learned to:

  1. Navigate the file system using cd, pwd, and ls
  2. Create directories with mkdir
  3. Create and manage files with touch, cp, mv
  4. Understand file permissions and the meaning of rwx
  5. Create bash scripts with proper comments
  6. Use chmod to modify file permissions
  7. Create interactive scripts that accept user input
  8. Remove directories recursively with rm -r

Key Commands Reference​

CommandPurposeExample
pwdShow current directorypwd
lsList directory contentsls -la
cdChange directorycd /home/user
mkdirCreate directorymkdir new_folder
touchCreate empty filetouch file.txt
cpCopy filescp file1.txt file2.txt
mvMove/rename filesmv old.txt new.txt
chmodChange permissionschmod 755 script.sh
rm -rRemove recursivelyrm -r directory/

Next Steps​

Now that you're comfortable with basic Linux operations, consider exploring:

  • Advanced bash scripting with loops and conditionals
  • Text processing with grep, sed, and awk
  • Process management with ps, top, and kill
  • File searching with find and locate
  • Network commands like wget, curl, and ssh

Happy scripting!