Command-Line How-tos
When working on the group server or HPCs, we generally don’t use graphical user interfaces (GUIs), rather we primarily interact with the machines through the command-line interface (CLI). Various shell environments exist but the most common are Bourne-Again Shell (Bash), the default for Ubuntu/WSL; Z shell (Zsh), the default for MacOS; and PowerShell, only used on Windows machines. Zsh is built on top of Bash so the commands are relatively interchangeable but if you’d like more information about the differences, this stack exchange post describes the difference comprehensively. The primary difference to note is the name of the default configuration environment for each with .bashrc and .bash_profile being for Bash and .zshrc and .zprofile for Zsh. Powershell isn’t used often in our group workflow as most machines use a Linux-based environment. However, if you need to do anything on your Windows machine outside of WSL, it may be useful to know a little about it. The syntax and commands are very different between PowerShell and Bash/Zsh.
Tutorials
Bash/Zsh
- The Ubuntu website provides a good tutorial on how to start with the command line and some basics with plumbing. If you’re using WSL and are not in the Ubuntu operating system (OS), WSL is already the Linux terminal, you can skim over the first part in section 3.
- For Bash scripting geeksforgeeks provides good basics for scripting and program control methods
- For Zsh scripting Austin Traver’s site provides a more comprehensive guide on scripting along with various other tutorials for MacOS
PowerShell
- Microsoft provides tutorials for PowerShell on their website
Tips/Tricks/Tools
Terminal Emulators
While the stock terminal emulator for most OS’s are good enough, added functionality and customizability can be gleaned by using other programs. The most popular ones are listed below
- MacOS: iTerm2 has a lot of customizability and extra features compared to Terminal and a large following
- Windows: Windows Terminal is the replacement for Windows Console and can run any command-line app in separate tabs
Programs
Many of these programs are optional as they fix some niche issues. I would recommend not using/installing these programs at first until you’re comfortable with the default methods they replace as they won’t be available on all computers.
- Neovim or
nvimis a modernized version ofvimwhich is extremely modifiable and usesLuafor plugins. Kickstart is a good starting point for plugins which you can choose to edit later - tmux is a terminal multiplexer, allowing you to switch between programs and/or run them in background. This youtube video provides a good starting point for
.tmux.conf. - fzf is an interactive filter which uses a fuzzy matching algorithm. Very useful for reverse searching commands and works well with
tmuxandnvim. - Zoxide is a replacement for cd which uses
fzfto more easily switch between commonly used directories.
Tips
- For Window Terminal, unbind copy and paste from
ctrl + candctrl + vand replace it withctrl + shift + candctrl + shift + vrespectively. This will allow you to do the following shortcuts - Pressing up on the arrow keys allows you to pull previously input commands
-
escthen the left or right arrow key can move you by word (For MacOS, theoptionkey also works) - Hidden files start with
.like.bashrcabove. These files won’t normally be shown when usingls. Usels -ato see all files, including hidden files or better yet, usels -halF. Even better yet, the group server’s default.bashrcfile hasllaliased tols -alF.
Terminal Shortcuts
Shortcuts are applicable for both Linux/WSL and MacOS terminals. For MacOS, shortcuts are as is (i.e. do not replace ctrl with cmd)
-
ctrl + a: Move the curser to the start of the line -
ctrl + e: Move the curser to the end of the line -
ctrl + c: clear current line/kill current process -
ctrl + l: clear entire terminal -
ctrl + z: Pause the current process (can be restarted with the commandfg) -
ctrl + r: Reverse search previously input command
Dotfile Management
The configuration files for various programs are hidden files (e.g. .bashrc, .zshrc, .tmux.conf) and are usually in your $HOME directory. This is fine at first but when you configure your environment more, it quickly becomes difficult to manage them, especially when you have multiple computers you work with. The following tutorial will help with managing dotfiles through a bare git directory. This method is slightly more difficult as you need some basic understanding of git but is good as git is installed on pretty much every HPC we use. Another method would be to GNU Stow but this would require downloading the program on the HPC first.
Comments
Comments powered by Disqus