Linux 小知识 文件管理小知识 Linux 小知识

这是我参与11月更文挑战的第16天,活动详情查看:2021最后一次更文挑战

Linux 小知识 | 文件管理小知识

Vim 定位行

快速定位到指定位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
bash复制代码$ vim 文件名 行数 # 查看文件并定位到具体行数

[root@VM-8-10-centos app]# vim --help
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 18 2020 15:49:08)

usage: vim [arguments] [file ..] edit specified file(s)
or: vim [arguments] - read text from stdin
or: vim [arguments] -t tag edit file where tag is defined
or: vim [arguments] -q [errorfile] edit file with first error

Arguments:
-- Only file names after this
-v Vi mode (like "vi")
-e Ex mode (like "ex")
-E Improved Ex mode
-s Silent (batch) mode (only for "ex")
-d Diff mode (like "vimdiff")
-y Easy mode (like "evim", modeless)
-R Readonly mode (like "view")
-Z Restricted mode (like "rvim")
-m Modifications (writing files) not allowed
-M Modifications in text not allowed
-b Binary mode
-l Lisp mode
-C Compatible with Vi: 'compatible'

异常处理

如何出现? 编辑文件时, 服务器连接异常关闭

如果 vim 异常退出, 在硬盘上可能会保存有交换文件

修改 a.txt 不会在原文件上修改 会创建 a.txt.swp(交换文件) 修改, 保存时在写回到a.txt中

处理方法

1
bash复制代码rm -rf a.txt.swp # 删除即可

echo 命令

1
2
3
4
5
6
7
bash复制代码echo 字符串 # 展示文本
[root@VM-8-10-centos touch-test]# echo "hello world"
hello world

echo 字符串 > 文件名 # 将字符串写到文件中(覆盖文件中的内容)
echo 字符串 >> 文件名 # 将字符串写到文件中(不覆盖文件中内容)
cat 不存在的目录 &>> error.log # 将命令的失败结果 追加到 error.log文件的后面

软连接

类似于 windows 中的快捷方式

为什么需要软链接?

因为某些文件和目录的路径很深,所以需要增加软链接(快捷方式)

1
2
3
4
5
6
7
8
9
10
bash复制代码ln -s 目标文件路径 快捷方式路径

[root@VM-8-10-centos app]# ln --help
Usage: ln [OPTION]... [-T] TARGET LINK_NAME
or: ln [OPTION]... TARGET
or: ln [OPTION]... TARGET... DIRECTORY
or: ln [OPTION]... -t DIRECTORY TARGET...
# 示例
cd app
ln -s /app/command/test test

find 命令

在指定目录下查找文件或文件夹

1
2
3
4
5
6
7
8
9
10
11
12
bash复制代码find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

语法: find [参数选项] <指定目录> <指定条件> <指定内容> # 在指定目录下查找文件
-name filename # 查找名为filename的文件 按文件名查找
-ctime -n或+n # 按时间来查找文件, -n指n天以内, +n指n天以前

[root@VM-8-10-centos app]# find . -name setup
./test/setup
./setup
# 全盘查找
find / -name "*.txt"

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%