Linux Basics: File Viewing and Management Commands

1. touch — Create Empty Files or Update Timestamps

Creates an empty file or updates a file’s timestamps.

Syntax

touch [options] <file>

Common Usage

touch file.txt # Create an empty …


This content originally appeared on DEV Community and was authored by yuna song

1. touch — Create Empty Files or Update Timestamps

Creates an empty file or updates a file's timestamps.

Syntax

touch [options] <file>

Common Usage

touch file.txt                    # Create an empty file
touch file1.txt file2.txt         # Create multiple files
touch existing.txt                # Update timestamps
touch file{1..5}.txt              # Create file1.txt ~ file5.txt

Useful Options

touch -a file.txt                 # Update access time (atime)
touch -m file.txt                 # Update modification time (mtime)
touch -c file.txt                 # Do not create the file if it doesn't exist
touch -d "2026-07-04 12:30:00" file.txt
touch -t 202607041230 file.txt
touch -r source.txt target.txt    # Copy timestamps from another file

Timestamp Types

  • atime : Last access time
  • mtime : Last modification time
  • ctime : Last metadata (status) change

View timestamps:

stat file.txt

2. cat — Display and Concatenate Files

Displays file contents or combines multiple files.

Syntax

cat [options] <file>

Common Usage

cat file.txt
cat file1.txt file2.txt
cat file1.txt file2.txt > combined.txt

Create or Append Files

cat > new_file.txt        # Create or overwrite
cat >> file.txt           # Append to an existing file

Press Ctrl + D to save and exit.

Useful Options

cat -n file.txt           # Show line numbers
cat -b file.txt           # Number non-empty lines only
cat -s file.txt           # Squeeze multiple blank lines
cat -E file.txt           # Show end-of-line markers ($)
cat -A file.txt           # Show all non-printing characters

Notes

Avoid using cat for very large files. Instead, use:

head file.txt
tail file.txt
less file.txt

3. less — View Large Files Efficiently

Displays large files one screen at a time without loading the entire file into memory.

Syntax

less file.txt

Exit with:

q

Navigation

Key Action
j / ↓ Next line
k / ↑ Previous line
Space / PgDn Next page
b / PgUp Previous page
g First line
G Last line

Search

/keyword      Search forward
?keyword      Search backward
n             Next match
N             Previous match

Useful Options

less -N app.log           # Show line numbers
less -i app.log           # Case-insensitive search
less +F app.log           # Follow file like tail -f
ps -ef | less             # View command output page by page

Notes

  • Press Ctrl + C to exit follow mode (+F).
  • Press Shift + F to resume following.

4. head — Display the Beginning of a File

Prints the first part of a file.

By default, head displays the first 10 lines.

Syntax

head [options] <file>

Common Usage

head file.txt
head -n 5 file.txt
head -5 file.txt
head -c 20 file.txt

Useful Options

head -q file1.txt file2.txt     # Hide file headers
head -v file.txt                # Always show file header

Practical Examples

Display lines 11–15:

head -n 15 system.log | tail -n 5

Show the five most recently modified files:

ls -lt | head -n 6

5. tail — Display the End of a File

Prints the last part of a file.

By default, tail displays the last 10 lines.

Syntax

tail [options] <file>

Common Usage

tail file.txt
tail -n 5 file.txt
tail -5 file.txt
tail -n +20 file.txt

Real-Time Monitoring

tail -f app.log              # Follow file updates
tail -F app.log              # Continue following after log rotation
tail -f app.log --pid=1234   # Stop when process exits

Stop monitoring with Ctrl + C.

Useful Options

tail -n 30 file.txt
tail -c 100 file.txt

Practical Examples

Monitor only error messages:

tail -f app.log | grep "ERROR"

Notes

  • -f follows a file as it grows.
  • -F is preferred for log files because it handles log rotation automatically.


This content originally appeared on DEV Community and was authored by yuna song


Print Share Comment Cite Upload Translate Updates
APA

yuna song | Sciencx (2026-07-07T14:05:26+00:00) Linux Basics: File Viewing and Management Commands. Retrieved from https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/

MLA
" » Linux Basics: File Viewing and Management Commands." yuna song | Sciencx - Tuesday July 7, 2026, https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/
HARVARD
yuna song | Sciencx Tuesday July 7, 2026 » Linux Basics: File Viewing and Management Commands., viewed ,<https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/>
VANCOUVER
yuna song | Sciencx - » Linux Basics: File Viewing and Management Commands. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/
CHICAGO
" » Linux Basics: File Viewing and Management Commands." yuna song | Sciencx - Accessed . https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/
IEEE
" » Linux Basics: File Viewing and Management Commands." yuna song | Sciencx [Online]. Available: https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/. [Accessed: ]
rf:citation
» Linux Basics: File Viewing and Management Commands | yuna song | Sciencx | https://www.scien.cx/2026/07/07/linux-basics-file-viewing-and-management-commands/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.