A safe Linux practice workspace
Know where you are before changing a file
This exercise uses a new practice directory. It does not delete files or touch real analysis data.
1. Inspect the current location
1 | pwd |
pwd prints the working directory. ls -lah lists detailed information, including hidden files and human-readable sizes. An absolute path begins at /; a relative path is interpreted from the working directory. . means the current directory and .. means its parent.
2. Create a separate practice directory
Run this in a Bash terminal on Linux or WSL:
1 | mkdir -p "$HOME/perry-linux-practice" |
The home directory is used only as a location for the new exercise. No environment variable is changed. Do not replace the example with a directory containing your raw research data.
3. Create, inspect and copy a small text file
1 | printf 'sample\tgroup\nS01\tcontrol\nS02\ttreatment\n' > samples.tsv |
The first run creates three lines, including a header. > overwrites an existing file with the same name, so inspect it before repeating the command. cp -i asks before overwriting a destination; answer n if you are unsure.
4. Ask three questions before making a change
- Where am I? Check with
pwd. - Are both source and destination correct? Inspect with
ls. - Could this overwrite, move or delete data? Test inside the practice directory first.
This exercise deliberately contains no bulk deletion command. In a real project, decide on backups and retention rules before managing files.
Exercise
Before running anything, explain the difference between ./samples.tsv, ../samples.tsv and /tmp/samples.tsv. Then use head to check that the copy still contains the same header.
Further reading
Use the official GNU Coreutils manual for detailed command behaviour. The Linux handbook currently contains additional chapters in Chinese. Return to the English collection for other complete English guides.