Problem
You would like to find the users in a group in linux.
Solution
You can have a list with the users by using getent (getentries):
getent group <groupname>
Problem
You would like to find the users in a group in linux.
Solution
You can have a list with the users by using getent (getentries):
getent group <groupname>
Problem
You have made some changes to the NGINX configuration and you would like to reload them without stopping and starting the server.
Solution
Use the following:
kill -HUP $(cat /var/run/nginx.pid)
Problem
You have defined a variable in a bash script (ie MY_FOLDER) but you also want to dynamically get the parent folder (ie MY_FOLDER can have multiple values).
Solution
Use the dirname as in the following
MY_FOLDER=/home/user/first_folder/second_folder MY_PARENT_FOLDER=$(dirname $MY_FOLDER) echo $MY_FOLDER echo $MY_PARENT_FOLDER ....... /home/user/first_folder/second_folder /home/user/first_folder
Problem
You would like to remove some lines from the bash history (ie using cut and paste with wrong values).
Solution
You can use the following, taken from the answer here
for i in {1..no_of_lines}; do history -d start_line; done
where start_line is the start of the lines you want to remove and no_of_lines is the number of lines you want to be removed.
Problem
You have a text file that has empty lines, and you would like to remove them.
Solution
You can use awk in linux like the following to create a new file with the empty lines removed:
awk 'NF' file_with_blank_lines > file_without_blank_lines
Problem
You would like to find the files that contain some specific text, and would like to do it recursively (ie in a project folder), using something simpler than the find command.
Solution
You can use the following in your current top folder to search recursively, case-independent and by displaying the file number that the searched text appears, with the following:
grep -rin "TextToBeSearched" .
Problem
You are trying to install/remove a package but you always get an error message about linux message as above:
Errors were encountered while processing: linux-image-3.13.0-128-generic
Solution
Try the following:
rm -rf /var/lib/dpkg/info/linux-image-3.13.0-128-generic.* apt-get purge linux-image-3.13.0-128-generic
Problem
You would like to know the release of your CentOS server but the cat /etc/issue does not work.
Solution
Try with the following:
cat /etc/centos-release
or with:
cat /etc/redhat-release
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.
#!/bin/bash
LM=$(date -d '2 month ago' +%Y%m)
YEARMONTH=${1:-${LM}}
echo $YEARMONTH
Problem
You would like to know what are the biggest nn files in your linux computer.
Solution
Run the following to give you the 20 largest files:
sudo du -ahx / | sort -rh | head -20
taken from Linux Journal Issue 275 March 2017