打算用python写一个ls命令脚本,以练习python基础。这个文档就是记录该小项目的进展和学习心得。
ls是Linux下最常用的命令之一,可以列出目录内文件即子目录名,可以配合众多参数使用。为此专门查看了Linux下man手册(我用ceontos7做的测试,其他Linux应该一样。但Windows环境下会有差异,比如Windows隐藏文件的方式与Linux不一样)。
ls功能
--20191107
要用python实现ls命令,那先要了解ls功能,尤其是各种参数。我打算先实现基本功能,然后在逐步添加参数功能。以下是我导出linux系统中ls命令的man手册。
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor
--sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print C-style escapes for nongraphic characters
--block-size=SIZE
scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE
format below
-B, --ignore-backups
do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and
sort by name; otherwise: sort by ctime, newest first
-C list entries by columns
--color[=WHEN]
colorize the output; WHEN can be 'never', &#