Thursday, December 21, 2023

Display both head and tail of a file or a ls command output or anyother command

Following Commands will basically show head and tail of a command or a file at once, basically it will sho the start and end of a file or a command.

Combining head and tail using cat

    cat filename | head && echo "..." && cat filename | tail

Using sed command to display both head and tail:

    sed -n -e '1,10p' -e '$p' filename

To view both the head and tail of the output from an ls command, you can combine head and tail commands together with a pipe (|) to display both at the same time.

    ls -l | { head; echo "..."; tail; }

    ls -l > temp_file && { head temp_file; echo "..."; tail temp_file; } && rm temp_file


No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

🎬 Installing Kali Linux on a Virtual Machine | Step-by-Step Guide 🐧

🎬 In this video, I’ll show you how to install Kali Linux 🐧 inside a Virtual Machine step-by-step! Whether you're a beginner curious...