Worksheet 1 - Linux commands
Real Linux Commands for Raspberry Pi: Student Worksheet
Listing Files and Folders
ls -l
Challenge: List the files in your current directory with details like file permissions, size, and date of modification. Test: Can you find which file was modified most recently?
Learning About the man Command
Objective: Learn how to use the man command to view the manual pages for different commands.
Instructions: Open the terminal and type man ls to view the manual for the ls command. Scroll through the manual to learn about the various options available for ls, such as listing files in different formats, colors, and more.
man ls
Challenge: Find the option that lets you sort files by modification time and use it when listing files in a directory.
Understanding --help with ls
Objective: Learn how to quickly get help on Linux commands without needing to open the full manual page.
Instructions: In the terminal, type ls --help to see a brief summary of the available options for the ls command. Compare this with the manual page to see the difference between the help output and the full man page.
ls --help
Challenge: Use the --help output to find an option that only shows directory names, and then list all directories in your current folder using that option.
Exploring the Power of sudo
Objective: Understand how the sudo command allows you to execute commands with administrative privileges.
Instructions: In the terminal, type sudo apt update to update the list of available software. Observe how you are prompted to enter your password because the sudo command requires elevated privileges.
sudo apt update
Challenge: Try running the apt update command without sudo and see what happens. This will help you understand why certain actions need administrative rights.
Finding Your Current Directory
pwd
Challenge: Use this command to print your working directory (the folder you're in). Test: Can you navigate to the /home directory and print its path using this command?
Changing Directories
cd
Challenge: Navigate to a directory (e.g., /home/pi/Documents) using this command. Test: Use cd .. to go back one directory. How can you go back two directories in one command?
Creating a New Folder
mkdir new_folder
Challenge: Create a new folder called projects in your home directory. Test: Can you create a folder named data inside projects?
Moving and Renaming Files
mv file.txt new_folder/
Challenge: Move a file called report.txt to the projects folder you created earlier. Test: Can you rename report.txt to summary.txt while moving it to projects?
Copying Files
cp file.txt backup.txt
Challenge: Copy a file called summary.txt to backup_summary.txt. Test: Can you copy the entire projects folder to another folder called backup_projects?
Deleting Files
rm file.txt
Challenge: Delete the backup_summary.txt file from your home directory. Test: How would you remove the entire backup_projects folder? (Hint: rm -r)
Viewing File Contents
cat file.txt
Challenge: Use this command to display the contents of summary.txt. Test: How can you display only the first 5 lines of a file? (Hint: Look up the head command)
==Finding Text Inside Files
grep "search_text" file.txt
Challenge: Search for the word temperature in the summary.txt file. Test: How would you find all occurrences of the word error in a log file called system.log?
Viewing System Information
df -h
Challenge: Display the available disk space on your Raspberry Pi using df -h. Test: How much space is available on the /boot partition?
Bonus Challenge:
Can you combine commands? For example, try combining ls with grep to find files with specific names. Run this:
ls | grep ".txt"