小编for*_*une的帖子

获取名称包含小于或等于给定输入日期的日期值的文件

我的一个文件夹包含以下格式的文件:

3_20150412104422154033.txt
3_2015041211022775012.txt
3_20150412160410171639.txt
3_20150412160815638933.txt
3_20150413161046573097.txt
3_20150413161818852312.txt
3_20150413163054600311.txt
3_20150413163514489159.txt
3_2015041321292659391.txt
3_20150414124528747462.txt
3_20150414125110440425.txt
3_20150414134437706174.txt
3_20150415085045179056.txt
3_20150415100637970281.txt
3_20150415101749513872.txt
Run Code Online (Sandbox Code Playgroud)

我想检索日期值小于或等于我的输入日期值的那些文件。

例如,如果我给出“3_20150414”即(3_YYYYMMDD),我希望输出是文件名

3_20150412104422154033.txt
3_2015041211022775012.txt
3_20150412160410171639.txt
3_20150412160815638933.txt
3_20150413161046573097.txt
3_20150413161818852312.txt
3_20150413163054600311.txt
3_20150413163514489159.txt
3_2015041321292659391.txt
3_20150414124528747462.txt
3_20150414125110440425.txt
3_20150414134437706174.txt
Run Code Online (Sandbox Code Playgroud)

我可以通过发出这样的命令来列出文件:

ls -l | grep '20150413\|20150414' |awk '{print $NF}'
Run Code Online (Sandbox Code Playgroud)

但我正在努力寻找<=匹配。

linux shell grep

7
推荐指数
1
解决办法
1万
查看次数

逐行获取程序的pid

我可以通过发出这样的命令来找到我的程序实例的 pid:

pidof avconv
Run Code Online (Sandbox Code Playgroud)

这给了我结果

16616 16283 16279 16198 16175 16035 15073 14049 4922
Run Code Online (Sandbox Code Playgroud)

但是如何逐行输出相同的结果,例如:

16616 
16283 
16279 
16198 
16175 
16035 
15073 
14049 
4922
Run Code Online (Sandbox Code Playgroud)

shell process

6
推荐指数
3
解决办法
1660
查看次数

获取输入日期之前创建的目录中的所有文件名

我有一个包含大量文件的目录。ls命令的输出是

-rw-r--r-- 1 nobody nogroup    427494 May 26 13:59 14_20150526065238928590_102.txt
-rw-r--r-- 1 nobody nogroup   2113592 May 26 14:00 14_20150526065238928590_105.txt
-rw-r--r-- 1 nobody nogroup    429947 May 26 14:00 14_20150526065238928590_110.txt
-rw-r--r-- 1 nobody nogroup    453831 May 27 14:00 14_20150526065238928590_112.txt
-rw-r--r-- 1 nobody nogroup    551023 May 27 14:01 14_20150526065238928590_118.txt
-rw-r--r-- 1 nobody nogroup     60083 May 27 14:01 14_20150526065238928590_119.txt
-rw-r--r-- 1 nobody nogroup    632324 May 28 03:38 14_20150526065238928590_160.txt
-rw-r--r-- 1 nobody nogroup    735624 May 28 03:38 14_20150526065238928590_161.txt
-rw-r--r-- 1 nobody nogroup   2707507 …
Run Code Online (Sandbox Code Playgroud)

shell timestamps files

3
推荐指数
1
解决办法
916
查看次数

标签 统计

shell ×3

files ×1

grep ×1

linux ×1

process ×1

timestamps ×1