18.01.2020 Views

Working with Linux

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The ls subshell returns the files and folders in the current directory and the ls from outside the

subshell will list those individually, showing additional details:

Counting all files and directories in the current directory

Given the fact that commas (,) and periods (.) are hard links that mark the current and parent

directory, we need to count all entries minus these two

This can be done using the expr $(ls -a | wc -l ) - 2 command:

Here, the subshell will return the number of entries (five, in this case). The number we are looking for

is the number of entries minus the special folders ("." and ".."). In order to do arithmetic operations,

we use the expr command, as in our example.

Notice that the subshell contains a pipe. The good thing is that we can combine pipes and subshells in

any way in order to obtain the desired result.

Imagine pipes and subshells as Lego pieces for your shell. They expand way beyond its capabilities

and give you access to new possibilities with infinite combinations. In the end, it all depends on your

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!