学习 Linux + Rust 可以从「基础环境 → Rust 基础 → Linux 系统编程 → 实战项目」这条主线走。下面给你一个比较系统的学习路线。
如果你已经是 Linux 用户,可直接用;否则建议:
ls cd pwd mkdir rm cp mv
cat less grep find
chmod chown ps top
推荐先学:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
然后:
source $HOME/.cargo/env
rustc --version
cargo --version
常用工具:
cargo new demo
cargo run
cargo build
重点学:
推荐资料:
rustup doc --book
Rust 在 Linux 下常用系统编程 crate:
std::os::unixlibcnixtokio(异步)anyhow / thiserror(错误处理)示例:读取目录
use std::fs;
fn main() {
for entry in fs::read_dir("/etc").unwrap() {
let entry = entry.unwrap();
println!("{}", entry.path().display());
}
}
示例:调用系统命令
use std::process::Command;
fn main() {
let output = Command::new("ls")
.arg("-l")
.output()
.unwrap();
println!("{}", String::from_utf8_lossy(&output.stdout));
}
cat / wc / grep 简化版nix 写 fork / pipestd::threadtokio如果你愿意,我可以:
你目前是:零基础 / 有 Python/C 基础 / 已在用 Linux?