Linux Basic

At the moment we are going to be taught extra about some command strains for Linux that we have now to know. So we go on now

Linux Basic

From smartphones to vehicles, supercomputers and residential home equipment, dwelling desktops to enterprise servers, the Linux working system is in all places.

Linux has been around for the reason that mid-Nineteen Nineties and has since reached a user-base that spans the globe. Linux is definitely in all places: It’s in your telephones, your thermostats, in your vehicles, fridges, Roku units, and televisions. It additionally runs a lot of the Web, all the world’s prime 500 supercomputers, and the world’s inventory exchanges.

However, apart from being the platform of option to run desktops, servers, and embedded programs throughout the globe, Linux is likely one of the most dependable, safe, and worry-free working programs accessible.

Right here is all the knowledge it’s essential to stand up to hurry on the Linux platform.

Extra element: https://www.linux.com/what-is-linux/

Helpful shortcuts

Utilizing The Terminal 

The examples on this doc assume that you’re utilizing a POSIX-compliant (similar to bash, sh, zsh, ksh) shell. 

Massive parts of GNU/Linux performance are achieved utilizing the terminal. Most distributions of Linux embrace terminal emulators that permit customers to work together with a shell from their desktop surroundings. A shell is a command-line interpreter that executes person inputted instructions. Bash (Bourne Once more SHell) is a standard default shell amongst many Linux distributions and is the default shell for macOS. 

These shortcuts will work if you’re utilizing Bash with the emacs keybindings (set by default): Open terminal 

Ctrl + Alt + T or Tremendous + T  

Cursor motion 

Ctrl + A Go to the start of the road you might be at present typing on. 

 Ctrl + E Go to the tip of the road you might be at present typing on. 

 Ctrl + XX Transfer between the start of the road and the present place of the cursor.  Alt + F Transfer cursor ahead one phrase on the present line. 

 Alt + B Transfer cursor backward one phrase on the present line. 

 Ctrl + F Transfer cursor ahead one character on the present line. 

 Ctrl + B Transfer cursor backward one character on the present line. 

Textual content manipulation 

Ctrl + U Reduce the road from the present place to the start of the road, including it to the clipboard. If you’re on the finish of the road, reduce your complete line. 

 Ctrl + Okay Reduce the road from the present place to the tip of the road, including it to the clipboard. If you’re initially of the road, reduce your complete line. 

 Ctrl + W Delete the phrase earlier than the cursor, including it to the clipboard. 

 Ctrl + Y Paste the very last thing from the clipboard that you just reduce just lately (undo the final delete on the present cursor place). 

 Alt + T Swap the final two phrases earlier than the cursor. 

 Alt + L Make lowercase from cursor to finish of phrase. 

 Alt + U Make uppercase from cursor to finish of phrase. 

 Alt + C Capitalize to finish of phrase beginning at cursor (entire phrase if cursor is initially of phrase).  Alt + D Delete to finish of phrase beginning at cursor (entire phrase if cursor is initially of phrase).  Alt + . Prints the final phrase written in earlier command. 

 Ctrl + T Swap the final two characters earlier than the cursor. 

Historical past entry 

Ctrl + R Allows you to search by means of beforehand used instructions. 

 Ctrl + G Depart historical past looking out mode with out working a command. 

 Ctrl + J Allows you to copy present matched command to command line with out working it, permitting you to

make modifications earlier than working the command. 

 Alt + R Revert any modifications to a command you’ve pulled out of your historical past, in case you’ve edited it.  Ctrl + P Exhibits final executed command, i.e. stroll again by means of the command historical past (Just like up arrow). 

 Ctrl + N Exhibits subsequent executed command, i.e. stroll ahead by means of the command historical past (Just like down arrow). 

Terminal management 

Ctrl + L Clears the display screen, just like the clear command. 

 Ctrl + S Cease all output to the display screen. That is helpful when working instructions with a number of lengthy output. However this does not cease the working command. 

 Ctrl + Q Resume output to the display screen after stopping it with Ctrl+S. 

 Ctrl + C Finish at present working course of and return the immediate. 

 Ctrl + D Log off of the present shell session, just like the exit or logout command. In some instructions, acts as Finish of File sign to point {that a} file finish has been reached. 

 Ctrl + Z Suspends (pause) at present working foreground course of, which returns shell immediate. You may then use bg command permitting that course of to run within the background. To once more convey that course of to foreground, use fg command. To view all background processes, use jobs command. 

 Tab Auto-complete recordsdata and listing names. 

 Tab Tab Exhibits all potentialities, when typed characters would not uniquely match to a file or listing title. 

Particular characters 

Ctrl + H Identical as Backspace. 

 Ctrl + J Identical as Return (traditionally Line Feed). 

 Ctrl + M Identical as Return (traditionally Carriage Return). 

 Ctrl + I Identical as Tab. 

 Ctrl + G Bell Character. 

 Ctrl + @ Null Character. 

 Esc Deadkey equal to the Alt modifier. 

Shut Terminal 

Ctrl + Shift + W To shut terminal tab. 

 Ctrl + Shift + Q To shut whole terminal. 

Alternatively, you may swap to the vi keybindings in bash utilizing set -o vi. Use set -o emacs to change again to the emacs keybindings.

SYSTEM INFORMATION

# Display Linux system information
uname -a

# Display kernel release information
uname -r

# Show which version of redhat installed
cat /etc/redhat-release

# Show how long the system has been running + load
uptime

# Show system host name
hostname

# Display the IP addresses of the host
hostname -I

# Show system reboot history
last reboot

# Show the current date and time
date

# Show this month's calendar
cal

# Display who is online
w

# Who you are logged in as
whoami

HARDWARE INFORMATION 

# Display CPU information
cat /proc/cpuinfo

# Display memory information
cat /proc/meminfo

# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
free -h

# Display free hard disk space linux
df -h

# Test for unreadable blocks on disk sda
badblocks -s /dev/sda

PERFORMANCE MONITORING AND STATISTICS

# Display and manage the top processes
top

# Display virtual memory statistics
vmstat 1

# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
free -h

# Execute "df -h", showing periodic updates
df -h

USER INFORMATION AND MANAGEMENT

# Display the user and group ids of your current user.
id
id username


# Display the last users who have logged onto the system.
last

# Show who is logged into the system.
who

# Show who is logged in and what they are doing.
w

# Create a group named "test".
groupadd test

# display all list groups
cat /etc/group


# Create  users 
useradd username

# Display list users 
cat /etc/passwd 

# set an account to group 
useradd -G groupname username

# Set password user
passwd john

# Delete the john account.
userdel john

FILE AND DIRECTORY COMMANDS

# List all files in a long listing (detailed) format
ll
ls
ls -al

# Display the present working directory
pwd

# Create a directory
mkdir directory

# Remove the directory and its contents recursively 
rm -r directory

# Forcefully remove directory recursively
rm -rf directory

# Create an empty file or update the access and modification times of file. 
touch file

# Remove (delete) file
rm file


# Force removal of file without prompting for confirmation
rm -f file


# Copy file1 to file2
cp file1 file2

# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.
cp -r source_directory destination

# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
mv file1 file2

# Create an file or update the access and modification times of file. create file 
vi file
- Insert value 
i
- Exit vi
ESC > :wq

# View the contents of file
cat file


# Display the first 10 lines of file
head file

# Display the last 10 lines of file
tail file

# Display the last 10 lines of file and "follow" the file as it grows.
tail -f file

PROCESS MANAGEMENT

# Display your currently running processes
ps

# Display all the currently running processes on the system.
ps -ef

# Display process information for processname
ps -ef | grep processname

# Display and manage the top processes
top

# Kill process with process ID of pid
kill pid

FILE PERMISSIONS

PERMISSION      EXAMPLE          U   G   W
rwx rwx rwx     chmod 777 filename 
rwx rwx r-x     chmod 775 filename
rwx r-x r-x     chmod 755 filename  
rw- rw- r–     chmod 664 filename
rw- r– r–     chmod 644 filename    

NOTE: Use 777 sparingly!         LEGEND        
U = User        
G = Group        
W = World        
r = Read        
w = write        
x = execute        
– = no access

NETWORKING

Solurion 1

  1. list all network devices
    nmcli d
  2.  Open the configuration file for your network interface
    vi /etc/sysconfig/network-scripts/ifcfg-

3. Add the following settings. If a configuration already exists, modify it to look like the following:

         DEVICE=enp3s0
         ONBOOT=yes
         DHCP=yes

For Static IP

   DEVICE=enp3s0
   ONBOOT=yes
   IPADDR=192.168.1.10
   NETMASK=255.255.255.0
   GATEWAY=192.168.1.1

4. Save your changes and exit
5. Your new settings will not apply until the network interface is restarted or brought online. If you are remotely
logged into the server and modifying the network settings of the interface you are connected to, reboot the system.
6. Restarting the network interface.
    ifdown enp0s3
    ifup enp0s3

# install net-tools
yum install net-tools

# Display all network interfaces and ip address
ip address show or
ifconfig -a
# Display eth0 address and details
ifconfig eth0
# Query or control network driver and hardware settings
ethtool eth0
# Send ICMP echo request to host
ping host
# Display status network
sudo systemctl status network.service 
or
sudo systemctl restart network
# Stop Network
sudo systemctl stop network.service
or 
sudo systemctl stop network
# Start the network interface.
sudo systemctl start network.service
or 
sudo systemctl start network
or  ifdown enp0s3
    ifup enp0s3

Solution 2
Configuring a Static IP

If you want to set the connection to have a static IP address, you can modify the configuration with the Network Manager.

Coomand for Open GUI Network: nmtui

1. First, open the required connection settings. If you have followed the steps outlined in the section above, you should already have the Edit a connection window in front of you.

2. To set a static IP address for the IPv4 configuration, open the drop-down menu next to the name of the appropriate connection.

3. By default, it is set to Automatic. Change the settings to Manual.
4. Then, select the Show option for the given network to add the necessary information.
5. Now you can add information related to your connection. This includes the addresses, gateways, DNS servers, and search domains. You don’t have to fill out all the fields.
6. Finally, make sure to enable the option for requiring IPv4 addressing for this connection and automatic connection.
7. Select OK and Back to return to the main menu.

ARCHIVES (TAR FILES)

# Create tar named archive.tar containing directory.
tar cf archive.tar directory

# Extract the contents from archive.tar.
tar xf archive.tar

# Create a gzip compressed tar file name archive.tar.gz.
tar czf archive.tar.gz directory

# Extract a gzip compressed tar file.
tar xzf archive.tar.gz

# Create a tar file with bzip2 compression
tar cjf archive.tar.bz2 directory

# Extract a bzip2 compressed tar file.
tar xjf archive.tar.bz2

INSTALLING PACKAGES

# Search for a package by keyword.
yum search keyword

# Install package.
yum install package

# Display description and summary information about package.
yum info package

# Install package from local file named package.rpm
rpm -i package.rpm

# Remove/uninstall package.
yum remove package

# Install software from source code.
tar zxvf sourcecode.tar.gz
cd sourcecode
./configure
make
make install

SEARCH

# Search for pattern in file
grep pattern file
Ex: grep "a" abc.txt
# Search recursively for pattern in directory
grep -r pattern directory

# Find files in /home/john that start with "prefix".
find /home/john -name 'prefix*'

# Find files larger than 100MB in /home
find /home -size +100M

SSH LOGINS

# Connect to host as user
ssh [email protected]

# Connect to host using port
ssh -p port [email protected]

# Connect from Window to server
useing program Putty 
download Putty here

DISK USAGE

# Show free and used space on mounted filesystems
df -h

# Show free and used inodes on mounted filesystems
df -i

# Display disks partitions sizes and types
fdisk -l

# Display disk usage for all files and directories in human readable format
du -ah

# Display total disk usage off the current directory
du -sh

DIRECTORY NAVIGATION

# To go up one level of the directory tree.  (Change into the parent directory.)
cd ..

# Go to the $HOME directory
cd

# Change to the /etc directory
cd /etc

Install Apache Web Server

  1. First step is to install web server Apache. 

         sudo yum -y install httpd 

          Once it is installed, enable (to run on startup) and start Apache webserver service. sudo systemctl enable —            now httpd 

          Point your browser to: 

          http://localhost  or IP

    2. Install MariaDB Server 

       sudo yum -y install mariadb-server 

       Then start and enable (on startup) the MariaDB server: 

       sudo systemctl enable –now MariaDB 

   3. Install PHP 

         sudo yum -y install php php-common 

         Then restart Apache’s httpd service. 

         sudo systemctl restart httpd 

         To test PHP, create a file called index.php in /var/www/html

          Then point your browser to: 

          http://localhost or IP /index.php 

     4. Install FTP

yum -y install FTP

Example Coding PHP Connect MariaDB

  1. Create file connect.php
  2. Open and write code here

<?php
$servername = “localhost”;
$username = “root”;
$password = “PasswordDB”;
$dbname = “databaseName”;

// Create connection
$conn= mysqli_connect($servername,$username,$password,$dbname);
// Check connection
if (!$conn) {
die(“Can not connect Database: ” . mysqli_connect_error());
}
echo “Connect Database Successful.”;
?>

Advertisements