Videos recorded using the OnlineTvRecorder sometimes have a prefix consisting of a five-digit number, for instance:

71072_Vertrauter_Feind_13.06.19_20-15_kabel1_140_TVOON_DE.mpg.HQ.cut.mp4

Of course, these files fail to sort into the list of unprefixed videos and we cannot search a movie by its initial letters.In this situation, the Bash helps us very nicely with its build-in string manipulation functions. The following snippet takes the filename and removes any sequence of digits followed by an underscore (as regex: [0-9]*_) from the beginning of the filename:

We can pack this into a loop to rename a batch of downloaded files:

The guard expression avoids warnings by mv if the old and new filename equal.

 References

  • [1] Bash string operations

 

Infinitest is a really great plugin for Eclipse. It executes all JUnit tests it can find whenever something changes. After I downloaded DKPro core, a multi-module Maven project, may CPU was running for quite a long time, until all unit tests had been executed once – even though I just wanted to look at the code…

To keep Infinitest from executing these tests over and over again on the next occasion, I put an infinitest.filters file in every single of the 72(!) modules as follows:

Surely, there is also a one-liner that solves the problem, but one works very reliable for me :-)

When we encounter strange, unexplainable problems with text files, hidden characters may be reason. This article describes several possibilities to tackle line-ending and whitespace problems.

Correcting mixed line endings

If a file has mixed line endings, the standard tool flip may help you:

A check with file reveals that the file test.txt has mixed line endings. Flip unifies the line endings to Unix (-u) or Windows (-m) standard:

Examining files

vim can show whitespace characters, if you enable the option list. In command mode, execute the following to show whitespaces like tabs or line endings. Unfortunately, the editor does not differentiate between different types of line endings.

Use :set nolist to return to normal view. With :set ff the program identifies the line ending standard.

If you need to get a detailed picture of the whitespace characters in your document, the octal file viewer od may be helpful, it displays the file as octal values and (interpreted) ASCII characters:

The results looks as follows:

Using cat -v text.txt, you can see bogus (non-Unix) line endings  being marked with a special symbol: ^M

The following Bash snippet outputs the users of a Unix system sorted by their user id:

  • cat outputs the content of /etc/passwd to standard output
  • sed replaces all colons (default field separator) with a whitespace
  • sort orders the lines by the third, whitespace separted field which is the user id
  • awk prints out only the user name and the correspondent user id, separated by a whitespace

Show one’s own/other’s groups

Show all groups on the system (with group id):

Create new group

Add user to group

Assign a specific home directory and shell to a user

If the user shall only be allowed to do SCP/SFTP transfers, then an appropriate login shell is scponly.

 

 

 

My favorite way of labeling backups and other files with the current date and time using the date command:

(produces  2013-07-23_10:44:49).

Links

  • [1] date man page

When downloading large files with scp, it is really annoying, if the download process stalls at 90+%, because it seems that you have wasted your time and scp leaves you with a broken file. Having encountered this problem, I was lucky enough to find this post which explains a remedy: Use rsync in order to complete the interrupted download.

Assume you downloaded a file with scp like this:

then you can continue the download as follows (note the –partial option):

Rsync finds out that a large portion of the file is already there and continues where scp once has stopped.

Links

  • [1] Article with solution

Miscellaneous

!! Re-execute previous command.
!27 Execute command 27 in the history (look it up with: history | tail)
Ctrl + R Reverse search in history (type Ctrl + R to search incrementally)
Ctrl + L Clear the terminal. The same as typing clear
Ctrl + M Enter/return. Useful if inside a long command.
Ctrl + S/Q Freeze terminal/Restore frozen terminal

Move and View Commands

Ctrl + A Go to begin of line (mnemonic: “Anfang” (DE))
Ctrl + E Go to end of line (mnemonic: “end”)
Ctrl + F or Arrow Right Forward one character.
Ctrl + B or Arrow Left Backward one character.
Alt + F or Ctrl + Arrow Right Forward one word.
Alt + B or Ctrl + Arrow Left Backward one word.
Shift + Page Up/Page Down Scroll view up/down one page

Edit Commands

Ctrl + K Delete from cursor to end of line
Ctrl + U Delete from cursor to begin of line
Ctrl + W Delete word left of cursor
Alt + D Delete word right of cursor
Ctrl + D Delete character under cursor or exit bash if line is empty.

Maven-managed Eclipse projects generate appropriate project settings (classpath, build path, etc.) from the pom.xml. The following files need to be ignored in a Maven Eclipse project:

As a shorthand, the following Bash command adds these lines to your .gitignore. It does not matter if your .gitignore is located in the project directory or in any parent of it.

echo “.settings
.project
.classpath
target/” >> .gitignore

Links

  • [1] gitignore man page

Some image processing programs expect the file extension to be in lower case. Many digital cameras, however, tend to use an uppercase extension (JPG in case of the Panasonic TZ-31).

The following Bash one-liner renames all JPG files in the current folder to have the lowercase jpg extension afterwards. The ${…} expression is called parameter expansion, which is quite a powerful mechanism:

Links

  • [1] Manpage of the Bash (see Section on Parameter Expansion)
  • [2] Parameter Expansion explained on bash-hackers.org