logo

Git & GitHub Tutorial - Part 2 - Basic Unix Commands

Git & GitHub Tutorial - Part 2 - Basic Unix Commands

In this part, we will see some basic Unix commands. As we will use git most of the time in command lines, it would be good to learn some basic Unix commands. Make sure you are using git bash for running these commands, Otherwise in the windows operating system some commands might not work.



ls

ls is short for the list of contents in the current directory including files and folders. If we want to see the list inside a folder we can use ls with a path like this


ls folderName

This will show the contents inside the folderName directory. To see the dotfiles or hidden files folders you can pass the -a flag like this


ls -a

This command will show the hidden files and directories




pwd

This will show the present working directory.



cd

This command is used for changing the directory. To go to a directory you have to write the path after cd like this

cd folderOne


You can move or go to multiple directories by typing the path like this

cd folderOne/anotherFolder


If you want to change the directory backward you have to type

cd ..


You can go back to multiple directories. Like if you go back two-step you have to type like this

cd ../..

This will make you go back to two directories you can add more step like this ../



start . or open .

To open a directory in file explorer in the windows operating system you have to write

start .


And to open a folder in MAC you have to write the following command

open .



touch

To create a file you can use the touch command followed by the file name with an extension like

touch story.txt


You can create multiple files in a single touch command by putting space between the files name like

touch index.html style.css script.js

This command will create all the files mentioned above


You can create a file inside another folder by typing the path like this

touch folderOne/test.txt

This command will create a test.txt file inside the folderOne directory.



mkdir

mkdir is used to create a directory. like

mkdir myNewDirectory


If your folder name contains spaces this command will create separate directories instead of creating one directory. Like

mkdir my new directory

this command will create three folders named my, new, directory instead of creating one folder


If you want to create a directory or folder name with spaces you have to use quotation like this

mkdir "my new directory"

This command will create a single folder named my new directory.



rm

To delete a file you can use rm command. This command will delete your file permanently and will not store in recycle bin or trash. Like

rm test.txt


You can also delete the file from the directory by referencing the path like if I have a file named testFile.txt inside testFolder I can delete this like

rm testFolder/testFile.txt

This command will delete the testFile.txt inside the testFolder.


You can delete multiple files at a time by typing their name separating with space like

rm fileOne.php fileAnother.html



rm -rf or rmdir

To remove a directory you can pass the -rf flag or you can use rmdir command. Like to delete folder name test the command is

rm -rf test



If you missed the first part of this tutorial you can read it from here https://devunlock.com/content/git-tutorial

At 17th Apr 2023
Share Content:
Read: 2

Recent Comments