Find missing numbers in continuous filenames (advanced ls & find)

落花浮王杯 提交于 2019-12-12 04:43:59

问题


Let's say I have a script that generates incrementing folder names over time (100, 101, 102, 103, 104, etc...). These folders are synced between machines and there is a chance of creation failure for any given folder on system 2.

System 1 is always in sync: 100/ 101/ 102/ 103/ 104/ etc...

System 2 may have errors: 100/ 102/ 103/ etc...

(as you can see, 101/ & 104/ are missing on system 2)

How can I generate a list of all the missing folders on System 2?

P.S. Rsync is not really an option because the actual number of folders is incredibly high.


回答1:


You can pipe the contents of ls on each machine to a file, and then diff the two files. You can also use the command comm to show lines that are only in one file, and not in the other.




回答2:


You could do something like this:

% ls -1 System1 > ls.System1            # Use the -1 flag to ensure 1 dir per line
% ls -1 System2 > ls.System2
% comm -23 ls.System1 ls.System2
101
104

The comm command can show you what is common to both, unique to f1, or unique to f2:

comm -12 f1 f2  # common to both
comm -23 f1 f2  # unique to f1
comm -13 f1 f2  # unique to f2



回答3:


just generate a list of successful creations as they occur




回答4:


you can use diff. assuming you had already mapped system2 to a path

diff system1/path system2/path


来源:https://stackoverflow.com/questions/1772675/find-missing-numbers-in-continuous-filenames-advanced-ls-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!