[英]Create a symbolic link named long_file pointing to the largest file in the current directory
I know how to create a symbolic link but I don't kow how to get largetst file in current directory.我知道如何创建符号链接,但我不知道如何在当前目录中获取最大的文件。 Please, help me!请帮我!
You can do it with the following command:您可以使用以下命令执行此操作:
find /path/to/dir-with-big-file/ -type f -printf "%s\t%p\n" | sort -n -r | head -n 1 | awk '{print $2}' | xargs -I % sh -c 'ln -sf % /path/to/symlink'
which breaks down as follows:分解如下:
find /path/to/dir-with-big-file/ -type f -printf "%s\t%p\n"
- find files and print %s
files size and %p
name. find /path/to/dir-with-big-file/ -type f -printf "%s\t%p\n"
- 查找文件并打印%s
文件大小和%p
名称。sort -n -r | head -n 1
sort -n -r | head -n 1
- sort in reverse order and get the first (ie biggest) one sort -n -r | head -n 1
- 以相反的顺序排序并获得第一个(即最大的)一个awk '{print $2}' | xargs -I % sh -c 'ln -sf % /path/to/symlink'
awk '{print $2}' | xargs -I % sh -c 'ln -sf % /path/to/symlink'
- extract full file name and create or update a symlink (eg in you case long_file) awk '{print $2}' | xargs -I % sh -c 'ln -sf % /path/to/symlink'
- 提取完整文件名并创建或更新符号链接(例如,在您的情况下为 long_file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.