xargs doesn't use my "ls" alias

The command xargs is only able to run commands, not aliases. GNU parallel, however, is able to run functions:

The command must be an executable, a script, a composed
command, or a function. If it is a function you need to export
-f the function first. An alias will, however, not work (see
why http://www.perlmonks.org/index.pl?node_id=484296).

So I would recommend either:

  • Giving xargs the full path to the version of ls you want to use (or an unambiguous name, perhaps gls depending on how it was installed on your system) or, if your shell allows it,

  • Defining ls as a function (function ls { gls "$@"; }; export -f ls in bash) and using GNU parallel instead of xargs (parallel -j1 if you would like to use a single CPU).


The alias substitution is done by the shell. If the shell tries to call command foo, and there is an alias foo=bar, it's the shell that substitutes the foo by bar here.

The shell only does this for commands. (Otherwise, arguments that happen to be the same as an aliased command would be replaced too.) But your ls here is not run by the shell, but an argument to xargs. Therefore, the shell does not replace it.

Then xargs executes ls, but it does not know about the aliases, so it just runs the first one it finds in the path.

The aliases are internal to the shell and there is no standardized way for a program to read them out.