➖Linux Utilities
This page demonstrates some of the most used Linux command line utilities and their usage.
Parallel Processing
parallel
Process Linux commands in parallel. Single-instance execution is time-consuming. Some examples where parallel command can be leveraged:
file sizes in a directory
Deleting files
#To get the sizes of objects
parallel -j 20 du -sh ::: *
#To remove directories in parallel
parallel -j 20 rm -rf ::: *
#use find max depth 2 and parallel utils
find . -max-depth 2 -type d | parallel -j 10 rm -rf ::: {}
pixz
pixz is a parallel compression tool. It compresses huge files in less time using parallel execution. It uses xz compression.
# Compress huge files parallelly
tar --owner=root --group=root -cf - . | pixz > ../<your>.tar.xz
flock
Manage locks from shell scripts. It can be used to ensure that only one process of a command is running at a time. This is particularly useful in situations where multiple processes may be trying to execute the same command simultaneously, and you want to ensure that only one of them succeeds.
flock <path to .lock> --command my-command
Process Management
kill
kill is a command utility for handling process ops. It is important to clean up all processes invoked by the parent process, or else it leads to zombie processes. Users have to explicitly kill the child processes before termination.
# Kill process
kill -9 <pid>
# Send SIGTERM to a process
kill -15 <pid>
# Kill all child process
kill -9 -- -GPID
nohup
nohup (No Hang Up) is a command in Linux systems that runs the process even after logging out from the shell/terminal.
nohup command [command-argument ...]
Misc
fakeroot
Imagine that you are a developer/package maintainer, etc. working on a remote server. You want to update the contents of a package and rebuild it, download and customize a kernel from kernel.org and build it, etc. While trying to do those things, you'll find out that some steps require you to have root
rights (UID
and GID
0) for different reasons (security, overlooked permissions, etc). But it is not possible to get root
rights, since you are working on a remote machine (and many other users have the same problem as you). This is what exactly fakeroot
does: it pretends an effective UID
and GID
of 0 to the environment which requires them.
$ fakeroot
# echo "Wow I have root access" > root.tst
# ls -l root.tst
-rw-rw-r-- 1 root root 23 Oct 25 12:13 root.tst
# ls -l /root
ls: cannot open directory /root: Permission denied
# exit
$ ls -l root.tst
-rw-rw-r-- 1 ubuntu ubuntu 23 Oct 25 12:13 root.tst
Last updated