Last Updated: January 23, 2019
· nvie

map function in shell

The following defines an intuitive "map" function for use in shell scripts or on the command line:

$ alias map="xargs -n1"

This takes a command which will be invoked on every line from stdin. A useful example: finding all directories that contain a certain file:

$ find * -name | map dirname

3 Responses
Add your response

Erm... use a wildcard in the path argument of find?

over 1 year ago ·

@avdleeuw In this case, I don't want the ./ prefixes on the output, so yes. I wouldn't use them in an uncontrolled environment :)

over 1 year ago ·

If you like map, have a look at GNU Parallel

over 1 year ago ·