Linux Format - UK (2019-12)

(Antfer) #1
14 LXF257 December 2019 http://www.linuxformat.com

ANSWERS


text files. The --bytes option tells it to use
binary data instead. Normally tail will
output the last x bytes (or lines) of a file.
Prefixing the number with + means ‘start
with byte x’ instead. Depending on how
you are counting bytes, you may need to
pass ‘x+1’ to tail.
You usually see dd mentioned when
copying image data to disks, but it is far
more capable than that.
$ dd if=BinaryData.bin bs=X skip=1 |
<program>
This should do what you want. The bs
option tells dd to copy data in blocks of

that size – the default is 512 bytes. The
skip tells it to skip the first block, so you
get all but the first x bytes. As there is no
of (output file) option, dd sends its output
to stdout, which is then piped to your
program. If the data file is static, but you
want to use the stripped version more than
once, you could use the split command to
create a new file without the first x bytes:
$ split --bytes=X BinaryData.bin
This will split the file into x-sized
chunks, with numeric suffixes. If x is more
than half the size of the original file,
BinaryData.bin01 is all you need,

otherwise you need to join the other pieces
back together:
$ rm BinaryData.bin
$ cat BinaryData.bin?? >NewBinaryData.
bin
This may be a cumbersome or elegant
approach, depending on your needs, but
you can also output to a file with tail or dd.
Whichever you use is a matter of personal
preference, all will do what you need.

Q


Persistent Peppermint
I installed Peppermint from the
DVD to the hard disk on my laptop, a
Samsung R60 Plus, but when I press
Shut Down it won’t power off. It says
shut down, and then nothing.
Wolfgang

A


Ah, the curse of the pretty splash
screen. These boot and shutdown
screens provide a more friendly-looking
alternative to the traditional screen of
scrolling text messages. However, those
messages tell you what is happening, or
not happening, during boot and shutdown.
So the first step is to get rid of the screen.
You can usually do this by pressing Esc
when it appears. If that doesn’t work, edit
the boot options from the initial boot
menu, usually by pressing E, and remove
and references to splash or quiet – we
want splash-free and noisy. When you
have done this, your computer will still
stop during the shutdown process, but you
will be able to see what it was trying to do
when it stopped. This could be unmounting
a network share, a problem if the network
is brought down before shares are
unmounted, or shutting down a service
that doesn’t want to stop.
Once you have identified the culprit, a
quick trip to your preferred search engine
with the relevant message will usually
provide the solution. One situation that
sometimes arises is that the computer
goes through the boot process and even
displays “Shutting down” or “Powering
off”, but doesn’t switch off. In this case
rebooting works – only shutting-down fails.
One possible solution to this is to edit the
boot options as above and add acpi=force
or noacpi. If one of those works, you can
edit /etc/default/grub and add the
option to the GRUB_CMDLINE_LINUX_
DEFAULT setting and run:
$ sudo update-grub
to make the change permanent (see page
72 for more about using GRUB).
If rebooting works, the more kludgy
solution is to reboot, then hit the power
switch when the BIOS screen appears.
At this point there is no operating system
loaded and no disks mounted, so a hard
shutdown can do no harm.

QUICK REFERENCE TO... MULTI COMMANDS


When using the command line, there
are often occasions when you need to
run several commands in sequence –
this can also happen when using a GUI,
but the solution is nowhere near as
simple. The classic example of this is
the standard method of compiling
software from source, this requires you
to run ./configure (possibly with some
arguments) followed by make then
make install.
Each of these steps can take
anywhere from a few seconds to many
hours, depending on the complexity of
the code and speed of your machine.
Waiting for one to complete before
running the next is inefficient, so
instead you could do:
./configure; make; make install
The semicolons cause the commands
to be executed in sequence, as if you
had run each one individually. Some of
you may have already noticed a
potential problem here: what happens
if ./configure or make fails? Will the
subsequent commands try to execute
anyway? The answer is yes, which

would hide any error messages in the
following output, and you may not even
realise there was an error until you try
to use the program. A safer way of
running these commands is:
./configure && make && make install
&& is a logical operator. This
command line actually means ‘if
./configure is true and make is true
and make install is true’. Fortunately
for us, the shell determines if a
command is true by running it to see if
it gives any errors. If a command fails,
there is no point in running the next one
because the test has already failed, so
joining commands with && runs them
in sequence, but stops as soon as one
of them returns an error, meaning we
no longer need to babysit the shell.
The companion command to &&
is || , which means ‘or’. So in
command1 || command
command2 only runs if command
fails. This is less useful in the interactive
shell, but is used often in shell scripts:
somecommand1 || echo “Something
broke!”

Failure to shut down properly can often be caused by the hardware’s ACPI implementation.

14 LXF257December 2019 1112Decmbr 09Go2t 9


ANSWERS


text files. The --bytes option tells it to use
binary data instead. Normally tail will
output the last x bytes (or lines) of a file.
Prefixing the number with + means ‘start
with byte x’ instead. Depending on how
you are counting bytes, you may need to
pass ‘x+1’ to tail.
You usually see dd mentioned when
copying image data to disks, but it is far
more capable than that.
$ dd if=BinaryData.bin bs=X skip=1 |



This should do what you want. The bs
option tells dd to copy data in blocks of
that size – the default is 512 bytes. The
skip tells it to skip the first block, so you
get all but the first x bytes. As there is no
of (output file) option, dd sends its output
to stdout, which is then piped to your
program. If the data file is static, but you
want to use the stripped version more than
once, you could use the split command to
create a new file without the first x bytes:
$ split --bytes=X BinaryData.bin
This will split the file into x-sized
chunks, with numeric suffixes. If x is more
than half the size of the original file,
BinaryData.bin01 is all you need,

otherwise you need to join the other pieces
back together:
$ rm BinaryData.bin
$ cat BinaryData.bin?? >NewBinaryData.
bin
This may be a cumbersome or elegant
approach, depending on your needs, but
you can also output to a file with tail or dd.
Whichever you use is a matter of personal
preference,allwilldowhatyouneed.

Q


Persistent Peppermint
I installed Peppermint from the
DVD to the hard disk on my laptop, a
Samsung R60 Plus, but when I press
Shut Down it won’t power off. It says
shut down, and then nothing.
Wolfgang

A


Ah, the curse of the pretty splash
screen. These boot and shutdown
screens provide a more friendly-looking
alternative to the traditional screen of
scrolling text messages. However, those
messages tell you what is happening, or
not happening, during boot and shutdown.
So the first step is to get rid of the screen.
You can usually do this by pressing Esc
when it appears. If that doesn’t work, edit
the boot options from the initial boot
menu, usually by pressing E, and remove
and references to splash or quiet – we
want splash-free and noisy. When you
have done this, your computer will still
stop during the shutdown process, but you
will be able to see what it was trying to do
when it stopped. This could be unmounting
a network share, a problem if the network
is brought down before shares are
unmounted, or shutting down a service
that doesn’t want to stop.
Once you have identified the culprit, a
quick trip to your preferred search engine
with the relevant message will usually
provide the solution. One situation that
sometimes arises is that the computer
goes through the boot process and even
displays “Shutting down” or “Powering
off”, but doesn’t switch off. In this case
rebooting works – only shutting-down fails.
One possible solution to this is to edit the
boot options as above and add acpi=force
or noacpi. If one of those works, you can
edit /etc/default/grub and add the
option to the GRUB_CMDLINE_LINUX_
DEFAULT setting and run:
$ sudo update-grub
to make the change permanent (see page
72 for more about using GRUB).
If rebooting works, the more kludgy
solution is to reboot, then hit the power
switch when the BIOS screen appears.
At this point there is no operating system
loaded and no disks mounted, so a hard
shutdown can do no harm.

QUICKREFERENCETO...MULTICOMMANDS


When using the command line, there
are often occasions when you need to
run several commands in sequence –
this can also happen when using a GUI,
but the solution is nowhere near as
simple. The classic example of this is
the standard method of compiling
software from source, this requires you
to run ./configure (possibly with some
arguments) followed by make then
make install.
Each of these steps can take
anywhere from a few seconds to many
hours, depending on the complexity of
the code and speed of your machine.
Waiting for one to complete before
running the next is inefficient, so
instead you could do:
./configure; make; make install
The semicolons cause the commands
to be executed in sequence, as if you
had run each one individually. Some of
you may have already noticed a
potential problem here: what happens
if ./configure or make fails? Will the
subsequent commands try to execute
anyway? The answer is yes, which

would hide any error messages in the
following output, and you may not even
realise there was an error until you try
to use the program. A safer way of
running these commands is:
./configure && make && make install
&& is a logical operator. This
command line actually means ‘if
./configure is true and make is true
and make install is true’. Fortunately
for us, the shell determines if a
command is true by running it to see if
it gives any errors. If a command fails,
there is no point in running the next one
because the test has already failed, so
joining commands with && runs them
in sequence, but stops as soon as one
of them returns an error, meaning we
no longer need to babysit the shell.
The companion command to &&
is || , which means ‘or’. So in
command1 || command
command2 only runs if command
fails. This is less useful in the interactive
shell, but is used often in shell scripts:
somecommand1 || echo “Something
broke!”

Failure to shut down properly can often be caused by the hardware’s ACPI implementation.
Free download pdf