while true; do clear echo "=== Page $CURRENT_PAGE of $TOTAL_PAGES ===" list_page $CURRENT_PAGE echo "" echo "[N]ext [P]rev [T]op [L]and (page 1) [Q]uit" read -r choice case $choice in N|n) ((CURRENT_PAGE++)); ((CURRENT_PAGE > TOTAL_PAGES)) && CURRENT_PAGE=$TOTAL_PAGES ;; P|p) ((CURRENT_PAGE--)); ((CURRENT_PAGE < 1)) && CURRENT_PAGE=1 ;; T|t) CURRENT_PAGE=1 ;; L|l) CURRENT_PAGE=1 ;; Q|q) exit 0 ;; esac done
#!/bin/bash # pagels.sh - Paginated listing of RAR files PAGE_SIZE=10 CURRENT_PAGE=1 TOTAL_FILES=$(ls -1 *.rar 2>/dev/null | wc -l) TOTAL_PAGES=$(( (TOTAL_FILES + PAGE_SIZE - 1) / PAGE_SIZE )) filedot to ls land 8 prev rar top
rar x archive.rar Suppose you have a terminal-based or web-based file listing with pagination. You are on page 8, looking at RAR files, and you want to list them, go to the previous page, or return to top – all using ls -style commands. Scenario A: Terminal with Paginated ls Output You have thousands of RAR files in a directory. Typing ls floods the screen. Solution: Use less or more for paging. while true; do clear echo "=== Page $CURRENT_PAGE
list_page() sed -n "$start,$((start + PAGE_SIZE - 1))p" Typing ls floods the screen