# Linux Utilities

### 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&#x20;
* Deleting files&#x20;

```bash
#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.

```bash
# 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.

```bash
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.&#x20;

```bash
# 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.&#x20;

```bash
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.

```bash
$ 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://explore-vineeth.gitbook.io/mywiki/programming/tools/linux-utilities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
