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:
1
|
|
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.
1
|
|
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:
1
|
|
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:
1
|
|
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:
1
|
|
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:
1
|
|
and if you want to pipe some output directly from a command (e.g. dmesg
) to a bastebin, run:
1
|
|
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.
1
|
|
Or better yet, use octal to accurately define what permissions the owner, the group, and everyone else has:
1
|
|
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.
1
|
|
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.
1
|
|
Nested Markdown/reST Syntax
Use the following too get a bold (or italic, etc.) link via markdown:
1
|
|
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.
1
|
|
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).
1
|
|
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/
:
1
|
|
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):
1
|
|
And alternative using the --no-clobber
argument for cp
:
1
|
|
Download flash videos under Linux
1) Youtube-dl
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.
- Return to your chrome cache page and refresh it, your topmost link should point to 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:
1
|
|
Edit apps launched at startup in GNOME 3.*
1
|
|
Make Git cache passwords for 10 hours
1 2 |
|
Change owner of a directory recursively
Note that chown
may need to be run as root.
1
|
|