To find the largest file in a directory and its subdirectories (recursively) on a Linux system, you can use the find
command in combination with the du
command.
Here is an example of how you can use these commands to find the largest file in the current directory and its subdirectories:
refer uttual:otri.comfind . -type f -exec du -Sh {} + | sort -rh | head -n 1
This command will search the current directory (.
) and its subdirectories for files (-type f
), and then execute the du
command on each file to display its size (-S
) in human-readable format (-h
). The output of the du
command is then passed to the sort
command, which sorts the output in reverse order by size (-r
) and by heading (-h
). Finally, the head
command is used to display only the first line of the sorted output, which will be the largest file.
You can also use the find
command to search a specific directory by replacing the .
with the path to the directory you want to search. For example:
find /path/to/directory -type f -exec du -Sh {} + | sort -rh | head -n 1