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.
โจ 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.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.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:-ls -a
: list all files including hidden file starting with '.'ls -l
: list with the long formatls -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
.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
.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.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
.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
Yes, we can use multiple directories & files names one after another to create multiple directories & files in one command.
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
.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
.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.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
.Here I remove myย hi.txtย file.
โข To remove a directory, use the command likeย
rm -r directory_to_remove
.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.Thanks for reading and stay tuned.๐๐
Previously published at https://dev.to/iamismile/command-line-tutorial-58km
Please Visit My Website