Useful commands | |
|---|---|
| Command Name | Description |
bash -c "command" | Start a new bash shell that runs command, and then exits immediately. This shell will be a child of the current shell. |
echo $? | Show the return code of the prior executed statement (0 = all went well, non-zero = some kind of issue) |
nix-channel --update && nixos-rebuild switch | The && operator says that the second command will only run if the first command succeeded (returncode = 0) |
grep -q password configuration.nix || echo "No password found" | The || operator says that the second command will only run if the first command failed (returncode != 0) |
command & | Execute command in the background (though stdout and stderr will still print to the terminal at random times later as tasks complete) |
TZ=Asia/Tokyo date | Get the current time in the Tokyo timezone (adjust the TZ env variable as appropriate) |
jobs | Show current processes (should show suspended processes, scoped to current session?) |
fg | Foregound and resume a suspended process |
kill -SIGINT 123 | The kill command is used to send signal to processes. The 123 in the example is a PID, a process ID that you can get from ps aux or htop or other programs which might show running processes. The kill command can send any type of signal, and accepts both numeric and character versions of signals |
ssh server ls | wc -l | This will run ls on the remote server, return the response via stdout/stderr, and the pipe will then transfer that stdout to the stdin of wc, but importantly, that wc will be running locally. To make the wc happen on the server, you have to quote it all. |
Issues | |
| Issue | How to fix |
| Mouse locks up | From root command line: 1. modprobe -r psmouse2. modprobe psmouse |
Keyboard shortcuts | |
| Keyboard shortcut | What it does |
| Ctrl+C | Send a SIGINT to the running program, attempting to kill it and gain back control. Not all programs respond to SIGINT, and often if you're running a remote shell through something like tmux, there can be confusion about which level of program to send the SIGINT to. |
| Ctrl+\ | Send a SIGQUIT signal to the running program. |
| Ctrl+Z | Send a SIGTSTP signal to suspend the running program |
| Ctrl+S | Be very careful, this tends to lock up the shell. To exit, run Ctrl+Q to regain control |
~$: DEBUG=1 or ~$: TZ=Asia/Tokyo date (variable and then command execution which needs that variable). If you want child processes to inherit the env variable, do ~$: export VARNAME=varvalue. Note that parallel shells, for instance, still won't inherit (even with export) - only child processes started from the initial shell. Once exported, subsequent setting of the value doesn't need to use export. To then delete the environment variables, use ~$: unset VARNAME. To show all the environment variables that are set, run ~$: env.
| Errors and what to do about them | |
|---|---|
| Command not found | Check first that you didn't mis-type the command. If you didn't, then check that you have the program installed. A useful tool for installation: Command Not Found will let you search for a command and get the right installation command for your OS. |