DEV Community

Ranvir Singh
Ranvir Singh

Posted on • Updated on • Originally published at blog.ranvir.xyz

Bash commands I have been using every day as a developer

In this post, I will be sharing all types of bash commands that I use during my daily life.

To start with, I am a big-time shell user. I do everything from the shell. It may be as simple as pushing the code, It may be running a project, It may be changing a few files. Everything I do involves shell to some extent.

Git

Git commands were the most common commands in my shell history. There are less than 10 git commands that I have used to date.

git status
git diff <file_name>
git add <file_name>
git branch <branch_name>
git checkout <branch_name>
git checkout <file_name>
git commit -m "<commit_message>"
git fetch <branch_name>
git cherry-pick <commit_hash>
git pull origin <branch_name>
git push origin <branch_name>
git reset
Enter fullscreen mode Exit fullscreen mode

These are the few git commands along with a few more which you will use. There are a lot of tutorials that will tell you the uses of these commands. If you want to know about anything specific, let me know in the comments below.

Moving inside the directory structure

Another pretty common command that I was using to switch between the different directories is cd.

cd /Users/ranvir/Documents/...
Enter fullscreen mode Exit fullscreen mode
cd ~/Documents/...
Enter fullscreen mode Exit fullscreen mode

Both of these commands will produce the same result.

cd ..
Enter fullscreen mode Exit fullscreen mode

This command will take you one directory back.

cd -
Enter fullscreen mode Exit fullscreen mode

This command is one of my favorites. This will take you to directory where you were before.

For example, if you were in ~/Documents/some_dir/ and then you ran the command

cd /var/www/html/
Enter fullscreen mode Exit fullscreen mode

and after completing your stuff, you run cd -, it will take you back to ~/Documents/some_dir/.

ls

ls/Listing command will help you to list everything in a directory. There are a lot of versions, but primarily we use the following.

ls
ls -a
ls -la
Enter fullscreen mode Exit fullscreen mode

Checking your command history

history
Enter fullscreen mode Exit fullscreen mode

Use this command to see your history.

Finding old commands

Use this technique to find old commands.

Use the combination of control + r and type the words that you want to appear.

For example: control + r restart. This will show the most recently used command with a restart in it. This command is pretty helpful in many of the cases.

Run the last command with sudo.

sudo !!
Enter fullscreen mode Exit fullscreen mode

This will run the last executed command as a sudo user.

Remove the clutter

To my surprise, this was one more which I was frequently using. Not sure if you guys are using it. Let me know in the comments below.

clear
Enter fullscreen mode Exit fullscreen mode

Exiting the terminal

This command was being used frequently to quit the shell as well.

exit
Enter fullscreen mode Exit fullscreen mode

vim and cat

These commands are used to edit or check the content of the files regularly.

vim ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

See and analyze your running processes

I prefer to use this command regularly to check which processes are taking more memory or CPU usage than other apps and maybe killing them.

htop
Enter fullscreen mode Exit fullscreen mode

Finding stuff around

This command is used to find content in a directory or a group of files. I mostly use the following version.

grep -rni "search_material" *
Enter fullscreen mode Exit fullscreen mode

where r stands for recursive and i stands for removing case check.

ssh

I have a lot of boxes (servers) running for various things that I have to access during the work. I have simply made a config, using which I can directly call the aliases to connect to a specific server. For example.

ssh ranvir_server
Enter fullscreen mode Exit fullscreen mode

Let me know if you want to know how is this config written.

Creating a directory

This command is used to create a directory.

mkdir abc
Enter fullscreen mode Exit fullscreen mode

Creating a file

This command is used to create new files.

touch abc.js
Enter fullscreen mode Exit fullscreen mode

Docker

I use a lot of docker related things to use databases. I think discussing docker will again a bigger one. I don't think we would be able to do that in this part.

Do let me know if you want to know more about the docker. I will come up with a new article.

Thanks, guys for coming this long. Please leave a like and do share your favorite commands that I have missed.

Top comments (2)

Collapse
 
abregman profile image
Arie Bregman

git:

git blame [file]
git log
git rebase -i
git checkout HEAD~1 -- [file]
Enter fullscreen mode Exit fullscreen mode

ls:

alias ll="ls -lh"
ls -ltr #also useful sometimes
Enter fullscreen mode Exit fullscreen mode

clear:

worth to mention you can use ctrl+l instead of typing the command

vim:

vi [file] +20 # this will open the file and get you to line 20
vi -u NORC # Open vim with no plugins activated
vi +/some_word [file]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
singh1114 profile image
Ranvir Singh

Awesome commands will definitely try a few of them. Thanks for sharing.