How To Use Command Lineโ€‚by@iamismile

How To Use Command Line

The command line is a tool or interface for interacting with a computer using only text rather than the mouse. Command-Line is an essential tool for software development. We can execute a wide variety of programs on our computer through this. In this tutorial we are going to learn the necessary UNIX commands for development. To run some basic command in windows you can download Git Command Line Interface from Git SCM. To use the command line, type the type of command that is used in LINUX and macOS.
image
Ismile Hossain HackerNoon profile picture

Ismile Hossain

Full-stack JavaScript developer.

twitter social iconlinkedin social iconfacebook social icongithub social icon

๐Ÿ’ป Command Line:

The command line is a tool or interface for interacting with a computer using only text rather than the mouse.

Command-Line is an essential tool for software development. We can execute a wide variety of programs on our computer through this. In this tutorial, we are going to learn the necessary UNIX commands for development.

UNIXย command is a type of command that is used in LINUX and macOS.

To run some basic UNIX command in windows you can download Git Command Line Interface fromย Git SCM.

๐Ÿ”ฐ Getting Started:

โœจ Let's start to learn (can use it as a reference guide) ...

โœ” Check the Current Directory โžกย 

pwd
:

On the command line, it's important to know the directory we are currently working on. For that, we can useย 

pwd
ย command.

image

It shows that I'm working on myย Desktopย directory.

โœ” Display List of Files โžกย 

ls
:

To see the list of files and directories in the current directory useย 

ls
ย command in your CLI.

image

Shows all of my files and directories of myย Desktopย directory.

โ€ข To show the contents of a directory pass the directory name to theย 

ls
ย command i.e.ย 
ls directory_name
.

โ€ข Some usefulย 

ls
ย command options:-

  1. ls -a
    : list all files including hidden file starting with '.'
  2. ls -l
    : list with the long format
  3. ls -la
    : list long format including hidden files

โœ” Create a Directory โžกย 

mkdir
:

We can create a new folder using theย 

mkdir
ย command. To use it typeย 
mkdir folder_name
.

image

Useย 

ls
ย command to see the directory is created or not.

I create aย cli-practiceย directory in my working directory i.e.ย Desktopย directory.

โœ” Move Between Directories โžกย 

cd
:

It's used to change directory or to move other directories. To use it typeย 

cd directory_name
.

image

Can useย 

pwd
ย command to confirm your directory name.

Change my directory to theย cli-practiceย directory. And the rest of the tutorial I'm gonna work within this directory.

โœ” Parent Directory โžกย 

..
:

We have seenย 

cd
ย command to change directory but if we want to move back or want to move to the parent directory we can use a special symbolย 
..
ย afterย 
cd
ย command, likeย 
cd ..

โœ” Create Files โžกย 

touch
:

We can create an empty file by typingย 

touch file_name
. It's going to create a new file in the current directory (the directory you are currently in) with your provided name.

image

I create aย hello.txtย file in my current working directory. Again you can useย 

ls
ย command to see the file is created or not.

Now open yourย hello.txtย file in your text editor and writeย Hello Everyone!ย into yourย hello.txtย file and save it.

โœ” Display the Content of a File โžกย 

cat
:

We can display the content of a file using theย 

cat
ย command. To use it typeย 
cat file_name
.

image

Shows the content of myย hello.txtย file.

โœ” Moving Files & Directories โžกย 

mv
:

To move a file and directory, we useย 

mv
ย command.

By typingย 

mv file_to_move destination_directory
, you can move a file to the specified directory.

By enteringย 

mv directory_to_move destination_directory
, you can move all the files and directories under that directory.

Before using this command, we are going to create two more directories and anotherย txtย file in ourย cli-practiceย directory.

mkdir html css

touch bye.txt

image

Yes, we can use multiple directories & files names one after another to create multiple directories & files in one command.

image

Move myย bye.txtย file into myย cssย directory and then move myย cssย directory into myย htmlย directory.

โœ” Renaming Files & Directories โžกย 

mv
:

mv
ย command can also be used to rename a file and a directory.

You can rename a file by typingย 

mv old_file_name new_file_name
ย & also rename a directory by typingย 
mv old_directory_name new_directory_name
.

image

Rename myย hello.txtย file to theย hi.txtย file andย htmlย directory to theย folderย directory.

โœ” Copying Files & Directories โžกย 

cp
:

To do this, we use theย 

cp
ย command.

โ€ข You can copy a file by enteringย 

cp file_to_copy new_file_name
.

image

Copy myย hi.txtย file content intoย hello.txtย file. For confirmation open yourย hello.txtย file in your text editor.

โ€ข You can also copy a directory by adding theย 

-r
ย option, likeย 
cp -r directory_to_copy new_directory_name
.

Theย 

-rย 
option for "recursive" means that it will copy all of the files including the files inside of subfolders.

image

Here I copy all of the files from theย folderย toย folder-copy.

โœ” Removing Files & Directories โžกย 

rm
:

To do this, we use theย 

rm
ย command.

โ€ข To remove a file, you can use the command likeย 

rm file_to_remove
.

image

Here I remove myย hi.txtย file.

โ€ข To remove a directory, use the command likeย 

rm -r directory_to_remove
.

image

I remove myย folder-copyย directory from myย cli-practiceย directory i.e. current working directory.

โœ” Clear Screen โžกย 

clear
:

Clear command is used to clear the terminal screen.

โœ” Home Directory โžกย 

~
:

The Home directory is represented byย 

~
. The Home directory refers to the base directory for the user. If we want to move to the Home directory we can useย 
cd ~
ย command. Or we can only useย 
cd
ย command.

๐Ÿ›  Tools I used for this tutorial:-

  1. Fluent Terminal
  2. Git Bash Shell

Thanks for reading and stay tuned.๐Ÿ™‚๐Ÿ‘‹

Previously published at https://dev.to/iamismile/command-line-tutorial-58km

Please Visit My Website

react to story with heart
react to story with light
react to story with boat
react to story with money
L O A D I N G
. . . comments & more!