Linux: Tips & Trix
1. Browse command history
You can search your command history easily by pressing CTRL + R and start typing a previous command (try to start typing a word that is in a middle of a command). If the suggestion that shows up is not what you are looking for you can press CTRL + R again to keep cycle back through your commands.
To make this even more powerfull, it is possible to search command history just by moving your cursor to the middle of command and pressing Up/Down keys to find all commands that start in the same way as your command.
Some major advantages of tmux:
1) You can have multiple bash windows open in one ssh session
2) You can save all of your bash windows and re-open them later from the same or from another computer
3) If you lose the connection, you don’t lose any of your work, because it is all saved in screen.
4) You can split a bash window with horizontal or vertical line and have several windows inside a window!
Some initial commands for tmux:
Ctrl+B, then C – open new window
Ctrl+B, then N – switch to the next window
Ctrl+B, then P – switch to the previous window
Type “exit” – close the current window
Ctrl+B, then D – detach screen
Ctrl+B, then ] – enter “copy” mode (this is a bit akward on a Swedish keyboard and can be remapped in your .tmux.conf file, see this)
Ctrl+B, then % – split window vertically
Ctrl+B, then ” – split window horizontally
Ctrl+B, then arrows – select another pane inside the current window
Ctrl+B+arrows – resize windows inside windows
Become comfortable with at least one commandline editor. The advantage over the graphical text editors (like gedit) is that you can edit files directly on the server to which you connected over ssh. You don’t have to download/upload files all the time.
Typing your password every time you connect to server or use scp and rsync commands is not very convenient. You can save some time by using passwordless ssh. Here is a short tutorial how to set up everything:
Even though, the main purpose of this is to save time of not typing passwords, I still recommend to put a password on your private key, otherwise it is not very secure. The advantage is that you have to type it only once after you login to your pc and then you can connect to all servers without password. Remember! Never share your private key with anyone.
Sorting files when using ls is often very convenient.
In Linux there are two output streams, standard output and standard error. If you run a command on the terminal then both output streams are printed on the screen. However, if you want to redirect the output to files, you can type a command like this:
your_command >output.log 2>output.err
Then, standard output will be written to output.log and standard error (error or warning messages) will be written to output.err. If you want to redirect both standard output and standard error to the same file, you can write like this:
If you are using tmux then the commands you started will continue running even after you logout. However, if you are not using neither tmux, the commands (even those you run in the background) are sometimes killed. To avoid this you should prepend “nohup” to the command. So this is how you should usually run your commands: