← All commands
Topic hub PowerShell Equivalents
Windows Linux PowerShell Equivalents Expanded guide Text Processing

Windows PowerShell ForEach-Object equivalent in Linux

Consumes a list or stream and runs another command for each item.

Windows PowerShell ForEach-Object
→
Linux equivalents
Debian/Ubuntu same command
xargs COMMAND
Fedora same command
xargs COMMAND
Arch same command
xargs COMMAND

Overview

What this command does

On Windows, "PowerShell ForEach-Object" is used to run a command for each input item. On Linux, the closest practical mapping shown here is "xargs COMMAND". Consumes a list or stream and runs another command for each item. This reference is grouped under PowerShell Equivalents → Text Processing.

Migration tip: <code>xargs -0</code> safely handles filenames containing spaces and newlines when paired with null-delimited input such as <code>find -print0</code>.

Windows → Linux context

What changes when you use this on Linux?

Equivalent task, different tool

Windows PowerShell ForEach-Object maps to xargs COMMAND for this task. Treat this as a workflow mapping rather than a character-for-character syntax translation.

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.

Command-specific caution

Plain xargs splits on whitespace. Use null-delimited input for arbitrary filenames.

Practical tasks

Common use cases

Run a command for each input item

Consumes a list or stream and runs another command for each item.

printf "%s\n" one two | xargs -n1 echo

Process one item at a time

find . -name "*.tmp" -print0 | xargs -0 rm -v

Process filenames safely

while IFS= read -r line; do printf "%s\n" "$line"; done < file.txt

Use a shell loop

Ready to run

Copyable Linux commands

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

printf "%s\n" one two | xargs -n1 echo
find . -name "*.tmp" -print0 | xargs -0 rm -v
while IFS= read -r line; do printf "%s\n" "$line"; done < file.txt

Walkthrough

Examples with explanations

printf "%s\n" one two | xargs -n1 echo # run a command for each item
find . -name "*.tmp" -print0 | xargs -0 rm -v # handle filenames safely
while IFS= read -r line; do printf "%s\n" "$line"; done < file.txt # process a file line by line

Reference

Common options and variations

Command or optionUse
printf "%s\n" one two | xargs -n1 echoProcess one item at a time
find . -name "*.tmp" -print0 | xargs -0 rm -vProcess filenames safely
while IFS= read -r line; do printf "%s\n" "$line"; done < file.txtUse a shell loop

Distro differences

Debian/Ubuntu vs Fedora vs Arch

Debian/Ubuntu, Fedora and Arch all use "xargs COMMAND" 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 xargs COMMAND Same command on this distribution.
Fedora same command xargs COMMAND Same command on this distribution.
Arch same command xargs COMMAND Same command on this distribution.

Important

What to watch out for

Plain xargs splits on whitespace. Use null-delimited input for arbitrary filenames.

Keep learning

Related PowerShell Equivalents commands