跳到主要内容

永久URL

· 阅读需 2 分钟

使用脚本生成永久URL

创建以下脚本,并运行 node scripts/generateSlug.js 给所有文章生成 slug 。

项目根目录/scripts/generateSlug.js
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const matter = require('gray-matter');

/**
* 生成一个8位长度的随机slug
* @returns {string} 8位随机十六进制字符串
*/
function generateSlug() {
return crypto.randomBytes(4).toString('hex');
}

/**
* 处理单个 Markdown 文件:
* 1. 解析文件中的 front matter
* 2. 如果前置数据中没有 slug,则生成并添加
* 3. 将修改后的内容写回文件
*
* @param {string} filePath 文件的完整路径
*/
function processMarkdownFile(filePath) {
// 读取 Markdown 文件内容
const fileContent = fs.readFileSync(filePath, 'utf8');
// 使用 gray-matter 解析 front matter 和正文内容
const parsed = matter(fileContent);

// 如果 front matter 对象中没有 slug 字段,则添加
if (!parsed.data.slug) {
const newSlug = `/${generateSlug()}`;
parsed.data.slug = newSlug;
console.log(`为文件 ${filePath} 生成新的 slug: ${newSlug}`);
// 通过 gray-matter 重新构造 Markdown 内容(包含新的 front matter)
const newContent = matter.stringify(parsed.content, parsed.data);
// 将新的内容写回到源文件
fs.writeFileSync(filePath, newContent, 'utf8');
}
}

/**
* 递归遍历指定目录,处理所有 Markdown 文件(支持 .md 和 .mdx 后缀)
*
* @param {string} dirPath 目录路径
*/
function processDirectory(dirPath) {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name);
if (entry.isDirectory()) {
// 如果是目录,则递归处理
processDirectory(fullPath);
} else if (entry.isFile() && (entry.name.endsWith('.md') || entry.name.endsWith('.mdx'))) {
// 如果是 Markdown 文件,调用处理函数
processMarkdownFile(fullPath);
}
}
}

// 指定 docs 目录所在路径(相对于脚本位置)
const docsPath = path.join(__dirname, '../docs');
// 开始处理 docs 目录下的所有 Markdown 文件
processDirectory(docsPath);

已收录命令统计

· 阅读需 4 分钟
灵魂信息
在线知识库
#数量统计
/mnt/d/网站开发/linux-cmd/my-website main ⇡2 !185 ?4 ❯ tree docs | grep .md |wc
144 453 4683

#详情
/mnt/d/网站开发/linux-cmd/my-website main ⇡2 !185 ?4 ❯ tree docs
docs
└── 02-command
├── 10-包管理器
│ ├── 10-apt.md
│ ├── 11-apt-get.md
│ ├── 12-apt-cache.md
│ ├── 13-dpkg.md
│ ├── 14-snap.md
│ ├── 20-dnf.md
│ ├── 21-yum.md
│ ├── 22-rpm.md
│ ├── 23-pacman.md
│ ├── 99-appimage.md
│ ├── 99-flatpak.md
│ └── _category_.json
├── 20-文件管理
│ ├── 查看、查找、比较
│ │ ├── _category_.json
│ │ ├── cd.md
│ │ ├── cmp.md
│ │ ├── diff.md
│ │ ├── du.md
│ │ ├── file.md
│ │ ├── find.md
│ │ ├── locate.md
│ │ ├── ls.md
│ │ ├── pwd.md
│ │ ├── stat.md
│ │ └── tree.md
│ ├── 创建、删除
│ │ ├── _category_.json
│ │ ├── rmdir.md
│ │ ├── rm.md
│ │ └── touch.md
│ ├── 权限
│ │ ├── _category_.json
│ │ ├── chattr.md
│ │ └── chmod.md
│ ├── 移动、复制、链接
│ │ ├── _category_.json
│ │ ├── cp.md
│ │ ├── dd.md
│ │ ├── ln.md
│ │ ├── mkdir.md
│ │ └── mv.md
│ ├── 重命名
│ │ ├── _category_.json
│ │ └── rename.md
│ └── _category_.json
├── 25-文本处理
│ ├── awk.md
│ ├── _category_.json
│ ├── cat.md
│ ├── cut.md
│ ├── echo.md
│ ├── grep.md
│ ├── head.md
│ ├── less.md
│ ├── more.md
│ ├── sed.md
│ ├── sort.md
│ ├── tail.md
│ ├── tr.md
│ ├── uniq.md
│ └── wc.md
├── 30-与用户相关
│ ├── _category_.json
│ ├── chage.md
│ ├── chgrp.md
│ ├── chown.md
│ ├── chsh.md
│ ├── groupadd.md
│ ├── groupdel.md
│ ├── groups.md
│ ├── passwd.md
│ ├── sudo.md
│ ├── su.md
│ ├── useradd.md
│ ├── userdel.md
│ └── usermod.md
├── 40-系统管理相关
│ ├── bg.md
│ ├── _category_.json
│ ├── dmesg.md
│ ├── fg.md
│ ├── free.md
│ ├── glances.md
│ ├── htop.md
│ ├── iotop.md
│ ├── jobs.md
│ ├── journalctl.md
│ ├── killall.md
│ ├── kill.md
│ ├── neofetch.md
│ ├── nice.md
│ ├── pgrep.md
│ ├── tail-f.md
│ ├── top.md
│ ├── uname.md
│ ├── uptime.md
│ ├── whoami.md
│ └── w-uptime.md
├── 50-网络
│ ├── 常用网络工具.md
│ ├── _category_.json
│ ├── curl.md
│ ├── dig.md
│ ├── ftp.md
│ ├── ifconfig.md
│ ├── iftop.md
│ ├── ip.md
│ ├── netstat.md
│ ├── nmap.md
│ ├── ping.md
│ ├── rsync.md
│ ├── scp.md
│ ├── ssh.md
│ ├── ss.md
│ ├── telnet.md
│ ├── traceroute.md
│ └── wget.md
├── 60-文件系统
│ ├── badblocks.md
│ ├── blkid.md
│ ├── _category_.json
│ ├── df.md
│ ├── fdisk.md
│ ├── fsck.md
│ ├── lsblk.md
│ ├── mdadm-fault-correcting.md
│ ├── mdadm-fault-correcting-practice.md
│ ├── mdadm.md
│ ├── mkfs.md
│ ├── mount.md
│ ├── parted.md
│ ├── pkill.md
│ ├── ps.md
│ ├── tune2fs.md
│ ├── umask.md
│ └── umount.md
├── 70-压缩和解压缩
│ ├── bunzip2.md
│ ├── bzip2.md
│ ├── _category_.json
│ ├── gunzip.md
│ ├── gzip.md
│ ├── tar.md
│ ├── unzip.md
│ └── zip.md
├── 80-定时任务
│ ├── at.md
│ ├── atq.md
│ ├── atrm.md
│ ├── _category_.json
│ ├── cron.md
│ └── crontab.md
├── 90-防火墙
│ ├── _category_.json
│ ├── firewalld.md
│ ├── gpg.md
│ ├── iptables.md
│ ├── nftables.md
│ ├── openssl.md
│ └── ufw.md
├── 99-更多
│ ├── alias.md
│ ├── bc.md
│ ├── cal.md
│ ├── _category_.json
│ ├── command-not-found.mdx
│ ├── date.mdx
│ ├── ffmpeg.md
│ ├── ncal.md
│ ├── tee.md
│ ├── tmux.md
│ ├── uuid.md
│ └── watch.md
└── index.md

17 directories, 160 files

Linux命令的重要性

· 阅读需 3 分钟

举个例子吧:远程桌面

  • GUI 远程桌面:需要远程和本地同时安装桌面环境,需要一定的网络带宽支持,需要消耗更多服务器资源,许多小服务器 1C1G、2C2G 的服务器根本就跑不了。
  • CLI SSH:对服务器和网络的消耗的接近0,反应更快,几乎不用考虑网络带宽和延迟。关键还便捷,电脑、手机、平板任何设备都可以运行 SSH 客户端。

1. 为什么 Linux 命令重要?

  • 高效灵活:命令行快速完成复杂任务,支持高度定制。
  • 自动化:脚本化任务,提升效率。
  • 系统管理:核心工具,用于配置、监控和维护。
  • 远程管理:通过 ssh 等工具轻松管理远程服务器。
  • 开源文化:丰富工具和社区支持。

2. 为什么 Linux 离不开命令行?

  • Unix 传统:继承 Unix 设计哲学,强调工具组合。
  • 服务器主导:服务器环境依赖命令行,资源占用低。
  • 开发者偏好:工具链以命令行为主,开发效率高。
  • 强大生态:丰富工具和可扩展性。

3. 为什么 Linux 桌面生态不完整?

  • 市场份额低:桌面市场被 Windows 和 macOS 主导,商业支持不足。
  • 硬件支持:部分硬件驱动不完善,厂商支持有限。
  • 碎片化:多种桌面环境和包管理工具,开发适配复杂。
  • 软件缺失:专业软件(如 Adobe、Office)和游戏支持不足。
  • 用户体验:界面设计和易用性不如 Windows 和 macOS。

4. Linux 桌面的未来

  • 技术进步:Wayland、Flatpak/Snap 改善兼容性和易用性。
  • 游戏生态:Proton 和 Steam Deck 推动 Linux 游戏发展。
  • 社区推动:开发者和社区持续改进桌面体验。

总结

  • 命令行是 Linux 的核心,高效且强大,适合开发和管理。
  • 桌面生态虽不完善,但在开源和定制性上有优势,未来可期。

常用命令分类

· 阅读需 4 分钟

Linux命令分类

Linux命令可以根据其功能和用途进行详细分类,以下是一些常见的分类及其对应的命令示例: