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

Enhancing Unix Proficiency: A Deeper Look at the 'Sleep' Command and Signals

Hashtags: #Unix #SleepCommand #Signals #UnixTutorial #ProcessManagement In the world of Unix commands, there are often tools that, at first ...