DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
<output cut for brevity>

Not every command is intended to be run with user-level
privileges. You can temporarily upgrade your privileges
by prepending the sudo command before you execute a
command that needs higher-level access. You will often
be prompted for a password to verify that you have the
right to use sudo. You need to be careful when using
sudo, as the whole idea of reduced privileges is to
increase security and prevent average users from
running commands that are dangerous. Use sudo only
when required, such as when you need to kick off an
update for your Linux distribution, which you do by
using the apt-get update command:


$ sudo apt-get update

As mentioned earlier, one of the most powerful features
of BASH is something called piping. This feature allows
you to string together commands. For example, the cat
command displays the contents of a file to the screen.
What if a file contains too much to fit on a single screen?
The cat command will happily spew every character of
the file at the screen until it reaches the end, regardless
of whether you could keep up with it. To address this,
you can pipe the output of cat to the more command to
stream the content from cat to more, which gives you a
prompt to continue one page at a time. To use the piping
functionality, you use the pipe character (|) between
commands, as shown in Example 2-2.


Example 2-2 Output of the cat Command Piped to the
more Command


Click here to view code image


$cat weather.py | more
import json
Free download pdf