Bash script using default value for empty parameter

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You have a bash script that accepts parameter(s) but you want to give a default value for a missing parameter.

Solution

For example you have a script that accepts a parameter with the year and month (ie 201703), but you want to give it a default of two months ago if the parameter is missing.

failed to execute ‘/lib/udev/socket:@/org/freedesktop/hal/udev_event’ ‘socket:@/org/freedesktop/hal/udev_event’

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

Looking at your /var/log/syslog you see entries every few seconds like the following:

Solution

Seems that hal is not used in newer Ubuntu versions, so you can remove it:

Taken from the answer here

Changing default editor for crontab from nano to vim

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to change the default editor for crontab from nano to vim.

Solution

Add the following to the ~/.selected_editor:

or run the select-editor and choose vim-basic (4)

Converting number from any base system to decimal in linux shell

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to quickly convert a number from a different base system (i.e. binary, octal, hexadecimal), to decimal.

Solution

Use the echo $(()) shell command to convert it passing it the current base system and the number, as in $((2#101010)) or using the O for octal or 0x for hexadecimal notations.
Examples:

Taken from Linux Journal’s Work the Shell column (March 2016)

Combine multiple zip files (from windows) and unzip them in linux

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You have received multiple zip files that were originally one big zip file, possibly from windows, and you want to put them back together and unzip them in linux.

Solution

So if your file names are for example called: file1.zip file2.zip etc, you can do the following:

git apply name_of_file.patch does not work

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You are given a patch file to apply to your git repository but using git apply does not work. No errors reported but no changes applied neither.

Solution

Try to use the patch command command possibly with the -p1 parameter like:

NOTE: Make sure that you are in the right folder relative to the file path in the patch file