Execute command for every file in the current dir

Perhaps xargs, which reinvokes the command specified after it for each additional line of parameters received on stdin...

ls -1 $FOLDER | xargs du

But, in this case, why not...

du *

...? Or...

for X in *; do
    du $X
done

(Personally, I use zsh, where you can modify the glob pattern to only find say regular files, or only directories, only symlinks etc - I'm pretty sure there's something similar in bash - can dig for details if you need that).

Am I missing part of your requirement?


The find command will let you execute a command for each item it finds, too. Without further arguments it will find all files and folders in the current directory, like this:

$ find -exec du -h {} \;

The {} part is the "variable" where the match is placed, here as the argument to du. \; ends the command.

Tags:

Linux

Bash