← All commands
Topic hub Terminal & Shell Scripting
Windows Linux Terminal & Shell Scripting Expanded guide Terminal

Windows for equivalent in Linux

Repeats a block of commands for each item in a list, range, or set of files.

Windows for
→
Linux equivalents
Debian/Ubuntu same command
for ... in ...; do ... done
Fedora same command
for ... in ...; do ... done
Arch same command
for ... in ...; do ... done

Overview

What this command does

On Windows, "for" is used to loop over a list or range. On Linux, the closest practical mapping shown here is "for ... in ...; do ... done". Repeats a block of commands for each item in a list, range, or set of files. This reference is grouped under Terminal & Shell Scripting → Terminal.

Migration tip: Bash <code>for</code> loops are much more flexible than Windows batch. Loop over files with globs, sequences with <code>{1..10}</code>, or command output with <code>$(command)</code>.

Windows → Linux context

What changes when you use this on Linux?

Same name, different environment

The basic command name for is familiar on both platforms, but Linux path rules, quoting, permissions and available options can still change the result.

Portable across the compared distros

The Debian/Ubuntu, Fedora and Arch rows use the same command in this mapping. Package availability or defaults can still vary, so check the installed tool version when an option behaves differently.

Practical tasks

Common use cases

Loop over a list or range

Repeats a block of commands for each item in a list, range, or set of files.

for i in {1..10}

Loop from 1 to 10

for f in *.txt

Loop over all .txt files

for i in $(cat list.txt)

Loop over lines in a file

Ready to run

Copyable Linux commands

Review paths, device names, package names and permissions before running any command.

for file in *.log; do
echo "Processing: $file"
gzip "$file"
done
for i in {1..5}; do
echo "Step $i"

Walkthrough

Examples with explanations

# Windows: for %i in (*.txt) do echo %i
for file in *.log; do
  echo "Processing: $file"
  gzip "$file"
done

# Numeric range:
for i in {1..5}; do
  echo "Step $i"
done

Reference

Common options and variations

Command or optionUse
for i in {1..10}Loop from 1 to 10
for f in *.txtLoop over all .txt files
for i in $(cat list.txt)Loop over lines in a file
for ((i=0; i<10; i++))C-style numeric loop

Distro differences

Debian/Ubuntu vs Fedora vs Arch

Debian/Ubuntu, Fedora and Arch all use "for ... in ...; do ... done" for this mapping. The command syntax shown here is portable across the three rows, although installed versions and system defaults can still vary.

DistributionPackage manager / baseEquivalent commandDifference to notice
Debian/Ubuntu same command for ... in ...; do ... done Same command on this distribution.
Fedora same command for ... in ...; do ... done Same command on this distribution.
Arch same command for ... in ...; do ... done Same command on this distribution.

Keep learning

Related Terminal & Shell Scripting commands