通过运行find /mnt/ExtraHDD1/ -type f -links +1 -printf '%i %n %p\n' | sort -n > test.txt find /mnt/ExtraHDD1/ -type f -links +1 -printf '%i %n %p\n' | sort -n > test.txt ,我得到以下输出:
32113282 3 /mnt/ExtraHDD1/1/6.png 32113282 3 /mnt/ExtraHDD1/2/6.png 32113282 3 /mnt/ExtraHDD1/3/6.png 32113284 2 /mnt/ExtraHDD1/1/8.png 32113284 2 /mnt/ExtraHDD1/2/8.png我运行的命令列出了/ mnt / ExtraHDD1 /中的所有硬链接。 我正在尝试生成排除列表,以便我不会多次将相同的文件上传到云端。 在每一行中,第一个数字(例如32113282)表示inode编号。 第二个数字(例如3)表示文件硬链接的次数。 由于这是一个排除列表,我想删除每个inode号的第一个实例,以便排除除第一个副本之外的所有硬链接副本。 所以在这种情况下,我想要以下输出:
32113282 3 /mnt/ExtraHDD1/2/6.png 32113282 3 /mnt/ExtraHDD1/3/6.png 32113284 2 /mnt/ExtraHDD1/2/8.png如何在bash中使用for循环执行此操作? 我知道如何用Java实现它,但bash语法让我感到困惑。
By running find /mnt/ExtraHDD1/ -type f -links +1 -printf '%i %n %p\n' | sort -n > test.txt, I get the following output:
32113282 3 /mnt/ExtraHDD1/1/6.png 32113282 3 /mnt/ExtraHDD1/2/6.png 32113282 3 /mnt/ExtraHDD1/3/6.png 32113284 2 /mnt/ExtraHDD1/1/8.png 32113284 2 /mnt/ExtraHDD1/2/8.pngThe command I ran lists all the hard-links in /mnt/ExtraHDD1/. I'm trying to generate an exclude list so that I don't upload the same file multiple times to the cloud. In each line, the first number (e.g. 32113282) represents the inode number. The second number (e.g. 3) represents the number of times the file is hard-linked. Since this is an exclude list, I want to remove the first instance of each inode number so that I exclude all copies of a hard-link except the first copy. So in this case, I want the following output:
32113282 3 /mnt/ExtraHDD1/2/6.png 32113282 3 /mnt/ExtraHDD1/3/6.png 32113284 2 /mnt/ExtraHDD1/2/8.pngHow can I do this using a for loop in bash? I know how to do it in Java but bash syntax is confusing me.
最满意答案
拯救!
如果我理解正确,第一个字段是关键。
$ awk 'a[$1]++' file 32113282 3 /mnt/ExtraHDD1/2/6.png 32113282 3 /mnt/ExtraHDD1/3/6.png 32113284 2 /mnt/ExtraHDD1/2/8.pngawk to the rescue!
If I understand correctly, first field is the key.
$ awk 'a[$1]++' file 32113282 3 /mnt/ExtraHDD1/2/6.png 32113282 3 /mnt/ExtraHDD1/3/6.png 32113284 2 /mnt/ExtraHDD1/2/8.png更多推荐
发布评论