欢迎光临散文网 会员登陆 & 注册

Linux常用命令: 文件处理

2023-03-06 21:32 作者:石城城  | 我要投稿

放心~被指到的人一定能学会的~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 


vim

VIM是一个命令行文本编辑器,为不同的文件操作提供了多种操作模式

通过i可以进入编辑模式. Esc可以返回命令模式(无法输入指令控制)

sed

直接通过脚本修改文件内容

wc

统计行/单词/字节

ln

给文件和目录创建连接

chmod

修改文件和目录的访问权限

 

 

1. vim

Vim (Vi IMproved), a command-line text editor, provides several modes for different kinds of text manipulation.

VIM是一个命令行文本编辑器,为不同的文件操作提供了多种操作模式

Pressing i enters edit mode. <Esc> goes back to normal mode, which doesn't allow regular text insertion.

通过i可以进入编辑模式. Esc可以返回命令模式(无法输入指令控制)

• Open a file(打开文件):

• View Vim's help manual(查看帮助手册):

• Save a file(保存文件, 简写:w ):

• Quit without saving(退出不保存, 简写 :q!):

• Save and quit (保存退出):

• Open a file at a specified line number(在某行打开文件):

• Undo the last operation(撤销最近操作):

• Search for a pattern in the file (press n/N to go to next/previous match)(文件搜索, 通n/N切换向后向前匹配):

• Perform a regex substitution in the whole file(替换内容,支持正则):

2. sed

Edit text in a scriptable manner.

直接通过脚本修改文件内容

• Replace the first occurrence of a regular expression in each line of a file, and print the result(打印并且替换文件中每行第一次出现的指定内容,支持正则):

• Replace all occurrences of an extended regular expression in a file, and print the result(打印并且替换文件中出现的指定内容,支持扩展正则):

• Replace all occurrences of a string in a file, overwriting the file (i.e. in-place)(替换文件中所有匹配的内容并写入文件):

• Replace only on lines matching the line pattern(匹配行之后再进行替换文件中的内容):

• Delete lines matching the line pattern(删除匹配行内容):

• Print only text between n-th line till the next empty line(从第n行打印内容到下一个空行):

• Apply multiple find-replace expressions to a file(多匹配替换操作):

3. wc

Count lines, words, or bytes.

统计行/单词/字节

• Count lines in file(统计行数):

• Count words in file(统计单词数):

• Count characters in file (taking multi-byte character sets into account)(可以统计中文字数等多字节字符):

4. ln

Creates links to files and directories.

给文件和目录创建连接

• Create a symbolic link to a file or directory(为文件目录创建软连接,路径绝对):

• Create a hard link to a file(创建硬链接):

5. chmod

Change the access permissions of a file or directory.

修改文件和目录的访问权限

• Give the [u]ser who owns a file the right to e[x]ecute it(给拥有者添加执行权限):

• Remove e[x]ecutable rights from the [g]roup(移出所属组的执行权限):

• Give [a]ll users rights to [r]ead and e[x]ecute(给所有用户添加读和执行权限):

• Give [o]thers (not in the file owner's group) the same rights as the [g]roup(将其他人设置为同所属组):

• Remove all rights from [o]thers(移出其他人的所有权限):

• Change permissions recursively giving [g]roup and [o]thers the abililty to [w]rite(给目录中所有文件和目录的所属组和其他人设置可读权限):

 

自学笔记~

如果有错~

期待大佬指出~

感谢帮助提升~ 


Linux常用命令: 文件处理的评论 (共 条)

分享到微博请遵守国家法律