Posts Common commands

Common commands

General shell commands

pwdget current path
pwd | pbcopycopy current path to clipboard
cd -go back to previous location
ls -ls or llist files with detailed info (permission, date, symoblic links)
cat filenameshow the contents of the file filename
free -shShow RAM - space used and free
df -hShow disk information - sapce used and free
du -sh .Show total size occupied by current directory
du -sh *Show size of each file or folder in current directory
du -sh * | tail -1Show total size occupied by the last file in the current directory
stat filenameDisplay file status
htop or ytopProcess info and CPU Usage
man command-nameInformation about the command
tree [-aldf][-L level][-P pattern][-I pattern][-o filename]display directory’s contents in a tree
a - all files
l - symbolic links
d - directories only
L - limit number of levels of directory
I - files not matching pattern
P - files matching pattern
o - output to filename
<C-T>fzf: fuzzy finding files or directories
<C-R>fzf: fuzzy finding commands in history
<Esc-C>fzf: fuzzy finding files or directories from current path

SSH Commands

SSH Tunnelling

ssh -NL 8888:localhost:8888 [email protected]

Copy multiple files from remote to local:

$ scp [email protected]:/some/remote/directory/\{file1,file2,file3\} /localpath
$ scp [email protected]:'/path1/file1 /path2/file2 /path3/file3' /localPath

Other ssh commands

Generate ssh key:

ssh-keygen -t rsa

Save ssh host info Modify this file: ~/.ssh/config

Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/id_rsa

Host targaryen
    User daenerys
    Port 7654

Host tyrell

Host martell

Host *ell
    User oberyn

Host * !martell
    LogLevel INFO

Host *
    User root
    Compression yes

Save ssh password so that no need to re-enter everytime

Run this in client (not server)

ssh-copy-id [email protected]

Open server in nautilus / file explorer

File explorer: Other locations > Connect to server > sftp://[email protected]/

tmux commands

tmux new -s name 
tmux ls 
tmux a -t name 
<prefix> = <c-B> (default), can be changed to <c-A> 
<prefix> [%”](Splitting panes)
<prefix> D(get out )
<prefix> cCreate a new window (appears in status bar)
<prefix> 0Switch to window 0
<prefix> 1Switch to window 1
<prefix> xKill current window
<prefix> dDetach tmux (exit back to normal terminal)
<prefix> zthe active pane is toggled between zoomed and unzoomed
<prefix> <c-S>save current state
<prefix> <c-R>reload saved state

Vim commands

I. Pure Vim


Verbs (operations) + Noun (text on which operation is performed)

[count] [operation] [text object / motion]

Run bash commands in vim


. (dot) - outputs the command into the current buffer

1. VIM Verbs (operations)

Ddelete everything from where your cursor is to the end of the line
dddelete a line
xdelete a sigle character
yyank text into the copy buffer.
yyyank line into the copy buffer.
vhighlight one character at a time.
Vhighlight one line at a time.
<c-v>highlight by columns.
ppaste text after the current line.
Ppaste text on the current line.
>Shift Right
>Shift Left
gUmake uppercase
gumake lowercase
~swap case

2. VIM Nouns (text)

i. Text Objects

Must be combined with verbs

iwinner word (non whitespace) (works from anywhere in a word)
awword with surrounding white space (works from anywhere in a word)
aw ~ W. Difference in position. E.g. For dw, cursor must be at beginning, whereas daw works from any position.
ibinner bracket (the contents of an HTML tag)
aba bracket
itinner tag (the contents of an HTML tag)
ata tag block
i”inner quotes
a”a quote
ipinner paragraph
apa paragraph
isinner sentence
asa sentence

Combination examples:

gUiwcapitalize a word
ci(change inner bracket
6dWdelete 6 words
yiscopy inner sentence
di”delete inner quotes

ii. Motions

Can be combined with verbs or used independently

[count] w/Wgo a (word / word with whitespace) to right
[count] b/Bgo a (word / word with whitespace) to left
[count] e/Ego to the end of (word / word with whitespace)
[count] ]mgo to the beginning of next method
[count] h / j / k / lleft / down / up / right
[count] f/F [char] [;,]+go to the next occurence of character
[count] t/T [char] [;,]+go to just before the next occurence of character
%move to matching parenthesis pair
[count] +down to first non blank char of the line.
[count]$moves the cursor to the end of the line.
0moves the cursor to the end of the line.
Gmove to the end of the file.
ggmove to the beginning of the file.

Combination examples:

3ceChange 3 wrods to end
d]mdelete start of next method
ctLchange upto before the next occurence of L
d]mdelete start of next method

3. Other important vim commands

iInsert to left of cursor
aInsert to right of cursor
Ainsert at end of line
Iinsert at beginning of line
oinsert at beginning of next line
Oinsert at beginning of previous line
<c-r>will redo the last undo.
/textsearch for text
:%s/text/replacement text/gsearch through the entire document for text and replace it with replacement text.
:%s/text/replacement text/gcsearch through the entire document and confirm before replacing text.
*search forward for word under cursor
#search backward for word under cursor
:vsplitvertical split windows
m[a-zA-Z]sets a custom mark whose location can be accessed using `[mark] and line accessed using ‘[mark]
’.move to the last edit
:marksshow all current marks that are being used
:q! or ZQforce quit
:wq or ZZwrite and quit
:bdremove buffer
gdGoto Definitions
grGoto References
[:vert] :sf filenamefind file and open in split mode
<c-v> select multiple lines then Iinsert at multiple lines
q <char> commands q
record command macros
apply recorded commands

4. Custom (Remapped) vim commands

jk (Custom- inoremap jk <Esc> )<Esc>
kj (Custom)inoremap kj <Esc><Esc>
nnoremap <C-c>| <Esc> 
nnoremap <C-s>:w<CR>
nnoremap <C-Q>:wq!<CR>
Better window navigation 
nnoremap <C-h><C-w>h
nnoremap <C-j><C-w>j
nnoremap <C-k><C-w>k
nnoremap <C-l><C-w>l

5. Using Args

Args are list of files initially opened. So, it’s a subset of buffers.

:argsdisplay args files
:args */.yamladd files to args
:sallopen all args files in split mode
:vert sallopen all args files in vertical split mode
:windo difftshow differences in all args files
c-x, c-lautocomplete
:vim TODO/ ##search in all args files
:cdo s/TODO/DONE/greplace in all args files

6. Scrolling and motions

<c-u> , <c-d>Up, down scroll
<c-b> , <c-f>Up, down full screen scroll
<c-y> , <c-e>Up, down scroll by lines
H / M / LNavigations to top / middle / bottom
ztPut current cursor position to top
zzPut current cursor position to middle
zbPut current cursor position to bottom

II. Vim Plugins commands

To apply latest settings:

:source $MYVIMRC

Bulk-rename in ranger

  • Select files to rename using visual selection
  • :bulkrename

1. vim-surround commands

ds[‘“bB{}t]delete surrounding quotes
cs[‘“bB{}t] [‘“bB{}t]change surrounding quotes
ysiw[‘“bB{}t]add surrounding quotes “
v-select, S[‘“bB{}t]add surrounding


<p> Hello </p>cst<h2><h2> Hello </h2>
if *x>3{ysW(if ( x>3 ) {
*“hello”ysWf print<cr(Enter)>print(“hello”)

2. Git plugins commands

<c-o> <c-i>Toggle between buffers
:Git diffShow git differences
:GdiffsplitShow differences in split mode
:GBrowseOpen the repository in github
:GVShow git commit history

3. Coc commands

:CocInstall coc-pythonInstalling coc tools
:CocUninstallUninstalling coc tools
:CocList extensions (Tab for autocompletion)Show extensions
:CocCommandexecute a COC command
oexpand/collapse in Coc explorer

4. coc-python

Shift Kdoc hint
:Formatautopep8 formatting
<C-w>wSwitch cursors between sidebar and code
<C-n> <C-n> <C-n>
multiple cursors:
Insert at first
Insert at end

5. FZF

:RgFind word inside file
:BLinesFind all occurences of word in a giant file
:LinesSame as above but search in all buffers
:History:HOstory of commands ran in vim
:Agsimilar to Rg but
:BuffersSearch through buffers
gfGoto file: open file directly from path written in vim

6. Startify

:SSaveSave session
:SLoadLoad session

7. vim-commentary

nnoremap <space>/:Commentary<CR>
vnoremap <space>/:Commentary<CR>

Git commands

git commit –amendadd to previous commits
git push origin -f branchnameforced push
git rebase mastermerge changes of master onto the current branch (first pull from master before rebase)
git log 
git diff 
git remote -vshow repo information
git reset –hard eg git reset --hard [email protected] 
git show 
git config –global 
git config –global 
git reset remove file from the current index (the “about to be committed” list) without changing anything else.
git checkout filenameUndo local changes to latest commit

Ignore files that have already been committed to the repo

$ git rm -r --cached .
$ git add .
$ git commit -m "Clean up ignored files"

Hard delete unpublished commits

git reset --hard commit_id (reset to the particular commit. It will destroy any local modifications.)

Alternatively, if there’s work to keep

git stash
git reset --hard commit_id
git stash pop

This saves the modifications, then reapplies that patch after resetting. You could get merge conflicts, if you’ve modified things which were changed since the commit you reset to.

Undo published commits with new commits

This will create three separate revert commits:

git revert a867b4af 25eee4ca 0766c053

It also takes ranges. This will revert the last two commits:

git revert HEAD~2..HEAD

Similarly, you can revert a range of commits using commit hashes:

git revert a867b4af..0766c053

Reverting a merge commit

git revert -m 1 <merge_commit_sha>

To get just one, you could use rebase -i to squash them afterwards Or, you could do it manually (be sure to do this at top level of the repo) get your index and work tree into the desired state, without changing HEAD:

git checkout 0d1d7fc32 .

Then commit. Be sure and write a good message describing what you just did

git commit

Git reset

git reset does know five “modes”: soft, mixed, hard, merge and keep. I will start with the first three, since these are the modes you’ll usually encounter. After that you’ll find a nice little a bonus, so stay tuned.

  • soft

    When using

      git reset --soft HEAD~1

    you will remove the last commit from the current branch, but the file changes will stay in your working tree. Also the changes will stay on your index, so following with a git commit will create a commit with the exact same changes as the commit you “removed” before.

  • mixed

    This is the default mode and quite similar to soft. When “removing” a commit with

      git reset HEAD~1

    you will still keep the changes in your working tree but not on the index; so if you want to “redo” the commit, you will have to add the changes (git add) before commiting.

  • hard

    When using

      git reset --hard HEAD~1

    you will lose all uncommited changes in addition to the changes introduced in the last commit. The changes won’t stay in your working tree so doing a git status command will tell you that you don’t have any changes in your repository.

    Tread carefully with this one. If you accidentally remove uncommited changes which were never tracked by git (speak: committed or at least added to the index), you have no way of getting them back using git.

  • Bonus (keep)

      git reset --keep HEAD~1

    is an interesting and useful one. It only resets the files which are different between the current HEAD and the given commit. It aborts the reset if anyone of these files has uncommited changes. It’s basically acts as a safer version of hard.

    This mode is particularly useful when you have a bunch of changes and want to switch to a different branch without losing these changes - for example when you started to work on the wrong branch.

Remove sensitive file from github repo history

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
git push -f origin master

Other git commands

git rm | rm plus git add combined
git rm --cached | file removed from the index (staging it for deletion on the next commit), but keep your  copy in the local file system.

i3wm commands

  • pavucontrol
  • alsamixer
mod + r - resize mode , then arrow keys or vim keys 
mod + Shift + e - exit 
mod + d - dmenu 
mod+Shift+c reload 
mod+Shift+r restart 

Alt+Shift- Change keyboard language

Brew bundle


Create a Brewfile in the root of your project with:

touch Brewfile

Add your dependencies in your Brewfile:

tap "homebrew/cask"
tap "user/tap-repo", "https://[email protected]/user/homebrew-tap-repo.git"
cask_args appdir: "/Applications"

brew "imagemagick"
brew "denji/nginx/nginx-full", args: ["with-rmtp-module"]
brew "[email protected]", restart_service: true, link: true, conflicts_with: ["mysql"]

cask "firefox", args: { appdir: "~/my-apps/Applications" }
cask "google-chrome"
cask "java" unless system "/usr/libexec/java_home --failfast"

mas "1Password", id: 443987910

whalebrew "whalebrew/wget"

cask and mas entries are automatically skipped on Linux. Other entries can be run only on (or not on) Linux with if OS.mac? or if OS.linux?.


You can then easily install all dependencies with:

brew bundle

Any previously-installed dependencies which have upgrades available will be upgraded.

brew bundle will look for a Brewfile in the current directory. Use --file to specify a path to a different Brewfile, or set the HOMEBREW_BUNDLE_FILE environment variable; --file takes precedence if both are provided.

My .Brewfile is stored in the home directory and the HOMEBREW_BUNDLE_FILE environment variable is set to ~/.Brewfile

You can skip the installation of dependencies by adding space-separated values to one or more of the following environment variables:


brew bundle will output a Brewfile.lock.json in the same directory as the Brewfile if all dependencies are installed successfully. This contains dependency and system status information which can be useful in debugging brew bundle failures and replicating a “last known good build” state.

You can opt-out of this behaviour by setting the HOMEBREW_BUNDLE_NO_LOCK environment variable or passing the --no-lock option.

You may wish to check this file into the same version control system as your Brewfile (or ensure your version control system ignores it if you’d prefer to rely on debugging information from a local machine).


You can create a Brewfile from all the existing Homebrew packages you have installed with:

brew bundle dump

The --force option will allow an existing Brewfile to be overwritten as well. The --describe option will output a description comment above each line. The --no-restart option will prevent restart_service from being added to brew lines with running services.


You can also use a Brewfile to list the only packages that should be installed, removing any package not present or dependent. This workflow is useful for maintainers or testers who regularly install lots of formulae. To uninstall all Homebrew formulae not listed in the Brewfile:

brew bundle cleanup

Unless the --force option is passed, formulae that would be uninstalled will be listed rather than actually be uninstalled.


You can check there’s anything to install/upgrade in the Brewfile by running:

brew bundle check

This provides a successful exit code if everything is up-to-date, making it useful for scripting.

For a list of dependencies that are missing, pass --verbose. This will also check all dependencies by not exiting on the first missing dependency category.


Outputs a list of all of the entries in the Brewfile.

brew bundle list

Pass one of --casks, --taps, --mas, --whalebrew or --brews to limit output to that type. Defaults to --brews. Pass --all to see everything.

Note that the type of the package is not included in this output.


Runs an external command within Homebrew’s superenv build environment.

brew bundle exec -- bundle install

This sanitized build environment ignores unrequested dependencies, which makes sure that things you didn’t specify in your Brewfile won’t get picked up by commands like bundle install, npm install, etc. It will also add compiler flags which will help find keg-only dependencies like openssl, icu4c, etc.

Restarting services

You can choose whether brew bundle restarts a service every time it’s run, or only when the formula is installed or upgraded in your Brewfile:

# Always restart myservice
brew 'myservice', restart_service: true

# Only restart when installing or upgrading myservice
brew 'myservice', restart_service: :changed
This post is licensed under CC BY 4.0 by the author.