# Miscellaneous Cheat Sheet

This is a collection of workflows, commands, or bash scripts solving a series of common use cases. These instructions use linux commands and directory structures.

## Apply Git Patch Directly from Remote Server

Many git hosts offer you automatic summaries of pull requests in the form of diffs or patches (simply append .diff or patch to your commit link).

To apply such patches directly (without having to manually download the files) you can run the following command:

The --ignore-space-change and --ignore-whitespace are not needed, but they save you the pain of patches failing due to unmatching white spaces.

## Copy Remote Folders

There are a number of commands which you can use to transfer files and folders remotely via the command line interface (CLI). On of them is scp (which stands for secure copy) and uses the SSH protocol.

Keep in mind that /path/to/your/files is an absolute path. If you do not have root access on your server, use a home/directory/relative/path (without the initial slash).

## List Files Versioned with Git

To get a list of all the files in your git repository (excluding untracked files from your repo directory), run the following:

## Batch Rotate Images

There are a number of ways to do this. One would be via the GIMP script-fu, which is awfully complicated to use (as an example of how you would batch rotate files with script-fu, you can see this thread on StackOverflow).

If your image happens to be in the JPEG file format, however, you can easily rotate it with a library function called jpegtran. This function ships with the libjpeg-turbo package, which you already have installed if your system is capable of viewing JPEG format files. To use this function simply run:

An other option is via ImageMagick, which is easy, but which would require you to download software you may otherwise not need. The respective command would be:

## Paste the last 100 lines from some output

Sometimes your output is too large to paste in whole. If the part of the output your are interested in is located close to the end, tail can be of good use.

If you want to paste from a file, run:

and if you want to pipe some output directly from a command (e.g. dmesg) to a bastebin, run:

## Change file permissions recursively

This command grants all users read permissions to the folder, subfolders, and all files therein - in addition to whatever permissions are already set. Note that chmod may need to be run as root.

Or better yet, use octal to accurately define what permissions the owner, the group, and everyone else has:

## Remove .orig files from (Git) folder

Occasionally Git merges may leave you with residual .orig files which clutter your repository. This question on StackOverflow exemplifies how the issue may arise. To solve the issue run the following command from your repository root.

## Text lookup in folder

The grep command with the -r option lets you find the occurrences of a string inside all files within a folder and all its subfolders.

## Nested Markdown/reST Syntax

Use the following too get a bold (or italic, etc.) link via markdown:

In reStructured Text (reST) this feature is on the to do list, but not yet available.

## OpenRC: See and edit runlevels

This assumes you are using OpenRC and will not work on systems set up with systemd. Note that rc-update may need to be run as root.

## Convert .flac to .mp3

Here you will need ffmpeg - a command line program which ships with the FFmpeg libraries, and comes together with media playback dependencies on many linux distros (meaning that you probably have it installed already).

## Rsync sub-directory

Run from the directory containing DIR. DIR is the directory to be synced and created if needed on the remote host. Do not use trailing slashes after the DIR directory name or all the contents will get dumped directly into your/remote/path/:

## Mass copy files without overwriting

Sometimes you want to copy all files in one (large) directory to another - which already contains some of these files. Usually using a file manager of cp (whithout arguments) for such a task can prove quite tedious. Here is an variant using rsync (recommended):

And alternative using the --no-clobber argument for cp:

Youtube-dl is a FOSS python script which allows you to download flash videos from not only YouTube, but over 150 websites. You can download it directly from the official website or through your package manager of choice (it is provided by portage and many others).

In case you foresee running into DRM restrictions, you may also want to get RTMPDump. Youtube-dl calls RTMPDump automatically if it encounters Adobe’s proprietary RTMP protocol and the software is installed.

#### 2) Chrome and wget

• Open your Chrome cache page (at chrome://cache/).
• Open the page containing your video in a new tab.
• Start playing the video.
• Copy the link (in plaintext, or copy the link destination and remove the chrome://... part at its start)
• Run this from your terminal:

## Change owner of a directory recursively

Note that chown may need to be run as root.

full history here