Before we go on to the list of commands, you need to open the command line first.
CLI
CLI is a command-line program that accepts text input to execute operating system functions.
e.g. To shut down a system we can use the GUI and click the respective button to do that but in Linux based system we can also write shutdown -h
in CLI to do the same thing.
1. pwd
pwd stands for public working directory, this command will return an absolute (full) path of the current working directory (folder) we’re in. e.g. /home/username
.
2. ls
ls stands for listing, this is used to view the contents of the directory.
e.g. let's say we are in the Documents folder if we input ls
it will show us all the files and folders in the Documents folder.
We can also use various flags with it:
- ls -a will show all the files including hidden files.
- ls -R will list all the files in the sub-directories as well.
3. cd
cd stands for change directory. To navigate through the Linux files and directories, the cd command is used. It requires either the full path or the name of the directory, depending on the current working directory that we're in.
- let's say we are In the Documents directory and photos is a subdirectory of that, now if we want to navigate to photos
cd photos
works perfectly. - but if we want to navigate to a completely different directory let's say /home/Desktop/movies we have to write the full path
cd /home/Desktop/movies/
4. mkdir
mkdir command is used to make a new directory — if you type mkdir Music
it will create a directory called Music in our current directory.
- To generate a new directory inside another directory, use this basic command
mkdir Music/Newfile
- We can create more than one directory with a single command like
mkdir Music Photos
this will create two folders named Music and Photos.
5. touch
The touch command allows you to create a blank new file through the command line. As an example, enter touch /user/Documents/Web.html
to create an HTML file entitled Web under the Documents directory.
- We can also create multiple files in a single line
touch index.html app.js
6. cp
cp stands for copy. The cp command is used to copy files from the current directory to a different directory. For instance, the command cp scenery.jpg /Pictures
would create a copy of scenery.jpg (from your current directory) into the Pictures directory.
- syntax goes like
cp {file path you want to copy} {path where you want to copy}
7. mv
mv stands for move. syntax and use are similar to the cp command but instead of copying the item, it will move the item to the specified path. the command mv scenery.jpg /Pictures
would move the scenery.jpg (from your current directory) into the Pictures directory.
8. rmdir
If we want to delete a directory, we use the rmdir command. However, rmdir only allows you to delete empty directories. it stands for remove directory.
9. rm
The rm command is used to delete directories and the contents within them. If you only want to delete the directory — as an alternative to rmdir
— use rm -r
.
Note: Be very careful with this command and double-check which directory you are in. This will delete everything and there is no undo.
10. echo
This command is used to move some data into a file. For example, if you want to add the text, “Hello, my name is Debasish” into a file called name.txt, you would type the command echo Hello, my name is Debasish >> name.txt
.