Linux文件管理命令

Posted 转角遇到抢劫的

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux文件管理命令相关的知识,希望对你有一定的参考价值。

一、文件过滤命令

1:​|​:管道符

#作用​:将管道符左边命令的标准输出,交给管道符右边命令的标准输入来处理

2:​grep​(命令):过滤输出内容

^​:以...开头
$​:以...结尾
*​:匹配*前面的内容至少0次或多次
.​:匹配任意字符

3:​##选项

-n​:打印行号 number
-A​:after 查看过滤内容的后N行
-B​:before 查看过滤内容的前N行
-C​:center 查看过滤内容的前、后N行
-v​:取反
-E​:可以过滤多个结果
-o​:只打印出过滤内容
-i​:不区分大小写

4:##举例( ^:以...开头)
0 ✓ 21:32:37 root@jinnan,10.0.0.101:/etc #​ grep ^e virc

endif
endif
endif
endif
endif

5:##举例($:以...结尾)
0 ✓ 21:33:17 root@jinnan,10.0.0.101:/etc # ​grep e$ virc

set bs=indent,eol,start " allow backspacing over everything in insert mode
"set backup " keep a backup file
set viminfo=20,\\"50 " read/write a .viminfo file, dont store more
set ruler " show the cursor position all the time
" start with spec file template
set csprg=/usr/bin/cscope

6:##举例(*:匹配*前面的内容至少0次或多次 | .:匹配任意字符)
0 ✓ 21:47:02 root@jinnan,10.0.0.101:/etc # ​grep w* virc

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo=20,\\"50 " read/write a .viminfo file, dont store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
" autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\\ if line("\\"") > 0 && line ("\\"") <= line("$") |
\\ exe "normal! g\\"" |
\\ endif

7:##举例( .:匹配任意字符)
0 ✓ 21:48:04 root@jinnan,10.0.0.101:/etc # ​grep ,. virc

set fileencodings=ucs-bom,utf-8,latin1
set bs=indent,eol,start " allow backspacing over everything in insert mode
set viminfo=20,\\"50 " read/write a .viminfo file, dont store more
" In text files, always limit the width of text to 78 characters
" When editing a file, always jump to the last cursor position
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set
directory=~/tmp,/var/tmp,/tmp
" Switch syntax highlighting on, when the terminal has colors
let &guicursor = &guicursor . ",a:blinkon0"

8:##举例(-n:打印行号 number)
0 ✓ 21:51:15 root@jinnan,10.0.0.101:/etc # ​grep -n o virc

2: set fileencodings=ucs-bom,utf-8,latin1
5:set nocompatible " Use Vim defaults (much better!)
6:set bs=indent,eol,start " allow backspacing over everything in insert mode
7:"set ai " always set autoindenting on9:set viminfo=20,\\"50 " read/write a .viminfo file, dont store more
10: " than 50 lines of registers
11:set history=50 " keep 50 lines of command line history
12:set ruler " show the cursor position all the time
14:" Only do this part when compiled with support for autocommands
15:if has("autocmd")
16: augroup redhat
17: autocmd!
18: " In text files, always limit the width of text to 78 characters
19: " autocmd BufRead *.txt set tw=78

9:##举例(-A:after 查看过滤内容的后N行)
0 ✓ 22:08:11 root@jinnan,10.0.0.101:/etc # ​grep -A 2 5 yum.conf

installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?
project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

10:##举例(-B:before 查看过滤内容的前N行)
0 ✓ 22:15:12 root@jinnan,10.0.0.101:/etc # ​grep -B 3 5 yum.confobsoletes=1

gpgcheck=1
plugins=1
installonly_limit=5

11:##举例(-C:center 查看过滤内容的前、后N行)
0 ✓ 22:17:48 root@jinnan,10.0.0.101:/etc # ​grep -C 3 5 yum.conf

obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?
project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

12:##举例(-v:取反)
0 ✓ 22:18:48 root@jinnan,10.0.0.101:/etc # ​grep -v a yum.conf

debuglevel=2
obsoletes=1
gpgcheck=1
plugins=1
# in /etc/yum.repos.d

13:##举例(-E:可以过滤多个结果)
0 ✓ 22:19:59 root@jinnan,10.0.0.101:/etc # ​grep -E 5|2 yum.conf

debuglevel=2
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?
project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum

14:##举例(-o:只打印出过滤内容)
0 ✓ 22:24:14 root@jinnan,10.0.0.101:/etc # ​grep -o 2 yum.conf

2
2

15:##举例(-i:不区分大小写)
0 ✓ 22:24:27 root@jinnan,10.0.0.101:/etc # ​grep -i d yum.conf

cachedir=/var/cache/yum/$basearch/$releasever
debuglevel=2

bugtracker_url=http://bugs.centos.org/set_project.php?
project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# This is the default, if you make this bigger yum wont see if the metadata
# is newer on the remote and so youll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# It is esp. important, to have correct metadata, for distributions like
# Fedora which dont keep old packages around. If you dont like this checking
# interupting your command line usage, its much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

二、文件的上传和下载命令

​1:#如何把windows的文件上传到虚拟机里

命令:​rz

2:# 如何把虚拟机的文件下载到windows里
命令:​sz​+文件名

3:## 需要安装:rz和sz命令
yum install -y lrzsz

## 注意:只能虚拟机和物理机之间上传下载

4:## 外网下载命令
# 安装​wget​命令
yum install -y wget
wget(命令)+下载地址
-o​:指定下载的位置和文件名字

三、文件查找命令

1:​type​(命令) -a 只针对系统的内置命令

2:##查找命令位置的命令:​which

which 只能查找命令

3:##举例
22:35:19 root@jinnan,10.0.0.101:~ # ​which mkdir

/usr/bin/mkdir
0 ✓ 22:35:39 root@jinnan,10.0.0.101:~ # ​which grep

alias grep=grep --color=auto

​/usr/bin/grep

四、字符命令-排序

1:#命令:​sort

2:##语法
sort  [选项]...  file...

3:##选项
-t​:指定分割符
-k​:指定按照某一行,进行排序
-n​:按照阿拉伯数字排序
-r:​倒叙排序
​​## 注意:默认按照每一行的第一个字符进行排序,如果字符相同就往后推,字母按照a-z的顺序排序,排序不修改源文件内容

4:##举例(​-t -k​)

0 ✓ 22:44:02 root@jinnan,10.0.0.101:~ # sort -t . -k 4 paixuti.txt
192.168.1.10 00:30:15:A2:3B:B6
192.168.3.10 00:30:15:A2:3B:B6
192.168.1.1 00:0F:AF:81:19:1F
192.168.3.1 00:0F:AF:81:19:1F
192.168.1.11 00:30:15:A3:23:B7
192.168.1.11 00:30:15:A3:23:B7
192.168.1.12 00:30:15:A2:3A:A1
192.168.3.12 00:30:15:A2:3A:A1
192.168.0.151 00:0F:AF:85:6C:F6
192.168.0.151 00:0F:AF:85:6C:F6
192.168.0.152 00:0F:AF:83:1F:65
192.168.1.152 00:0F:AF:83:1F:65
192.168.0.153 00:0F:AF:85:70:03
192.168.0.153 00:0F:AF:85:70:03
192.168.2.20 00:0F:AF:85:55:DE
192.168.2.20 00:0F:AF:85:55:DE
192.168.2.2 00:0F:AF:85:6C:25
192.168.3.2 00:0F:AF:85:6C:25
192.168.1.21 00:0F:AF:85:6C:09
192.168.2.21 00:0F:AF:85:6C:09
192.168.2.22 00:0F:AF:85:5C:41
192.168.2.22 00:0F:AF:85:5C:41
192.168.3.3 00:0F:AF:85:70:42
192.168.3.3 00:0F:AF:85:70:42

5:##举例(​-n​:按照阿拉伯数字排序)
0 ✓ 22:45:21 root@jinnan,10.0.0.101:~ # sort -t . -n paixuti.txt
192.168.0.151 00:0F:AF:85:6C:F6
192.168.0.151 00:0F:AF:85:6C:F6
192.168.0.152 00:0F:AF:83:1F:65
192.168.0.153 00:0F:AF:85:70:03
192.168.0.153 00:0F:AF:85:70:03
192.168.1.10 00:30:15:A2:3B:B6
192.168.1.1 00:0F:AF:81:19:1F
192.168.1.11 00:30:15:A3:23:B7
192.168.1.11 00:30:15:A3:23:B7
192.168.1.12 00:30:15:A2:3A:A1
192.168.1.152 00:0F:AF:83:1F:65
192.168.1.21 00:0F:AF:85:6C:09
192.168.2.20 00:0F:AF:85:55:DE
192.168.2.20 00:0F:AF:85:55:DE
192.168.2.2 00:0F:AF:85:6C:25
192.168.2.21 00:0F:AF:85:6C:09
192.168.2.22 00:0F:AF:85:5C:41
192.168.2.22 00:0F:AF:85:5C:41
192.168.3.10 00:30:15:A2:3B:B6
192.168.3.1 00:0F:AF:81:19:1F
192.168.3.12 00:30:15:A2:3A:A1
192.168.3.2 00:0F:AF:85:6C:25
192.168.3.3 00:0F:AF:85:70:42
192.168.3.3 00:0F:AF:85:70:42

6:##举例(​-r​:倒叙排序)
0 ✓ 22:47:03 root@jinnan,10.0.0.101:~ # sort -t . -r paixuti.txt
192.168.3.3 00:0F:AF:85:70:42
192.168.3.3 00:0F:AF:85:70:42
192.168.3.2 00:0F:AF:85:6C:25
192.168.3.12 00:30:15:A2:3A:A1
192.168.3.1 00:0F:AF:81:19:1F
192.168.3.10 00:30:15:A2:3B:B6
192.168.2.22 00:0F:AF:85:5C:41
192.168.2.22 00:0F:AF:85:5C:41
192.168.2.21 00:0F:AF:85:6C:09
192.168.2.2 00:0F:AF:85:6C:25
192.168.2.20 00:0F:AF:85:55:DE
192.168.2.20 00:0F:AF:85:55:DE
192.168.1.21 00:0F:AF:85:6C:09
192.168.1.152 00:0F:AF:83:1F:65
192.168.1.12 00:30:15:A2:3A:A1
192.168.1.11 00:30:15:A3:23:B7
192.168.1.11 00:30:15:A3:23:B7
192.168.1.1 00:0F:AF:81:19:1F
192.168.1.10 00:30:15:A2:3B:B6
192.168.0.153 00:0F:AF:85:70:03
192.168.0.153 00:0F:AF:85:70:03
192.168.0.152 00:0F:AF:83:1F:65
192.168.0.151 00:0F:AF:85:6C:F6
192.168.0.151 00:0F:AF:85:6C:F

以上是关于Linux文件管理命令的主要内容,如果未能解决你的问题,请参考以下文章

linux基本命令

LINUX运维——文件管理命令及用户和组管理

2022-03-31 学好大数据先攻克 Linux 之文件管理(下) 补充基础命令

Linux文件管理 head

linux基础命令

Linux中从后台启动进程,应在命令结尾处加上啥符号