文件与目录管理:`mkdir`、`rm`、`cp`、`mv`
掌握高效创建、删除、复制和移动文件及目录的方法。
文件与目录管理:`mkdir`、`rm`、`cp`、`mv` 是 CoddyKit 上的免费 Linux Command Line Mastery 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Command Line Mastery 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Command Line Mastery 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Mastering File Management
Managing files is a core shell skill. This lesson covers the four essentials: mkdir, cp, mv, and rm — create, copy, move, delete.
Creating Folders with `mkdir`
mkdir (make directory) creates a new folder — just give it a name. Try making one called my_documents.
mkdir my_documentsAdvanced `mkdir` Usage
Create several folders at once by listing names. Add -p to build nested directories, creating any missing parents along the way.
mkdir reports project/src/main -pCopying Files with `cp`
cp (copy) duplicates a file: give it a source and a destination. Here we use touch to make a file first, then copy it.
touch notes.txt
cp notes.txt backup_notes.txtCopying Folders with `cp -r`
To copy a whole folder, add -r (recursive) so cp grabs the directory and everything inside. Without it, folders are skipped.
mkdir data_folder
touch data_folder/file_a.txt
cp -r data_folder archived_dataMoving Files with `mv`
mv (move) relocates files or folders — like cut and paste. Point it at a source and a destination directory.
touch document.pdf
mkdir important_files
mv document.pdf important_files/Renaming Files & Folders
Bonus: mv also renames. Move a file to the same place with a new name, and you’ve renamed it.
touch old_report.txt
mv old_report.txt new_report.txtDeleting Files with `rm`
rm (remove) deletes files — permanently, with no trash to recover from. Always double-check what you’re removing.
touch unwanted.txt
rm unwanted.txtDeleting Folders with `rm -r`
To delete a non-empty folder, add -r so rm clears the directory and its contents. Extreme caution — this is irreversible.
mkdir empty_folder
rm -r empty_folderQuick Check: File Management
Imagine you have a file named draft.txt in your current directory. You want to create a new folder called final_docs and then move draft.txt into it, renaming it to final_report.txt in the process. Which sequence of commands would achieve this?
Lesson Summary
Great work! You’ve got file management down: mkdir to create, cp to copy, mv to move or rename, and rm to delete (with -r for folders).
常见问题解答
「文件与目录管理:`mkdir`、`rm`、`cp`、`mv`」课时是免费的吗?
是的 — 「文件与目录管理:`mkdir`、`rm`、`cp`、`mv`」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Command Line Mastery 课程的其余内容,请升级到 CoddyKit PRO。 Linux Command Line Mastery 课程共包含 4 节课。
「文件与目录管理:`mkdir`、`rm`、`cp`、`mv`」这节课中我会学到什么?
掌握高效创建、删除、复制和移动文件及目录的方法。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Linux Command Line Mastery 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Linux Command Line Mastery 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「文件与目录管理:`mkdir`、`rm`、`cp`、`mv`」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Linux Command Line Mastery 课中编写并运行代码吗?
能。每节 Linux Command Line Mastery 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- Linux Shell 入门
- 基本导航:`cd`、`ls`、`pwd`
- 文件与目录管理:`mkdir`、`rm`、`cp`、`mv`
- 获取帮助:man、--help 与 tldr