by Tom Victor Posted on July 2, 2016, 1:01 p.m.
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.
Hope you should have some Intrest on learning new stuff.
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
ls ls -l
mdkir folder_name sudo mkdir /folder_name
There a some situations where we want to find a perticular task/Id from above command(ps -ax), here is an example of a node script trigred by rc.local onstartup.
ps -ax | grep discover_ble_devices.js
sudo apt-get install django sudo apt-get install zip sudo apt-get install mysql
sudo apt-get update
content will be updated soon
sudo serviece nginx start sudo serviece nginx stop sudo serviece nginx restart
sudo fdisk -l
sudo lshw -C disk
sudo apt-get install pydf pydf or df or df -Th /dev/sda1
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.
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
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
sudo apt-get install zip zip -r name.zip /directory
sudo apt-get install unzip unzip file.zip -d destination_folder
content will be updated soon
nano file.cof nano file.txt
rm -r -f folder_name
sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql restart
for changing MySQL data folder try this tutorial
The following command will list all the SSH keys saved on your default directory (~/.ssh)
ls -al ~/.ssh
The following command will copy the contents of the file github_rsa.pub, This is a very useful command while playing with ssh keys, an alternative for this is manual copying using cat command.
pbcopy < github_rsa.pub
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 the 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.
ssh-add -K ~/.ssh/GitHub
The above command will add the newly generated SSH key(GitHub and GitHub.pub) to the ssh-agent, this step is must inorder to establish connection over SSH
SSH stands for secure shell. It's running on port 22. It is commonly used for managing a remote server. SFTP protocol is also running on the same port 22. SSH will add an extra level of security while communicating to the remote server. The communication can be achieved 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 kept on the local computer. Since the SSH key is the only way to authenticate it should be kept in a secure and secret location. Use the above method to generate SSH keys. the public key will have a .pub extension.
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 the commonly used Linux commands, its usage, examples... If you have any specific doubt please mention on the comment section below. Hope This tutorial is helpful for you...