Top Linux File Management commands cheat sheet

By mastering file management in Linux and Unix systems you will be able to accomplish tasks more efficiently, boosting your overall productivity when working in the shell. This is a practical guide presenting the top Linux file management commands, complete with examples. This cheat sheet is is designed for system administrators, database admins, and developers alike. The Linux command line ships with plenty of powerful tools enabling you to create, move, organize, search, and do files and directories manipulation with ease.

In this blog post, we’ll be exploring commonly used Linux commands for file/directory management:

  • File system navigation
  • File operations
  • Viewing and editing files
  • Searching of files on Nix systems

Whether you’re navigating your home directory or managing files across servers, these commands form the backbone of efficient Linux and Unix shell-based usage.

1. File System Navigation Linux commands

pwd – Print Working Directory

  • Usage: Displays the current working directory path.
pwd

ls – List Directory Contents

  • Usage: Lists files and directories.
  • Examples:
# Basic listing
ls

# Long format with details
ls -l

# Show hidden files
ls -a

# Human-readable file sizes
ls -lh

# Sort by modification time (newest first)
ls -lt

# Recursive listing of subdirectories
ls -R

# List by file size (largest first)
ls -lS

cd – Change Directory

  • Usage: Changes the current working directory.
  • Examples:
# Navigate to a specific directory
cd /path/to/directory

# Navigate to home directory
cd or cd ~

# Navigate to parent directory
cd ..

# Navigate to previous directory
cd -

# Navigate to a directory with a space in its name
cd "Directory With Spaces"

mkdir – Make Directory

  • Usage: Creates new directories.
  • Examples:
# Create a single directory
mkdir directory_name

# Create nested directories (including parents)
mkdir -p parent/child/grandchild

# Create a directory with specific permissions
mkdir -m 755 directory_name

rmdir – Remove Directory

  • Usage: Removes empty directories.
  • Examples:
# Remove an empty directory
rmdir directory_name

# Remove multiple empty directories
rmdir dir1 dir2

2. File Operations Linux commands

cp – Copy Files/Directories

  • Usage: Copies files and directories.
  • Examples:
# Copy a file
cp source_file destination_file

# Copy a file to a directory
cp file.txt /path/to/directory/

# Copy multiple files to a directory
cp file1.txt file2.txt destination_directory/

# Copy recursively (for directories)
cp -r source_directory/ destination_directory/

# Copy preserving attributes (permissions, timestamps)
cp -p source_file destination_file

# Interactive mode (asks before overwriting)
cp -i source_file destination_file

# Verbose mode (shows what's being copied)
cp -v source_file destination_file

mv – Move/Rename Files

  • Usage: Moves or renames files and directories.
  • Examples:
# Rename a file
mv old_filename new_filename

# Move a file to a different directory
mv file.txt /path/to/directory/

# Move multiple files to a directory
mv file1.txt file2.txt destination_directory/

# Interactive mode (asks before overwriting)
mv -i source_file destination_file

# Move only if source is newer than destination
mv -u source_file destination_file

rm – Remove Files/Directories

  • Usage: Deletes files and directories.
  • Examples:
# Remove a file
rm filename

# Remove multiple files
rm file1 file2

# Remove recursively (for directories)
rm -r directory_name

# Force removal (no confirmation)
rm -f filename

# Remove directory and all contents (force + recursive)
rm -rf directory_name

# Interactive mode (asks before removal)
rm -i filename

touch – Create or Update Files

  • Usage: Creates empty files or updates file timestamps.
  • Examples:
# Create an empty file
touch new_file.txt

# Create multiple files
touch file1.txt file2.txt

# Update timestamp without modifying content
touch existing_file.txt

# Set specific timestamp (using date format YYYYMMDDhhmm)
touch -t 202301011200 file.txt
  • Usage: Creates hard or symbolic links between files.
  • Examples:
# Create a symbolic (soft) link
ln -s original_file link_name

# Create a hard link
ln original_file link_name

# Create a symbolic link to a directory
ln -s /path/to/directory link_name

3. File Viewing and Editing Linux commands

cat – Concatenate and Display Files

  • Usage: Displays file contents, concatenates files.
  • Examples:
# Display file contents
cat filename.txt

# Display multiple files
cat file1.txt file2.txt

# Display with line numbers
cat -n filename.txt

# Concatenate files and write to a new file
cat file1.txt file2.txt > combined.txt

# Display non-printing characters
cat -A filename.txt

NB: The tac command is the reverse of cat – it prints files in reverse order, starting with the last line.

less – Paginated File Viewing

  • Usage: Views file contents page by page.
  • Examples:
# View a file
less filename.txt

# Open with line numbers
less -N filename.txt

# Open at a specific line number
less +100 filename.txt

# Search for text (press /)
# Type '/pattern' and press Enter

# Navigate within less:
# Space/Page Down: Next page
# b/Page Up: Previous page
# g: Go to start of file
# G: Go to end of file
# q: Quit

head – View Beginning of Files

  • Usage: Displays the beginning of files.
  • Examples:
# Show first 10 lines (default)
head filename.txt

# Show first N lines
head -n 20 filename.txt

# Show first N bytes
head -c 100 filename.txt

# Show all but the last N lines
head -n -5 filename.txt

tail – View End of Files

  • Usage: Displays the end of files.
  • Examples:
# Show last 10 lines (default)
tail filename.txt

# Show last N lines
tail -n 20 filename.txt

# Follow file updates in real-time (useful for logs)
tail -f /var/log/syslog

# Show last N bytes
tail -c 100 filename.txt

# Start output from line N
tail -n +100 filename.txt

nano – Simple Text Editor

  • Usage: Basic text editor for file creation and modification.
  • Examples:
# Open or create a file
nano filename.txt

# Open with cursor at specific line and column
nano +10,5 filename.txt

# Open in read-only mode
nano -v filename.txt

# Common nano shortcuts:
# Ctrl+O: Save
# Ctrl+X: Exit
# Ctrl+K: Cut line
# Ctrl+U: Paste
# Ctrl+W: Search
# Ctrl+_: Go to line number

vim – Advanced Text Editor

  • Usage: Powerful, modal text editor.
  • Examples:
# Open or create a file
vim filename.txt

# Open in read-only mode
vim -R filename.txt

# Open at specific line number
vim +100 filename.txt

# Open multiple files in tabs
vim -p file1.txt file2.txt

# Basic vim modes and commands:
# i - Insert mode
# Esc - Command mode
# :w - Save
# :q - Quit
# :wq - Save and quit
# :q! - Force quit without saving
# dd - Delete line
# yy - Copy line
# p - Paste
# /pattern - Search for pattern

4. File Searching and Matching Linux commands

find – Find Files and Directories

  • Usage: Searches for files and directories based on various criteria.
  • Examples:
# Find files by name
find /path/to/search -name "filename.txt"

# Find files by wildcard pattern
find /path/to/search -name "*.log"

# Find case-insensitive
find /path/to/search -iname "*.LOG"

# Find directories only
find /path/to/search -type d -name "dir_name"

# Find files only
find /path/to/search -type f -name "file_pattern"

# Find files modified in the last 7 days
find /path/to/search -mtime -7

# Find files larger than 100MB
find /path/to/search -size +100M

# Find and delete matching files (use with caution!)
find /path/to/search -name "temp*.txt" -delete

# Find and execute a command on each file
find /path/to/search -name "*.txt" -exec chmod 644 {} \;

# Find empty files
find /path/to/search -type f -empty

grep – Search Text Within Files

  • Usage: Searches for patterns in files using regular expressions.
  • Examples:
# Basic search in a file
grep "pattern" filename.txt

# Search case-insensitive
grep -i "pattern" filename.txt

# Search recursively in directories
grep -r "pattern" /path/to/directory

# Show line numbers with matches
grep -n "pattern" filename.txt

# Show only filenames with matches
grep -l "pattern" file1.txt file2.txt

# Count matches
grep -c "pattern" filename.txt

# Show context around matches (3 lines before and after)
grep -A 3 -B 3 "pattern" filename.txt

# Use regular expressions
grep -E "pattern1|pattern2" filename.txt

# Invert match (show non-matching lines)
grep -v "pattern" filename.txt

# Search for whole words only
grep -w "word" filename.txt

locate – Find Files by Name

  • Usage: Quickly finds files using a pre-built database.
  • Examples:
# Basic search
locate filename

# Case-insensitive search
locate -i filename

# Limit results count
locate -l 10 filename

# Update the locate database
sudo updatedb

which – Locate Executable

  • Usage: Shows the full path of shell commands.
  • Examples:
# Find location of a command
which command_name

# Find all locations of a command
which -a command_name

whereis – Locate Binary, Source, and Manual Files

  • Usage: Locates binary, source, and man page files for commands.
  • Examples:
# Find locations for a command
whereis command_name

# Find only binary files
whereis -b command_name

# Find only manual pages
whereis -m command_name

Conclusion

We hope this guide was effective in covering essential commands for managing files and directories in Unix-based systems. For more comprehensive coverage, stay tuned for our upcoming cheat sheet on “Linux Shell Administration” quick reference. This will cover advanced day-to-day administrative topics and commands in detail.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

PHP 8.4 is available for production use with lots of new features, improvements and deprecated ones as well. In this […]

In this guide we’ll explore installation of Julia Programming Language on CentOS | RHEL 9 systems. Julia is dynamically typed, […]

Adobe Illustrator is a popular vector illustration application that one can use to capture their creative ideas. Designers use it […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.