更换空白的未知量X数量 [英] Replacing unknown amount of blank spaces for X amount
问题描述
哎,所以我写一个Linux脚本,我来到了一个有趣的发现。
Hey so I'm writing a linux script and I came to an interesting finding.
我有一个命令,将目录内的文件,通过它的大小和排序打印最大的一个。命令如下:
I've got a command that will sort the files inside a directory by it's size and prints the largest one. Command is as follows
找到。型的F -ls |排序-r -n -k7 |头-n 1
这将打印的东西。
895918591 8 -R-W-X 1用户01 XDF 1931年3月28日23时21 ./myscript.sh
所以我想独自获得的最大文件大小和打印。要分开呢我用切-d''-f2
的问题是,这种只留下空的输出。那是因为空间的量是不一致的。
So I want to to get the largest file size alone and print it. To separate it I used cut -d' ' -f2
issue is, this leaves only empty output. That is because the amount of spaces is inconsistent.
所以我试图做这样的事情。
So I tried doing something like this
找到。型的F -ls |排序-r -n -k7 |头-n 1 | TR -d [:空白:] |切-d''-f2
问题是,这会删除所有的空格,现在我不能用普通分离器将它们分开。于是我问,有没有办法来代替字面上所有的空格,然后用一个空格替换它们?
Issue is, this removes all the blank spaces now I can't separate them by common separator. So I'm asking, is there a way to replace literally all the blank spaces and then replace them with a single blank space?
如果没有,至少任何其他方式获得该字节数?
If not, at least any other way to get to that number of bytes?
推荐答案
我觉得你手头的得太多问题:
I think you're overthinking the issue at hand:
find -type f -printf "%s\n"|sort -n|tail -n1
这篇关于更换空白的未知量X数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!