Home > Bash, Linux, Useful commands > Run command on each file in directory

Run command on each file in directory

Most useful when you have many files in directory and bash doesn’t want to cooperate:

-bash: -: Argument list too long

First one:

for file in *; do ls -al "$file"; done

where * could be a file name or extension ex.: *.jpg

And much more easy to remember:

find . -exec ls -al {} \;
Categories: Bash, Linux, Useful commands
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: