Developers love CLI tools that give them the freedom to work from any operating system and pick the tools of their trade. This trend is enhanced by the fact that most development platforms these days offer CLI tools first and then add GUI tools on top of that.
In this post, I’m going to talk about basic shell commands. You’ll learn how can create a file, read the file or write a file from your command line or bash shell.
If you haven’t read our GitHub post where I explain about GitHub repo UI and many more. Check it out.
Table of Contents
Basic Shell commands
All shell command are case sensitive.
|Command Name||Commend Description|
|pwd||Print path for the current directory|
|mkdir||Make directory or folder|
|ls||Show all the file in the folder|
|ls -l||Show all the file in the folder as list view|
|ls -la||Show hidden file and folder with full details|
|cd||Change the directory or folder|
|.||Alias of the current directory|
|..||Alias of the parent directory|
|clear||Clear the terminal|
|echo||Print the terminal|
|touch||Make an empty file|
|help||Help on specific command|
|man||Help on specific command for mac / Linux|
|>||Write to the file|
|>>||Append to the file|
|cat||create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.|
|rm -rf||Remove folder|
|start .||Open the current folder in windows explorer|
|explorer .||Open the current folder in windows explorer|
|open .||Open the current folder in default file manager in mac / Linux|
Let’s test all those bash commands with example, open your git bash.
After open the git bash you will see a terminal like this. Don’t be afraid.😅
First box indicate which folder or directory are you in and the second box indicate your username and the pc name.
Currently, I’ve open the terminal inside a folder called git. To check out the file path from the bash terminal, I’ve run the command PWD.
pwd command will print the current directory path. It will help you to find out which directory are you in pwd bash command. In this example, the pwd command shows the full path for this folder.
Command: ls, ls -l, ls -la
The ls command print out all the file from the current folder. In this example, the ls command shows all the data inside the git folder.
ls # all file ls -l # all file list view ls -ls # all file along with hidden folder/file
ls -l command allow you to print all the file from current folder as list view.
ls -la command allow you to print all the folder along with hidden files and folder. Hidden folder generally start with (.) dot before the name. Here .top-secret folder is a hidden folder.
The mkdir command is to allow you to create a new folder or directory. First, check out the list of file from the folder. In this picture, there are no file name projects.
mkdir [directory name]
let’s create the folder using mkdir command from the terminal.
Here you can see there is new folder named the project created by mkdir command.
The cd command allows you to change the directory. In this example, let’s change the current directory to the projects directory.
cd [directory name]
In the project folder there is no files, total 0.
one dot(.) means you are selecting the current folder.
Command: start . or explorer . or open .
To open the folder from the terminal use this command. You can use both command “start .” or “explorer .” It will open the folder in windows explorer.
start . or explorer . or open .
Double period (..) means go back to previous folder.
To go back to the git folder, you have to use “cd ..” It will let you go back to your parent folder.
The touch command let you create an empty file in a folder. In the example, I’m creating a file name hello_world.c using git bash.
touch [file name]
This command allows you to write in the file. In the example here I’m creating a new file with text inside named mubin.txt. You can also see that mubin file has length 36. It’s mean this file is not empty.
echo "mesage" > [file name]
The cat command allows you to see what’s inside the file. Here, I’m using the cat command to see what’s inside the file name mubin.txt. It prints out “Hello, I’m moving”. using the cat command to see what’s inside the file
cat [file name]
One the other, when I print out the hello_world.c file. It shows nothing because the file is empty.
This command allows you to add new data to an existing file. Here, in my mubin.txt file adding a new line, “I’m from Bangladesh”. And print out the data using cat command.
echo "message" >> [file name]
Nano is an editor for git bash. Which is allow you to read, write and edit the file. Here, I’m adding data inside new-file.txt through nano editor.
nano [file name with extension]
Here in the new file, I’m adding a new text line ” this file just edited by nano editor.”
To save the data press ctrl+o key it will show new option and ask the file name.
Add new name to the file or leave as it. Press enter to save the file.
To close the nano editor simply press ctrl+x button. You will go back to the original bash. You can check the new-file.txt using cat command.
The rm command allows you to remove the file. Here, I’m going to remove the hello_world.c file using the rm command. Before deleting the data here, you can see the file.
rm [file name]
After rm command the hello_world.c file is deleted. You can also see that from ls file.
Command: rm -rf
This command allow you to remove a folder or directory. Here, I’m going to delete a folder name dark.
rm -rf [folder name]
To sum it up, all those commands are used everyday basic, so keep practice, and It will let you reduce much more work.
Hey! check it out, you can also make your boring terminal to more playful. Make terminal more playful ever.
Want to know more about Git Bash Commands. Check it out.