Basic Linux Commands
In this tutorial we are going to learn about the basic and most useful commands of linux. In the following tutorial I am gona to use a Linux server(Ubuntu 2016 LTS version), But not limited this one only. These are the basic commands of linux, you can use this on any linux machine.
For testing the linux commands you must have a linux installed computer, Here I am using a ubuntu server 2016 LTS. If you are a windows or mac user you can install VM Ware or Virtual Box to try these commands, Since we are only dealing with the terminal, you can install the minimal version of linux on your Virtual machine. But it does not have Graphical Interface You limetted to use KeyBord Only.
AssumptionsHope you should have some Intrest on learning new stuff.
Changing Directory( cd )
Changing working directory is a primary need of any computer user. We all are familial with double clicking, drag and drop,,,all that stuff,,, But in terminal you have a two letter command for that.cd
any other directory
Listing everything in a directory ( ls )
ls ls -l
Make a new directory ( mkdir )
mdkir folder_name sudo mkdir /folder_name
How to know current directory( pwd )
How to install an package or software( sudo apt-get install )
sudo apt-get install django sudo apt-get install zip sudo apt-get install mysql
Updating packages( pwd )
sudo apt-get update
How to uninstall an package or software( remove )
content will be updated soon
Start, stop and restart a program
sudo serviece nginx start sudo serviece nginx stop sudo serviece nginx restart
Listing partitions( sudo fdisk -l )
sudo fdisk -l
All physical hard disk information( sudo lshw -C disk )
sudo lshw -C disk
How to know the disk Space available( df or pydf )
sudo apt-get install pydf pydf or df or df -Th /dev/sda1
How to create a new partition( fdisk )
Use fdisk -l for listing all avilable disks, Then you will get a list of avilable disks and the partitions inside each disk. eg: "/dev/xvda" is the disk and "/dev/xvda1" is the partition. If you want to add new partition in a newly attached disk(Additional storage disk on AWS and Azure are use cases), Let the new disk be /dev/sdb (usualy suffix bfor secod disk or may be difrent in your case, verify using fdisl -l comand). For crating new partition use fdisk command, sudo fdisk /dev/sdb, now you will enter into fdisk utlity. enter m for help, n for new partition. newxt you will be asked for primary or extended paertition. enter p for primary, next is the partition no choose default value 1 (if you need more partitions then it can aso be done once you uderstand the procedure). next is the first and last sectors choose the default value(If you need only one partition). final step is to give write command by entering w. This will execute the new partition table. It can be varified by using the command fdisk -l Eg:
sudo fdisk -l sudo fdisk /dev/sdb welcome to fdisk (util-linux 2.27.1). Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 Command (m for help): w The partition table has been altered.
How to format a partition( fdisk )
First step is to find the exact partition name using list command then use mkfs command for formating
sudo fdisk -l mkfs -t ntfs /dev/sdb1
How to mount a partition or disk( mount )
First step is to create a directory on the root to which the partition to be mount using sudo mkdircommand.
mkdir /mydata mount /dev/sdb1 /mydata
Compressing files in linux( zip )
sudo apt-get install zip zip -r name.zip /directory
Decompressing files in linux( unzip )
sudo apt-get install unzip unzip file.zip -d destination_folder
content will be updated soon
Edicting files in linux( nano )
nano file.cof nano file.txt
Browse on internet in linux( curl )
Downloading files from internet( curl )
Deleting files( rm )
Deleting folder( rm )
rm -r -f folder_name
How to stop and restart mysql server?
sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql restart
for changing mysql data folder try this tutorial
Listing SSH Keys on your computer
ls -al ~/.sshmore details
Generating a new SSH key
ssh-keygen -t rsa -b 4096 -C "email@example.com" or ssh-keygen -t rsa -b 2048 -C "firstname.lastname@example.org"
Now you will be asked for location to save the file. now enter your location
Enter file in which to save the key (/Users/Tomvictor/.ssh/id_rsa): /Users/Tomvictor/.ssh/mysshkey
Then you will be asked for entering a phrase, enter your phrase or simply press enter
Login to remote server using SSH
SSH stands for secure shell. Its running on port 22. It is commonly used for managing remote server. SFTP protocol is also running on the same port 22. SSH will add a extra level of security while communicating to the remote server. The communication can be achived either using a password for authentication or authentication via SSH key. The SSH key method is more secure and safer way. SSH key is two files one is private and other public. The public key will be stored on the remote server while the private key should be keep on the local computer. Since the SSH key is the only way to authenticate it should be kept ina secure and secret location. Use the above method to generate SSH keys. public key will having an .pub extention.
ssh username@Remote_IP or shh username@Remote_domain_name or ssh -i location_of_private_key/privatekey username@Remote_IP_or_Domain_name
So we discussed about the commonly used linux commands, its usage, examples... If you have any specific doubt plese mension onthe comment section below. Hope This tutorial is helpful for you...