-1

How can I find a number of files in a folder, assign it to a variable, then echo that variable, all in one command line?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250

2 Answers2

2
linecount=$(find /folder/name/here/ -type f | wc -l); echo ${linecount}

is the simplest way of doing this. it counts every file in the folder and its sub-folders.

MelBurslan
  • 6,836
  • 2
  • 24
  • 35
0

What comes to my head without using semicolon to break and start a new command is to use Parameter substitution with Command substitution

$ echo ${filecount=$(find . -type f | wc -l)}

Then you can echo the variable again and you can confirm the result.

tachomi
  • 7,372
  • 4
  • 25
  • 45