Linux CLI HowTo 3 🐧 How To ls file and less commands

3 – How-To: ls, file and less commands
How to List All Files in /var Directory
Steps:
- Open terminal
- Type
ls /varand press Enter - Observe the output showing all files and directories in /var
Why: Shows system-wide files and directories that are typically not user-specific
How to List Files in Both /var and Home Directory
Steps:
- Open terminal
- Type
ls /var ~and press Enter - Notice how it shows contents of both directories side by side
Why: Demonstrates how to view multiple directory contents simultaneously
How to Show Detailed File Information in Home Directory
Steps:
- Open terminal
- Type
ls ~ -land press Enter - Examine the output showing permissions, ownership, size, and dates
Why: Provides comprehensive file information including access rights and metadata
How to Show All Files Including Hidden Ones in Home Directory
Steps:
- Open terminal
- Type
ls ~ -laand press Enter - Notice how hidden files (starting with dots) are now visible
Why: Reveals complete user directory contents including configuration files
How to List Files by Modification Time in Home Directory
Steps:
- Open terminal
- Type
ls ~ -ltand press Enter - Observe files sorted from newest to oldest
Why: Helps identify recently modified files for troubleshooting or tracking changes
How to Get Help Information for ls Command
Steps:
- Open terminal
- Type
ls --helpand press Enter - Read the available options and usage information
Why: Provides quick reference for all ls command options without needing external documentation
How to Check File Type of All Files in Current Directory
Steps:
- Open terminal in target directory
- Type
file *and press Enter - Observe file type descriptions for each item
Why: Identifies whether files are text, binary, images, or other types without opening them
How to Check File Type of Specific Directory
Steps:
- Open terminal
- Type
file Downloadsand press Enter - See the file type description for the Downloads directory
Why: Quickly determines if a directory is actually a file or directory
How to Get Brief File Type Information
Steps:
- Open terminal
- Type
file file -band press Enter - Notice the concise output without full path information
Why: Provides clean, simple file type identification without verbose path details
How to Check MIME Type of a File
Steps:
- Open terminal
- Type
file filename -iand press Enter - View the MIME type (e.g., text/plain, image/jpeg)
Why: Useful for web development, file handling, or identifying file formats for applications
How to Display Content of /etc/passwd File One Page at a Time
Steps:
- Open terminal
- Type
less /etc/passwdand press Enter - Use arrow keys to scroll, PgUp/PgDn for pages, or ‘q’ to quit
Why: Allows safe viewing of large system files without overwhelming the terminal output
How to Jump to Specific Line in a File Using less
Steps:
- Open terminal
- Type
less /etc/passwdand press Enter - Type
25gthen Enter to jump to line 25 - Press ‘q’ to quit
Why: Quickly navigate to specific information within large text files without scrolling manually
How to View File Contents with Line-by-Line Navigation
Steps:
- Open terminal
- Type
less /etc/passwdand press Enter - Use Up/Down arrow keys to move one line at a time
- Press ‘q’ to quit when done
Why: Allows precise navigation through file content for detailed examination
How to View File Contents with Page-by-Page Navigation
Steps:
- Open terminal
- Type
less /etc/passwdand press Enter - Use PgUp/PgDn keys to move one page at a time
- Press ‘q’ to quit
Why: Efficient way to browse through large files without overwhelming screen display
How to Navigate to Beginning and End of File
Steps:
- Open terminal
- Type
less /etc/passwdand press Enter - Press Home key to go to beginning of file
- Press End key to go to end of file
- Press ‘q’ to quit
Why: Quick access to start and end of files for checking header/footer information