Unix Commands I Use

Estimated time to read: 1 minute

I keep Googling commands for some of these situations regularly -

General -

1) To find files one level below your current directory -

I was trying to find which repos in my set of folders have a setup.py file. So, this is what I'd use.

find . -maxdepth 2 -iname setup.py

2) To find what process is running on port 2181 -

sudo lsof -n -i :2181 | grep LISTEN

3) Reduce prompt width on bash -

If the current directory you're in is very deep in the directory tree, chances are, your System Prompt is pretty long and this wastes a lot of screen space. Starting from bash v4 though, there's a new variable called PROMPT_DIRTRIM that you can set.

  • Before : Before

  • After: After

Github -

4) To change your git remote-url -

git remote set-url origin <url_name>

5) Steps for deleting a branch:

  • for deleting the remote branch: git push origin --delete <your_branch>
  • for deleting the local branch: git branch -D <branch_name>

6) To delete a file from remote while retaining your local copy -

  • For single file: git rm --cached mylogfile.log
  • For single directory: git rm --cached -r mydirectory