一条命令把文件夹共享给局域网

把目录变成一个网页,同一 Wi-Fi 下的设备用浏览器就能下载文件。

Linux网络Python共享HTTP 服务器低风险
在要共享的文件夹里运行 python3 -m http.server 8000,其他设备用浏览器打开 http://你的IP:8000 即可。

01命令

命令
$ cd /path/to/folder && python3 -m http.server 8000

02作用说明

Python 自带的 http.server 会把当前目录变成一个可浏览的文件列表,不需要装任何东西、也不用改配置。用 ip addr 查到自己的 IP 后,同一局域网里的手机、电脑都能直接下载。按 Ctrl+C 即停止共享。

03风险

风险低风险
使用条件python3 (preinstalled on most distros)
!注意: 它没有任何密码保护:运行期间同一网络里的任何人都能读取该文件夹及其子目录的全部内容。用完立即停止,也不要在自己的主目录里直接运行。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • http.server — Python documentation
    Python Software Foundation · community · 2026-09-17
    依据: python -m http.server serves the current directory over HTTP on the given port; it is intended for testing and local use.

最后验证: 2026-09-18 · 分类: 网络

06相关方案