Getting Started with Linux — command line interface
This article is divided into two Parts:
Part 1 — Linux fundamentals walk through and hands on commands
Part 2 — Hands on more commands
Prerequisite — Basic knowledge of computer terminal
What is Linux: Linux is a name which broadly denotes a family of free and open-source software operating system distributions built around the Linux kernel.
What is linux kernel: The Linux kernel, an operating system kernel which all Linux distributions use, was first released on September 17, 1991 by Linux Torvalds.
Linux Distribution: Popular once are
2. Linux Mint
And many more
Why Use Linux:
1. Open source
2. Stable , reliable ,secure
3. Runs on many hardware platforms
4. Free software ecosystem
6. Simple documentation for commands
7. Easy library & software installation
And many more….
There are many ways we can install various linux distribution, some of them are
1. Installing virtual box on host machines and installing linux distribution of your choice
2. Creating linux instances provided by various cloud provider Eg creating EC2 instance with linux version and using ssh to the instances
3. Windows user can also use WSL — (free & easy installation) for Ubuntu/Kali distribution.
Let’s start the journey starting with small steps –
Linux Directory Structure –
- (/) — it denotes “Root”, it is the home directory of the superuser. All the directories in the linux system come under root directory.
2. (/bin) — contains the executable programs and other binaries
3. (/home) — contains the user’s data files and user-specific configuration files.
4. (/etc) — system configuration files.
5. (/opt) — Optional or third party software.
6. (/tmp) — directory for temporary files.
7. (/usr) — user related programs.
8. (/var) — variable related data(log files)
Basic linux commands –
1. ls — list directory contents
2. ls -l — listing directories with timestamp
3. cd — change directory
1. pwd — display the present working directory
2. echo — display arguments to screen
3. cat — allows us to create single or multiple files, view contain of file, concatenate files
4. man — display online manual
5. clear- clears the screen
6. exit — exists the shell or current session.
7. spacebar — helps in displaying/traveling to the next page
8. rm — helps in removing file
9. mv — helps in renaming file
10. cp — copy command helps in copying file in same directory or another directory
11. vi — creates a new file in vi editor mode(we can also use nano,touch and emac) as other editor options.
12. wq — helps in saving and quitting the page
13. q— helps in quitting the page without saving changes
14. Help — command to get help
Many other commands also present — please check Linux documentation.
Let’s see the practical implementation of some of these commands with a USE Case.
Use Case/ Problem statement –
1. Traverse through a particular directory in our system. See the current files present in the directory.
2. create a new directory and create a new file add some data into it save and exit the file
3. display the contents of the file
4. rename the file and copy file into another directory
I am using Linux (Ubuntu 18.04 LTS) distribution.
Step 1. Lets use (cd /) to see our root directory and (ls) command to display the contents of the root directory
Step 2: Now I ll choose directory (h) as my working directory using cd command and ls command to list the content of directory(h)
Step 3: create new directory as myworkspace using (mkdir) command and again using (ls) command we can see new folder has been created with name myworkspace
Step 4: navigate inside myworkspace folder and create a new file using vi editor (you can use other editor option I mentioned above). On pressing enter we will be inside the empty file(linux_basics) where we will add some content into it and save and exit out of file.
Step 5 : once inside the file we need to press (i) for getting into insert mode to edit the file(we can see at the left bottom page prompting insert).
Once writing is completed press ESC button and type colon ( : ) to enter into command mode and type wq (save and quit) command.
Step 6: Type (ls -l) to list the contents along with timestamp.
Step 7: type (cat/more) to display the contents of the file
Note : Cat command display entire content on the screen whereas more display contents that would fit your screen. Basically use more command when file contents is less.
Step 8 : Lets rename the file with new name. Use mv (move) command. It takes 2 parameters mv(existing filename, new_filename to convert)
Step 9: Copy command — it is used to copy file to existing or another directory
Cp to copy file in same directory and saving with new filename
Cp to copy from directory to another.
I created a new directory new_workspace and used (pwd) command to check the new directory path then travelled back to directory from where the file needs to be copied.
used the cp command along with destination directory(new_workspace) path and new filename to be stored.
Step 10. Check the contents of the new file using cat.
Rm (remove) — command is used to delete file from the directory.
Finally, we have completed our first use case. Hope it was informative.
Will post Use case 2 soon with more commands.
Please provide your feedback would help me to improve.
Thank you everyone.