Skip to content

Commit

Permalink
Update command line
Browse files Browse the repository at this point in the history
  • Loading branch information
sajith committed Apr 17, 2024
1 parent 07f1b7c commit 81bdff4
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions theme2/SF100/linux-commandline-scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,38 @@ You probably know all this already, so let us skip ahead.

## The command line

<!-- TODO: rewrite this -->

Suppose you want to find all the text files in a directory that
contain a certain pattern, like "hello". How would you do that?
To perform certain kinds of tasks, using the command line is often
quicker and more efficient. You can "chain" or compose separate
programs that do different things together. You can also save fairly
complicated tasks in the form of scripts for later use, and share them
with your colleagues.

Now suppose you want to replace all instances of "hello" with
"bonjour". How would you do that?
For example, you will find documentation for the software installed on
`lnx201` in the directory `/usr/share/doc`. Many of those are named
`README`, or `README.md`, or `README.rst`, or `readme.txt`, or some
such variation. How many such files are there in `/usr/share/doc`?

You can do these things using the Linux command line. You would be
invoking commands like `find` and `grep` and `sed` and `awk`, instead
of using programs with a graphical user interfaces.
We can find that out by using [find] (a program for finding files) and
[wc] (a word count program):

Plenty of software with friendly user interfaces exist, and they are
often easier to use. In order to use the command line, you will have
to be familiar with often arcane tools and memorize stuff.
```{.bash}
[ssasidharan@lnx201 ~]$ find /usr/share/doc/ -iname "readme*" | wc -l
1589
```

Why would you want to use the command line then?
Many of the files in `/usr/share/doc` mention the word "license" or
"LICENSE" or some variation thereof. How many such lines are there?

Because, for certain types of tasks, it is often quick and efficient
to use the command line. You can "chain" or compose separate programs
that do different things together. You can also save fairly
complicated tasks in the form of scripts for later use, and share them
with your colleagues.
```{.bash}
[ssasidharan@lnx201 ~]$ grep -ir license /usr/share/doc/ | wc -l
84089
```

Learning to use the command line well will leave more power on your
hands.

[find]: https://www.man7.org/linux/man-pages/man1/find.1.html
[wc]: https://man7.org/linux/man-pages/man1/wc.1.html

# The shell

Expand Down

0 comments on commit 81bdff4

Please sign in to comment.