Linux commands : Part 3

Let’s have a look at some of advance commands that we won’t be using frequently but are handy if known.

1) Console output to file
To write output of terminal commands to text file, we can use ‘>’ or ‘tee’.
The ‘>’ followed by file name will create a new or append to existing (with flag) file, where all output will be witten.

mount > mount_info.log

It’ll redirect and write all output to ‘mount_info.log’ file.

mount | tee mount_info.log

It’ll will display command output in terminal and write it to ‘mount_info.log’ file also.
tee : read from standard input and write to standard output and files.

2) System hardware info
To get system hardware information, we can use ‘lshw’ : list hardware command. It’ll display detail informations related to cpu, memory, disk, partition, firmware etc.

sudo lshw

The output will look like this :

description: Portable Computer
product: Inspiron N5110 (To be filled by O.E.M.)
vendor: Dell Inc.
version: Not Specified
serial: 6DR0HP1
width: 64 bits
capabilities: smbios-2.6 dmi-2.6 vsyscall32
configuration: boot=normal chassis=portable sku=To be filled by O.E.M. uuid=44454C4C-4400-1052-8030-B6C04F485031
description: Motherboard
product: 0FXK2Y
vendor: Dell Inc.
physical id: 0
version: A06
description: CPU
product: Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
vendor: Intel Corp.
physical id: 4
bus info: cpu@0
version: Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
serial: To Be Filled By O.E.M.
slot: CPU 1
size: 800MHz
capacity: 800MHz
width: 64 bits
clock: 100MHz

3) Execute multiple commands
To execute multiple commands in single go, we can use a ‘;’ separator. The commands will be executed from left to right in order.

sudo mkdir hello; sudo mv hello ~/Desktop

Create a directory named ‘hello’, then move it to desktop.

4) Unlock locked resource
When we run a package manager and install/update packages then it perform exclusive lock. If we try to run second package manager then we get error message stating :

E: Could not get lock /var/lib/dpkg/lock – open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

To unlock the resouces, we can use ‘fuser’ to find out the runaway process and kill the process that is hogging the resource.

$ sudo fuser -vki /var/lib/dpkg/lock; sudo dpkg --configure -a

fuser : identify processes using files or sockets.
k : kill the process that is still using /var/lib/dpkg/lock.
i : Ask the user for confirmation before killing a process.
Then configure all packages that are yet unpacked and unconfigured.

Leave a comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.