NNOPP
NNOPP

Reputation: 107

How to use multiple bash commands in single lines

OS: Linux RedHat

Bash: 3.5

I have 2 commands below to get list of files with status of them and another command for footprint. I want to find the way to combine them together in single line.

Here's my mentioned commands.

  1. find "$PWD" -type f ! -iname '*thumbs.db*' -print0 | xargs -0 stat -c "%y %s %n"

  2. find "$PWD" -type f -print0 | xargs -0 sha1sum -b

Upvotes: 1

Views: 79

Answers (2)

subin
subin

Reputation: 490

You can do this with -exec in find command itself.

find $PWD -type f ! -iname '*thumbs.db*' -exec stat -c "%y %s %n" {} \; -exec sha1sum -b {} \;

Upvotes: 0

helloV
helloV

Reputation: 52433

Will this work? Do a man on xargs.

find $PWD -type f ! -iname '*thumbs.db*' -print0 | xargs -0 -I '{}' sh -c 'stat --printf "%y %s %n " {} ; sha1sum -b {}'

If you do not want the file name repeated twice:

find $PWD -type f ! -iname '*thumbs.db*' -print0 | xargs -0 -I '{}' sh -c 'stat --printf "%y %s %n " {} ; sha1sum -b {} | cut -d\  -f1'

There needs to be 2 blank spaces after d\ in cut command.

Upvotes: 1

Related Questions