A safe Linux practice workspace

LINUX HANDBOOK / 01

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
2
pwd
ls -lah

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
2
3
mkdir -p "$HOME/perry-linux-practice"
cd "$HOME/perry-linux-practice"
pwd

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
2
3
4
5
printf 'sample\tgroup\nS01\tcontrol\nS02\ttreatment\n' > samples.tsv
head -n 3 samples.tsv
wc -l samples.tsv
cp -i samples.tsv samples-copy.tsv
ls -lh 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

  1. Where am I? Check with pwd.
  2. Are both source and destination correct? Inspect with ls.
  3. 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.

引用到评论
随便逛逛博客分类文章标签
复制地址关闭热评深色模式轉為繁體