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.
The output will look like this :
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 :
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.