The Linux Commands Series: Part I
man, ls, cd, pwd, mkdir, rmdir, mv, cd, open, touch
I intend to write a series of total VI blog posts describing the most used Linux Commands. This blog is the first of the series. I hope you all enjoy the reading.
Citation/References/Credit will be mentioned at the end of the post.
This command helps you to understand all other commands.
Word man is from manual pages. Man pages are useful for any developer when dealing with commands.
Whenever I want to know or understand any command, I type “man <command>” to get the manual for the command.
Remember, the information presented in the man pages is enormous sometimes. So, just keep in mind not to get lost in the information rather try to find what you need.
When inside a folder if you want to view the list of all the files inside the folder then type the command:
You can also mention a full path of a folder starting from root-like:
ls command also has several options which you can find using the man command mentioned above. One of the most used options is:
ls -la /bin
It displays more information from left to right about the files such as the file permissions, the number of links to that file, the owner of the file, the group of the file, the file size in bytes, the file modified DateTime, the file name.
The set of data is generated by option ‘l’ and option ‘a’ also shows the hidden file which is represented by a dot(.)
cd means change directory. You can mention a folder name that you want to move into from the current directory or you can also mention a full path from the root.
Example: If you have a folder called “animals” then to move into the “animals” folder use the below command.
Now you are in the “animals” folder.
If you want to move into the parent folder then you can use “..”. For example, if the “animals” folder is in a parent folder called “Earth” where there is one other folder called “reptiles” then in order to move into the parent folder use the command below from the “animals” folder.
cd .. # Now you are in Earth folder
# is used to write a comment line, whatever you write after the # is considered as a comment.
If you want to move into the “reptiles” folder directly from the “animals” folder use the command below,
You can also mention a full path starting from root-like below,
PWD means present working directory. Whenever you need to know which directory you are in then use this command, just type “pwd”, it’ll print the current folder full path.
This command is useful to create folders, for example, if you want to create an animals folder then use the below command:
You can also create multiple folders, for example, if you want to create two folders animals and reptiles then use the below command:
mkdir animals reptiles
You can also create nested folders by adding the “-p” option, for example, if you want to create an animals folder inside the Earth folder then use the command below:
mkdir -p Earth/animals
You can delete a folder using this command.
For example, if you want to delete the “animals” folder then:
You can remove multiple folders too,
rmdir animals reptiles
Note: The folder you want to delete must be empty.
If you want to delete folders with files in them then we can use the “rm” command with the “-rf” option:
rm -rf animals reptiles
Note: There won’t be any prompt asking for confirmation so be careful when using this command.
You can move a file around using this command. You can specify the file current path and destination path:
mv path1/file1 path2
or you can mention the file name from current folder and destination path:
mv file1 path2
You can rename a file or a folder using this command:
mv file1 file2
You can also move multiple files to a folder, for example, to move files into “animals” folder:
mv file1 file2 animals
You can copy a file content into another file using this command:
cp file1 file2
You can also recursively copy an entire folder into another folder:
cp -r folder1 folder2 #Folder 1 entirely with contents are copied to Folder2
You can open a file using this command:
open <file name>
You can also open a directory using this command:
open <directory name>
To open the current directory:
You can create an empty file using the “touch” command:
touch <file name>
If the file already exists then it opens the file in write mode and updates the timestamp of the file.
This is the end of this blog post. I will publish a blog post in this series once a week.