Let's say I have a newline-separated list of file paths from a previous command that I can copy to clipboard. What's the easiest way to paste this list to feed it into another command in a shell? Preferably, so that I can still edit the list before executing the command. E.g., I want to rm
some subset of the untracked files returned by git status
.
Asked
Active
Viewed 209 times
-2

ykaganovich
- 149
- 3
- 8
-
I'm getting downvotes and no help... I guess this belongs on StackOverflow instead? – ykaganovich Jul 30 '20 at 03:33
2 Answers
1
git has a command for deleting untracked files.
git clean --exclude=<pattern> --dry-run # Remove --dry-run to delete for real
git clean --interactive # Or, interactive mode is a prompt version
Or, a more general solution is to pipe delimited strings into xargs
, to batch run some command (rm
) on the input. Although, this requires that stdin only contains the list of files. For git, this implies using plumbing commands designed to be parsed. In practice, git clean
is easier to use for this specific use case.

John Mahowald
- 32,050
- 2
- 19
- 34
-
Good tip on the `git clean` parameters. But I was hoping for something more generic... – ykaganovich Jul 30 '20 at 04:52
-
I mentioned a more generic way via `xargs`. A common pattern is to generate (new line) delimited strings on stdout, and pipe those into `xargs` to do a thing with every input. (No cut and paste needed.) But I am not going to bother with generating that list myself with git "plumbing" commands, when a user friendly "porcelain" command to do the specific thing already exists. – John Mahowald Jul 30 '20 at 16:27
0
So far, the best answer I found is
cat | xargs rm
I didn't realize it, but after Ctrl-D, it will pipe it as expected to the target command.

ykaganovich
- 149
- 3
- 8