Linux Command Line: Loop & execute command for all files in directory

Sometimes we tend to forget that for loops work within the command line as well 🙂

 

An example with du -h to retrieve the file size of each file within the current directory

for x in *; do du -h $x; done

Another example with unzip to unzip each *.zip file within the current directory

for x in *.zip; do unzip $x; done

 

Â