Linux DevOps Practical Labs
Lab Set 1: Basic Skills
Lab 1.1: Wildcards and File Management
- Create 10 files named
test1.txtthroughtest10.txtin a new directory calledlab1 - Create 5 files named
report_jan.log,report_feb.log,report_mar.log,report_apr.log,report_may.log - List only files that start with “test” and have a single digit
- List only files that end with
.logextension - Copy all
.txtfiles to a new directory calledbackup - Delete all files that start with “test” and end with numbers 6-9
- Create files named
data_A.csv,data_B.csv,data_C.csv - List only files that contain uppercase letters in their names
- Rename all
.logfiles to have a.backupextension instead - Find and list all
.csvfiles in the current directory using the find command
Lab 1.2: Aliases and Productivity
- Create a temporary alias called
llthat shows detailed file listings with human-readable sizes - Create an alias called
..to go up one directory - List all currently active aliases in your session
- Create an alias called
portsto show all listening network ports - Remove the
llalias you created - Make your aliases permanent by adding them to the appropriate configuration file
- Reload your configuration file to apply the changes without logging out
Lab 1.3: Environment Variables and PATH
- Create a temporary environment variable called
DB_HOSTwith valuelocalhost - Create and export an environment variable called
APP_ENVwith valuedevelopment - Display the value of your
HOMEenvironment variable - Display your current
PATHvariable in a readable format (one directory per line) - Create a directory called
~/mybinand add it to your PATH temporarily
Lab Set 2
Lab 2.1: File Permissions and Security
- Create a file called
secret.txtand set permissions so only you can read and write it (no access for group or others)
Lab 2.2: Number Systems and Permissions
- Convert the permission
rwxr-xr-xto its octal (numeric) representation - Convert the octal permission
644to its symbolic representation - Convert the binary number
111101101to octal format (for permissions) - If a file has permissions
rw-r-----, calculate its numeric value - Convert the decimal number 255 to hexadecimal
- Convert the hexadecimal number
FFto binary - Convert the binary number
11111111to decimal - Create a file with permissions
rwxrwx---using numeric notation - What would be the binary representation of the permission
rwx------? - Calculate what permission
chmod 777represents in symbolic and binary format
Lab 2.3: Bashrc Configuration and Source
- Open your
.bashrcfile and add a comment section for “Custom Aliases” - Add an alias for
gs='git status'in your.bashrc - Add an alias for
dc='docker-compose'in your.bashrc - Add a custom function called
mkcdthat creates a directory and changes into it in one command - Create a separate file called
.bash_aliasesfor all your aliases - Modify your
.bashrcto source (load) the.bash_aliasesfile if it exists - Create a file called
.envwith database connection variables - Source the
.envfile and verify the variables are loaded - Add a custom PS1 prompt configuration to your
.bashrc - Reload your entire
.bashrcwithout logging out to test all changes
Lab 2.4: Advanced Wildcards and Find
- Create a complex directory structure:
project/{src,tests,docs}/{js,py}with multiple files - Find all
.jsfiles in the entire project directory tree - Find all files that were modified in the last 24 hours
- Find all files larger than 1MB in your home directory
- Use wildcards to list only files that start with a vowel (a, e, i, o, u)
- Find all executable files in
/usr/binthat start with ‘git’ - Delete all
.tmpfiles recursively in your project directory (be careful!) - Find all empty files in the current directory and its subdirectories
- Copy all
.conffiles from/etcthat contain the word “network” in their name to a backup directory - Use character classes to find all files that start with a digit followed by exactly two letters
Lab Set 1 - Expected Outcomes
After completing Lab Set 1, you should be able to:
- ✅ Confidently use wildcards to match file patterns
- ✅ Create and manage aliases for common commands
- ✅ Work with environment variables and PATH
- ✅ Customize your bash prompt with colors and information
- ✅ Understand basic file operations and navigation
Lab Set 2 - Expected Outcomes
After completing Lab Set 2, you should be able to:
- ✅ Master file permissions in both numeric and symbolic formats
- ✅ Convert between different number systems (binary, octal, hexadecimal)
- ✅ Configure and customize your
.bashrceffectively - ✅ Use advanced find commands and wildcards
- ✅ Implement security best practices with file permissions
Hints and Tips
For Wildcards:
- Remember
*matches zero or more characters - Remember
?matches exactly one character - Use
[0-9]for digits,[a-z]for lowercase letters - Character classes like
[[:alpha:]]are very powerful
For Permissions:
- Read = 4, Write = 2, Execute = 1
- Add them together: rwx = 4+2+1 = 7
- Common patterns: 644 (files), 755 (executables), 700 (private)
For Environment Variables:
- Use
exportto make variables available to child processes - Variables are case-sensitive
- Access with
$VARIABLE_NAMEor${VARIABLE_NAME}
For .bashrc:
- Always test changes before making them permanent
- Keep backups of your configuration files
- Use
source ~/.bashrcto reload without logging out - Comment your customizations for future reference
Validation Commands
To verify your work:
# Check file permissions
ls -l filename
# Verify aliases
alias
# Check environment variables
printenv | grep VARIABLE_NAME
# View your prompt
echo $PS1
# Test command in PATH
which command_name
# Verify sourced variables
echo $VARIABLE_NAME
Additional Challenges (Optional)
Challenge 1: Create a Development Environment Setup Script
Write a script that:
- Sets up all necessary environment variables for a project
- Creates project directory structure
- Sets appropriate permissions on all directories
- Adds project bin directory to PATH
- Creates useful aliases for the project
Challenge 2: Permission Audit Script
Write a script that:
- Finds all world-writable files
- Finds all SUID/SGID files
- Checks for files with overly permissive settings
- Generates a security report
Challenge 3: Custom Bash Profile
Create a comprehensive .bashrc that includes:
- Organized sections with clear comments
- Useful aliases for your workflow
- Custom functions for common tasks
- A beautiful, informative prompt
- Smart PATH management
- Conditional configurations based on hostname or OS
Troubleshooting Guide
If aliases don’t work:
- Check if you exported them (not needed for aliases, but needed for variables)
- Ensure you sourced the file:
source ~/.bashrc - Check for syntax errors in your alias definition
If PATH changes don’t work:
- Make sure you used
export - Verify the directory exists
- Check for typos in the path
- Ensure you reloaded your configuration
If permissions seem wrong:
- Use
ls -lto verify what was actually set - Remember: directories need
xpermission to be entered - Check both numeric and symbolic representations
- Verify you have permission to change the file
If variables disappear:
- Remember to
exportthem - Add them to
.bashrcfor persistence - Check if you’re in the same shell session
- Verify the syntax is correct