视频网站HLS技术分析与本地下载实践

视频网站HLS技术分析与本地下载实践

HLS技术介绍

现在的视频网站为了提升视频加载速度的同时节省带宽资源都采用HLS技术,网站后台把视频做成小的视频切片,这些切片记录在m3u8文件里面。每个切片都是一个ts文件,每个ts文件可以几百KB直接播放大概10s左右,浏览器播放的同时请求每个ts文件。视频网站小广告特别多,[……]

阅读全文

1 Star2 Stars3 Stars4 Stars5 Stars (暂时还没有打分)
Loading...
linux下常见命令总结——grep和find使用方法

linux下常见命令总结——grep和find使用方法

       作为一名后台开发工程师需要频繁与linux系统“打交道”,掌握一些的Linux命令可以让这个交互过程更加流畅。本篇文章重点介绍grep和find两个查找命令,对工作中查找日志和文件有很大帮助。

grep 命令

grep [OPTIONS] PATTERN [FILE…]

文本搜索工具,根据用户指定的“模式(过滤条件)”对目标文件逐行进行匹配检查,打印匹配的行。

PATTERN:正则表达式主要分为基本正则表达式、扩展正则表达式,grep都支持。

  • 查找文件中字符串

[root@VM_5_28_centos ~]# grep bash passwd 
root:x:0:0:root:/root:/bin/bash
  • 忽略大小写查找某个字符串并显示行号

[root@VM_5_28_centos ~]# cat test.txt 
oewjaiofewfoieawjfioeawjfoi
1
2
AAAA
aa
[root@VM_5_28_centos ~]# grep -n -i aa test.txt 
4:AAAA
5:aa
  • 查找不能被匹配到的数据

[root@VM_5_28_centos ~]# grep -v a test.txt 
1
2
AAAA
  • 查找被匹配到数据的前2行 (A 表示后几行、B表示前几行、C表示前后几行)

[root@VM_5_28_centos ~]# grep -B 2 aa test.txt 
2
AAAA
aa
  • 多条件查找被匹配到的数据(egrep支持多条件查找)

[root@VM_5_28_centos ~]# egrep "1|2" test.txt 
1
2
  • 利用grep进行递归多个文件查找某个字符串

[root@VM_5_28_centos ~]# grep -R aa ./*
Binary file ./go/hello matches
Binary file ./go/pkg/linux_amd64/github.com/dutchcoders/goftp.a matches
./go/test/test.txt:aa
Binary file ./test.mp4 matches
./test.txt:aa

find 命令

find [OPTIONS] [查找起始路径] [查找条件] [处理动作]

[查找起始路径] :制定具体搜索目标起始路径;默认为当前目录。

[查找条件]:指定的查找标准,可以根据文件名,大小,类型,从属关系,时间戳,权限等标准进行;默认为找出指定目录下的所有文件。

[处理动作]:对符合查找条件的文件做出的操作,例如删除等操作;默认为输出至标准输出。

  • 查找某个文件

[root@VM_5_28_centos ~]# find ./ -name test*  
./test.mp4
-name 区分大小  -iname 不区分大小写 ./ 表示当前路径下

  • 查找空文件

[root@VM_5_28_centos ~/go]# ll
total 1892
-rwxr-xr-x 1 root root 1919238 Aug 16 19:45 hello
-rw-r--r-- 1 root root      70 Aug 16 19:45 hello.go
drwxr-xr-x 3 root root    4096 Aug 16 20:17 pkg
drwxr-xr-x 3 root root    4096 Aug 16 20:17 src
drwxr-xr-x 2 root root    4096 Feb  5 16:54 test
-rw-r--r-- 1 root root       0 Feb  5 16:54 test.txt
[root@VM_5_28_centos ~/go]# find ./ -type f -empty
./test.txt
  • 查找空文件夹

[root@VM_5_28_centos ~/go]# find ./ -type d -empty
./src/github.com/dutchcoders/goftp/.git/objects/info
./src/github.com/dutchcoders/goftp/.git/refs/tags
./src/github.com/dutchcoders/goftp/.git/branches
./test
[root@VM_5_28_centos ~/go]# ls -ltr test
total 0

  • 查找空文件并执行删除

# find ./ -type f -empty -exec rm -f {} \;
# ll
total 1892
-rwxr-xr-x 1 root root 1919238 Aug 16 19:45 hello
-rw-r--r-- 1 root root      70 Aug 16 19:45 hello.go
drwxr-xr-x 3 root root    4096 Aug 16 20:17 pkg
drwxr-xr-x 3 root root    4096 Aug 16 20:17 src
drwxr-xr-x 2 root root    4096 Feb  5 16:54 test

       find是一个实时查找命令,可以根据名字、权限、文件大小实时查找文件、文件夹,支持模糊和递归查找。最后一个参数“处理动作”可以用来对查找到的结果进行处理,例如删除文件、查看文件大小等。

vim 巧应用

vim查看日志一行特别长,一行内显示不下,怎么办?

  • 直接在vi的命令模式中输入:set wrap

  • 利用gk、gj进行上下查看,防止直接跳到下一行不方便查看。

  • 如果想取消,就输入:set nowrap

想要替换文中的某个字符,怎么办?

  • 直接在vim的命令模式中输入:s/原始字符/新字符/g   替换单行内字符

  • 直接在vim的命令模式中输入:%s/原始字符/新字符/g   替换文中所有原始字符

[……]

阅读全文

1 Star2 Stars3 Stars4 Stars5 Stars (暂时还没有打分)
Loading...