Basic Linux Commands Every Beginner Should Know

Basic Linux Commands Every Beginner Should Know

If you're new to Linux this will prolly help you out ;)

·

5 min read

OVERVIEW

While using Twitter I was going through one of my friend's tech blogs which was published on this platform. So I thought why not try this? Also, it would be pretty amazing if I were to publish what I learn publically and help others learn through my experiences and vice-versa. And at the end, it would help me to revise the stuff I learn. So, if you're a beginner then it is very important for you and this will surely help you out. Hope that you learn something from it.

Why is it important?

If you're interested in computer science then you don't even need to read this out, you would be passionate to learn about new things but still, it's another way of performing operations directly by giving commands rather than performing actions manually. Also in terms of speed, using the command line is faster than using your output devices. So here goes -


Current Location of directory

pwd - Gives us the exact location in which we are right now i.e. Desktop (given that you are opening your terminal on a Desktop).

PS C:\Users\lenovo\Desktop> pwd

Path
----
C:\Users\lenovo\Desktop

Access directory items

ls - Shows all the items present in the current directory(folder/location).

Note: Assuming you are opening GitBash on your Desktop, an additional file desktop.ini will be created, but you don't have to worry because it's a hidden file used to store information about the arrangement of a Windows folder. Essentially, if the layout or settings for a folder are changed, a desktop.ini file is automatically generated to save those changes.

PS C:\Users\lenovo\Desktop> ls


    Directory: C:\Users\lenovo\Desktop


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        28-01-2023     08:57                Dimen
d-----        12-01-2023     14:03                dump
-a----        10-08-2015     13:46        6977272 KMSAuto Net.exe
-a----        19-11-2022     12:20           2392 Mridul - Chrome.lnk
-a----        14-11-2022     03:22          39936 Mridul's  Resume (AutoRecovered).doc
-a----        18-11-2022     04:35          34816 Mridul's  Resume 123.doc
-a----        18-11-2022     04:50         382186 Mridul_Resume - Copy.pdf
-a----        18-11-2022     04:38          21376 Mridul_Resume.docx
-a----        18-11-2022     04:50         382186 Mridul_Resume.pdf
-a----        26-01-2023     14:25           2208 Slack.lnk
-a----        14-11-2022     04:21          39936 Updated Resume.doc
-a----        19-11-2022     12:23          94786 Vallary_Resume.pdf
-a----        19-11-2022     13:26         318586 Vallary_Resume_2022.rtf
-a----        14-11-2022     03:07           2202 WhatsApp.lnk

Print Text

echo -- Prints whatever you write after it.

PS C:\Users\lenovo\Desktop\Test> echo hi
hi

Information about commands

man -- Tells us what a particular command does and how it works(basically it's documentation).

PS C:\Users\lenovo> man pwd

NAME
    Get-Location

SYNTAX
    Get-Location [-PSProvider <string[]>] [-PSDrive <string[]>] [-UseTransaction]  [<CommonParameters>]

    Get-Location [-Stack] [-StackName <string[]>] [-UseTransaction]  [<CommonParameters>]


ALIASES
    gl
    pwd


REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
        -- To view the Help topic for this cmdlet online, type: "Get-Help Get-Location -Online" or
           go to https://go.microsoft.com/fwlink/?LinkID=113321.

Create a new directory

mkdir Test -- Creates a new folder Test in the current directory i.e. Desktop.

PS C:\Users\lenovo\Desktop> mkdir Test


    Directory: C:\Users\lenovo\Desktop


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        28-01-2023     10:04                Test

Go inside the directory

cd Test/ -- Go inside the Test directory.

Note: Now our current directory is changed to Desktop/Test so whatever action we perform will be done on the Test directory.

PS C:\Users\lenovo\Desktop> cd Test/
PS C:\Users\lenovo\Desktop\Test>

Go back

cd .. -- Go back to the previous directory.

PS C:\Users\lenovo\Desktop\Test> cd..
PS C:\Users\lenovo\Desktop>

Remove directory

rmdir Test/ -- Remove the Test folder from the current directory.

Note: This command only works if the Test folder is empty, if there are additional folders inside the Test folder then we cannot use the above command.

So, for removing a non-empty directory use the below command to remove the Test folder.

rm -r Test/ -- Removes the Test folder even if have additional files in it.

PS C:\Users\lenovo\Desktop> mkdir Test


    Directory: C:\Users\lenovo\Desktop


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        28-01-2023     10:18                Test


PS C:\Users\lenovo\Desktop> rmdir Test

Copy

cp -r x/ y/ -- Copy x folder into y folder.

Note: We created 2 folders x and y using mkdir inside our current directory i.e. Test. To copy one folder to the other folder write the name of the folder you wanna copy first and then the folder in which you wanna copy as mentioned above.

cp name.txt y/ -- We don't need -r to copy files.

Move

mv -r x/ y/ -- Move x folder into y folder.

Note: We created 2 folders x and y using mkdir inside our current directory i.e. Test. To move one folder to the other folder write the name of the folder you wanna move first and then the folder in which you wanna copy as mentioned above.

mv name.txt y/ -- We don't need -r to move files.

Rename a file

mv Test Test1 -- Test will be renamed to Test1.

Create a new file

touch name.txt -- Creates a file in the current directory.

Download files from internet

wget -- can help you download files from the internet.

wget "download link"

Display previous commands

history -- display the commands that you’ve typed before.

Clear

clear -- This command is used to clear the terminal and make a new start.


Tip: Try implementing the rest of the commands by yourself, it's fun. And in case you get stuck then of course you have google for that. XD


Thank you so much :)


Â