{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreifv2o6iym4ktjauvjrkj4q7ldrjsnnlzgwvlcqfpmerkokh6zrtcm",
"uri": "at://did:plc:4n6wgsqsqm6q2hjncgwmreey/app.bsky.feed.post/3mf7y5xm64ae2"
},
"path": "/post/46013578",
"publishedAt": "2026-02-19T14:28:17.000Z",
"site": "https://programming.dev",
"tags": [
"Linux",
"cm0002",
"3 comments",
"@thingsiplay@lemmy.ml"
],
"textContent": "submitted by cm0002 to linux\n6 points | 3 comments\n\n> Just wanted to share an alias I have in use and found it useful again. It’s a simple wrapper around `xargs`, which I always forget how to use properly, so I set up an alias for. All it does is operate on each line on stdout.\n>\n> The arguments are interpreted as the command to execute. The only thing to remember is using the `{}` as a placeholder for the input line. Look in the examples to understand how its used.\n>\n>\n> # Pipe each line and execute a command. The \"{}\" will be replaced by the line.\n> #\n> # Example:\n> # cat url.txt | foreach echo download {} to directory\n> # ls -1 | foreach echo {}\n> # find . -maxdepth 2 -type f -name 'M*' | foreach grep \"USB\" {}\n> alias foreach='xargs -d \"\\n\" -I{}'\n>\n>\n> Useful for quickly operating on each line of a file (in example to download from list of urls) or do something with any stdout output line by line. Without remembering or typing a for loop in terminal.\n\nOC by @thingsiplay@lemmy.ml",
"title": "foreach - Bash alias to execute command on each line"
}