Get just the number of lines of a file without the filename when using the wc command

wc -l < path/to/file

September 9, 2023bashoneliners


wc -l path/to/file prints the number of lines in the specified file, and also the file path, for example if /etc/resolv.conf has 4 lines in it, then the output of wc -l /etc/resolv.conf would be:

4 /etc/resolv.conf

wc -l < path/to/file uses input redirection (the < operator) to pass the content of a file to wc on standard input, without the filename, and the output this way will be simply: