0
0
Linux CLIscripting~15 mins

Home directory (~) and shortcuts in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Home Directory (~) and Shortcuts in Linux CLI
📖 Scenario: You are learning to use the Linux command line. One important part is understanding the home directory and shortcuts like ~ which means your home folder. This helps you move around files and folders easily.
🎯 Goal: Learn how to use the home directory shortcut ~ and other shortcuts to list files and navigate directories in Linux CLI.
📋 What You'll Learn
Create a variable with the path to the home directory using ~
Create a variable with the path to the Documents folder inside the home directory
Use a command to list files in the Documents folder using the shortcut variable
Print the list of files found in the Documents folder
💡 Why This Matters
🌍 Real World
Using shortcuts like <code>~</code> helps you write scripts that work on any Linux user's computer without hardcoding full paths.
💼 Career
Many jobs require automating tasks on Linux servers or desktops where knowing how to use home directory shortcuts is essential for file management.
Progress0 / 4 steps
1
Create a variable for the home directory using ~
Create a variable called home_dir and set it to the string "~" which represents the home directory shortcut.
Linux CLI
Need a hint?

The tilde ~ is a shortcut for your home directory in Linux.

2
Create a variable for the Documents folder inside the home directory
Create a variable called documents_dir and set it to the string that joins home_dir and "/Documents" using string concatenation.
Linux CLI
Need a hint?

Use +"/Documents" to add the Documents folder to the home directory path.

3
List files in the Documents folder using the shortcut variable
Use the os module to list files in the directory stored in documents_dir. Import os and create a variable called files that stores the list of files using os.listdir(documents_dir).
Linux CLI
Need a hint?

Use os.path.expanduser() to convert ~ to the full home path before listing files.

4
Print the list of files found in the Documents folder
Print the variable files to display the list of files in the Documents folder.
Linux CLI
Need a hint?

The output will be a list of file names or an empty list if the Documents folder is empty.