Command to change the default home directory of a user

Ibrahim’s comment on the other answer is the correct way to alter an existing user’s home directory. Change the user’s home directory: usermod is the command to edit an existing user.-d (abbreviation for –home) will change the user’s home directory. Change the user’s home directory + Move the contents of the user’s current directory: -m (abbreviation for –move-home) will move … Read more

What does `set -x` do?

set -x enables a mode of the shell where all executed commands are printed to the terminal. In your case it’s clearly used for debugging, which is a typical use case for set -x: printing every command as it is executed may help you to visualize the control flow of the script if it is not functioning … Read more

Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?

wait returning >= 0 tells you a child process has terminated (and that calling wait didn’t fail), but it does not tell you whether that process terminated successfully or not (or if it was signalled). But, here, looking at your code, it’s fairly obvious the program does care about whether the child process that terminated did so successfully or not: … Read more

How to read a file into a variable in shell?

In cross-platform, lowest-common-denominator sh you use: In bash or zsh, to read a whole file into a variable without invoking cat: Invoking cat in bash or zsh to slurp a file would be considered a Useless Use of Cat. Note that it is not necessary to quote the command substitution to preserve newlines. See: Bash Hacker’s Wiki – Command substitution – Specialities.

How to colorize diff on the command line

Man pages for diff suggest no solution for colorization from within itself. Please consider using colordiff. It’s a wrapper around diff that produces the same output as diff, except that it augments the output using colored syntax highlighting to increase readability: or just: Installation: Ubuntu/Debian: sudo apt-get install colordiff OS X: brew install colordiff or port install colordiff

How to colorize diff on the command line

Man pages for diff suggest no solution for colorization from within itself. Please consider using colordiff. It’s a wrapper around diff that produces the same output as diff, except that it augments the output using colored syntax highlighting to increase readability: or just: Installation: Ubuntu/Debian: sudo apt-get install colordiff OS X: brew install colordiff or port install colordiff

What is the difference between SIGSTOP and SIGTSTP?

Both signals are designed to suspend a process which will be eventually resumed with SIGCONT. The main differences between them are: SIGSTOP is a signal sent programmatically (eg: kill -STOP pid ) while SIGTSTP (for signal – terminal stop) may also be sent through the tty driver by a user typing on a keyboard, usually Control–Z. SIGSTOP cannot be ignored. SIGTSTP might be.