diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index d3f13421d6..5e83f47705 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -254,7 +254,8 @@ ErrorOr serenity_main(Main::Arguments args) while (it.has_next()) { auto path = it.next_full_path(); if (!FileSystem::is_directory(path)) { - auto key = user_has_specified_files ? path.view() : path.substring_view(base.length() + 1, path.length() - base.length() - 1); + // Remove leading './' when `grep -r` was run without any specified paths. + auto key = user_has_specified_files ? path.view() : path.substring_view(base.length() + 1); if (auto result = handle_file(key, true); result.is_error() && !suppress_errors) warnln("Failed with file {}: {}", key, result.release_error());