Learning linux basic
Ugonna
Posted on November 20, 2024
Linux is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution (distro), which includes the kernel and supporting system software and libraries, many of which are provided by the GNU Project.
The following steps below are basic linux commands.
Open VMware Workstation Pro.
- First update packet index by tying sudo apt update Next in the terminal, type sudo apt install open-vm-tools -y In the terminal, type sudo reboot. To run the account as administrator you must be in root, so type the command sudo su. it will prompt for a password which would be invisible to the eye when tying. This is the root
- How to navigate file system in linux i.pwd (print working directory)- it prints the current working directory. pwd shows the part one is currently in The above image shows we are in the home directory. ii. Ls- list files or directory contents. since there is no files in the account so create new directory before testing ls. So type mkdir ugodir1 and mkdir ugodir2 to create directories ugodir1 and ugodir2 respectively. Then type ls to see the newly created directories ugodir1 and ugodir2 iii. The clear commands helps clear everything on the screen. This is the initial screen This is the cleared screen iv. The history command shows all previous commands performed in the vmware The above image shows there have been 25 commands performed earlier. v. ls -l: list directory contents. it lists files and directories with detailed information (permissions, owner, size, etc.) vi. cd.. moves one directory up vii. To leave the root shell and back to normal interface type exit
- Files and directory operations: Before initiating more commands we have to be in root. so type the command sudo su i. touch command is used to create new empty file. Type in the terminal touch ugo.txt to create ugo.txt file ii. cp: helps to copy files or directories. To do that type cp file.txt /path/to/destination in your terminal. That is copies file.txt to the specified directory. So type cp ugo.txt ugodir2 Then cd (change directory) into ugodir1 and ls to view if there is any file in the directory The above image shows that there is no file in ugodir1
iii. mv: move or rename files or directories. its done by typing mv file.txt/path/to/destination in your terminal or shell. That is file.txt to the specified directory. To perform the above, check if there is any file in the directory (ugodir1) you want to move the file ugo.text to.
First, you have to leave the current directory with the command cd ugodir1 and ls it
Before performing, the move command we have to leave the current directory ugodir1 with the command cd ..
To move ugo.txt type in your terminal type mv ugo.txt ugodir1 and ls it
In the image above, from the one annotated green shows that the file ugo.txt is not there, so it has been moved.
To check if the file ugo.txt has being moved to directory ugodir1, you cd into it and do an ls.
iv. cat [file name]: display contents of a file. The cat command has to be performed on a file that has content inside. So, we are going to use the vim command to edit/add contents to ugo.txt file.
v. vim command: ugo.txt is an empty file. To add contents into it type vim ugo.txt
The below image, is the empty ugo.txt file
Type in the information you want to be in the ugo.txt file. When you are done to exit the ugo.txt file press escape button, press shift and : button together and wq. wq means w for save while q means quit.
continauation of cat command: To view what is in ugodir1, type cat ugo.txt
vi. rm command: rm[file name]: removes (deletes) a file...
type rm file.txt in your terminal or shell. it deletes file.txt.
So type rm ugo.txt and do an ls shows the file ugo.txt has been removed
In the above image, the green annotation shows that ugo.txt file has been removed from ugodir1 directory.
vii. rmdir command: removes (deletes) an empty directory. Type rmdir ugodir1 in your shell or terminal. It deletes the directory called ugodir1. Before performing the above command, use the command cd .. and ls to view the directories
To remove directory ugodir1, you type in the terminal rmdir ugodir1 and ls it.
In the above image, in the green annotation shows that ugodir1 has been delected.
Viewing and editing files:
i. less [filename]: view the contents of a file one screen at a time.
Type less file.txt in your terminal or shell.
It opens file.txt for viewing, allowing you to scroll through the content.
ii. vim[filename]: Edit a file using vim text editor.
Type vim file.txt in your terminal or shell.
Opens file.txt in the vim editor for editing that is it create a file and opens it for editing at the same time unlike touch command that only creates am empty text file.
so type in the terminal vim stella1.txt to create the file stella1 for editing
The below image is the stella1 file for editing
To edit anything in stella1.txt file press i
System and information management.
i. uname -a: Display detailed information about the system.
Type uname -a in your terminal or shell.
Prints all system information, including the kernel version.
The image below explains it. The green annotation shows the detailed information about the system
ii. df -h: Displays disk space usuage.
Type df -h in your terminal or shell.
Shows available disk space in human-readable format
The above image the green annotation is the available disk space in human-readable format.
iii. free -h: Display memory usuage.
Type free -h in your terminal or shell.
Shows used and available memory in human-readable format. The below image explains the command. The green annotation is the used and available memory in human-readable format
.
iv. top: Display running processes and system resource usage.
Type top in your terminal or shell.
Shows a real-time view of running processes, including CPU and memory usage
Type top in your terminal and press enter
Below image is the view
v. grep[pattern or search-term] [file]: search for a pattern.
Type grep "search-term" file.txt in your terminal
Search for search_term within file.txt and print matching lines.
First of check if there is still in file in directory ugodir2. cd into ugodir2 and ls it
From the above image it shows that ugo.txt file is still there so, type cat ugo.txt
The green annotation shows that the file ugo.txt that we typed something on has being deleted.
Then use the vim command to create content in the ugo.txt file. so type in the terminal vim ugo.txt
This takes you to another page, press i in the keyboard to enable tying. type the in content you want to be in ugo.txt file such as (lets get some grep information)
To go back to the terminal press escape, shift and colon key at the same time, then wq and enter.
The type in the terminal, grep information ugo.txt. it searches for the word information in the ugo.txt file. This shown by the green annotation in the image below with the search word "information" highlighted red.
Editing a text file:
i. To quit vim/vi editor. Follow the following steps
a. press the escape key on your keyboard
b. press shift and : key on your keyboard at the same time
c. type wq and press enter key.
type in the terminal vim ugo.txt
when you press escape key, it leaves the insert mode. Then press shift and : key at the same time. This will prompt a colon (:) key at the bottom of the ugo.txt file
Then press wq to save and quit and return back to the terminal.
Posted on November 20, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.