Skip to content

Linux File Operations API

Linux 文本处理管道,用于过滤、转换和汇总流式文本。

1 class · 7 methods

Text Commands

7 methods

常在管道中组合使用的 POSIX 文本工具。

ls [-l] [-a] [-h] [path...]

搜索匹配正则表达式的行;-i 不区分大小写,-v 反转,-E 扩展,-r 递归。

Parameters

NameTypeDescription
pathstringDirectory or file paths to list.

Returns

void

Example

linux
ls -lah /var/log
cp [-r] [-i] [-p] source... dest

用于过滤和转换文本的流编辑器;-i 就地编辑文件。

Parameters

NameTypeDescription
sourcestringSource file(s) or directory.
deststringDestination file or directory.

Returns

void

Example

linux
cp -rp src/ /backup/src/
mv [-i] source... dest

模式-动作扫描语言;将每条记录拆分为字段并按记录运行程序。

Parameters

NameTypeDescription
sourcestringSource path(s).
deststringDestination path.

Returns

void

Example

linux
mv old_name.txt new_name.txt
rm [-r] [-f] [-i] path...

排序文本行;-n 数值,-r 反向,-u 去重,-k 键字段。

Parameters

NameTypeDescription
pathstringFile or directory paths to remove.

Returns

void

Example

linux
rm -rf node_modules
find path [-name pattern] [-type f|d] [-mtime -n] [-exec cmd {} \;]

过滤或报告相邻重复行;通常在 sort 之后。-c 前缀计数。

Parameters

NameTypeDescription
pathstringRoot directory of the search.
patternstringGlob pattern matched against file name.
typecharf for regular file, d for directory, l for symlink.

Returns

void

Example

linux
find . -name '*.log' -mtime +7 -delete
chmod [-R] mode file...

从 stdin 读取并写入 stdout 和给定文件;-a 追加而非覆盖。

Parameters

NameTypeDescription
modestringSymbolic or octal permission spec.
filestringTarget file(s) or directories.

Returns

void

Example

linux
chmod -R 750 app/
chown [-R] owner[:group] file...

Changes the owner and optionally the group of files or directories.

Parameters

NameTypeDescription
ownerstringUser name or uid.
groupstringOptional group name or gid.

Returns

void

Example

linux
chown -R node:node /app