Posts

Showing posts with the label Linux Commands

How to reset root password on centos 7

Image
Many methods to reset root password centos 7. if GRUB 2 bootloader then no longer using in single-user mode as well as emergency mode. To below step by step to reset root password centos 7. You may reading link below : awk useful commands examples CentOS/RHEL Use yum Command To Downgrade Upgrade or Rollback Updates Generate and Verify Files with MD5 Checksum in Linux use inotify-tools on centos Step 1: Start the system, on Grub 2 boot screen, you press the e key as shown below. Step 2: In linux16 line or linuxefi on UEFI system, add parameters end line as shown below. rw init=/bin/bash Using Ctrl+A press or Ctrl+E press to start or end a line. Disable paramenters the rhgb and quiet in order to enable system message as shown top. Step 3: you press Ctrl+x to start single user mode passwd Step 4: update selinux information touch /.autorelabel Step 5: To resume the initialization and finish the system boot. exec /sbin/init Video how to reset root password on cen

use inotify-tools on centos

inotifywait - wait for changes to files using inotify. To install inotify-tools on centos sudo yum install inotify-tools To install inotify-tools on ubuntu sudo apt-get install inotify-tools For example, how to monitor folder /home/huupv with action create,delete,modiy,move. The scripts as below: #!/bin/bash #Author huupv #My blog huuphan.com inotifywait -m -r /home/huupv -e create -e delete -e modify -e move | while read FOLDER ACTION1 ACTION2 ACTION3 ACTION4 do         echo "Path $FOLDER Create $ACTION1" >>/tmp/output         echo "Path $FOLDER Delete $ACTION2" >>/tmp/output         echo "Path $FOLDER Modify $ACTION3" >>/tmp/output         echo "Path $FOLDER Move $ACTION4" >>/tmp/output done The man page inotifywait man inotifywait NAME        inotifywait - wait for changes to files using inotify SYNOPSIS        inotifywait  [-hcmrq]  [-e  <event> ] [-t <seconds> ] [--format <fmt> ]

screen command on linux

To install screen on linux For centos/RHEL base system sudo yum install screen -y For ubuntu base system sudo apt-get install screen -y screen command useful for wget,ryncs not lose session, when you detach it. For example, create the screen with title $ screen -t 'zimbra' ssh [email protected] pressing "ctrl+a" n: next the screen (switch between screen) pressing "ctrl+a" p: previous the screen (switch between screen) pressing "ctrl+a" x : lock the screen pressing "ctrl+a" k: kill the screen pressing ctrl+a d : deattach To list the screen [huupv@huupv ~]$ screen -ls There is a screen on:     31083.pts-0.huupv    (Detached) 1 Socket in /var/run/screen/S-huupv. To resume the screen screen -r 31083 How to deattached screen with Attached status [huupv@localhost]$ screen -ls The output There is a screen on: 20655.pts-4.ra3 (Attached)1 Socket in /var/run/screen/S-huupv. [huupv@localhost]$ screen -r -d 20655.pts-4.ra3 Error

Linux basic commands

Linux basic commands How to check version Ubuntu lsb_release -a How to check to distribute cat /etc/*release How to check CPU information cat /proc/cpuinfo How to check PCI devices lspci How to list all USB devices lsusb How to get PC name from IP nmblookup -A <ip> nbtscan <ip> How many connect on server who -H How many core processor nproc How to check full CPU information lscpu  How to create new user adduser huupv passwd huupv For centos usermod -aG wheel huupv For ubuntu echo "huupv ALL=(ALL) ALL" >> /etc/sudoers How to find UUID disk blkid /dev/sda6 lsblk -f To continuous....

How to send email using mail command in linux

Image
in my post, i'm use mail command to send message email. mail -s "Subject title huuphan.com" -S [email protected] <<EOF ---------------------------------------- The content email Hello phan van huu My site: huuphan.com ----------------------------------------- EOF The script sending 100 email from command. #!/bin/sh i=1 for (( i = 1 ; i <= 100 ; i++ )); do  echo "Test Mail $i, Send from mail.huuphan.com" | mailx -v -r "[email protected]" -s "Test Mail $i" -a "/tmp/quotausage" -S smtp="mail.huuphan.com:25" -S smtp-auth=login -S smtp-auth-user="[email protected]" -S smtp-auth-password="123456789" -S ssl-verify=ignore -S nss-config-dir=/etc/ssl/certs [email protected],[email protected] done

xdotool − command−line X11 automation tool

Image
To install xdotool on ubuntu sudo apt-get update sudo apt-get install xdotool To install xdotool on fedora sudo yum install xdotool To display the current coordinates of the mouse cusrsor on linux #while true; do clear; xdotool getmouselocation; sleep 0.1; done The simple script for xdotool #!/bin/bash xdotool mousemove 343 755 click 1 sleep 2 while true do     xdotool mousemove 392 44 click 1     xdotool key "Return"     sleep 3     xdotool key Page_Up     sleep 3     xdotool mousemove 277 580 click 1     sleep 3     xdotool key Page_Down     sleep 3     xdotool mousemove 718 152 click 1     sleep 3     xdotool mousemove 46 482 click 1     sleep 3     xdotool mousemove 383 15 click 1     sleep 3 done Man xdotool http://man.cx/xdotool

How to running cron job every 5 minutes,seconds,hours,days

Image
How to running cron job every 5 minutes,seconds,hours,days. How to running a script a specific interval using cronjob in linux.  To execute a cronjob every 5 minutes */5 * * * * /home/huupv/script.sh To execute a cronjob every 5 hours 0 */5 * * * /home/huupv/script.sh How to running a job every 5 seconds $ cat every-5-seconds.sh #!/bin/bash while true do  /home/huupv/script.sh  sleep 5 done $ nohup ./every-5-seconds.sh & To execute a cronjob every 5th weekday 0 0 * * 5 /home/huupv/script.sh or 0 0 * * Fri /home/huupv/script.sh 0=Sun 1=Mon 2=Tue 3=Wed 4=Thu 5=Fri 6=Sat

Bash Scripting Made Simple: Practical Examples

Bash Scripting Made Simple: Explore practical examples to streamline your workflow and enhance your bash scripting skills effortlessly. List all IP addresses connected to Server Discovering all IP addresses connected to the server is essential for network monitoring and security. Utilize tools like netstat or ss commands to obtain this information efficiently. #!/bin/bash while true; do echo "CTRL+C TO BREAK" netstat -tnu | grep :22 | awk '{print $5}' | cut -f1 -d : | sort | uniq -c | sort -nr | head -n 8 sleep 15 clear done ########################################################################################### # site: huuphan.com # author: phan van huu # List all IP addresses connected to Server # For example: list ip address connected to server via ssh port 22 # awk '{print $5}' | cut -f1 -d : | sort | uniq -c | sort -nr | head -n 8 # awk '{print $5}': the display 5th field only # sort | uniq -c | sort -nr: Sort the list, group it

The usefull linux commands

Welcome to our guide on mastering essential command-line operations and system management tasks! In this blog post, we'll explore practical tips and tricks to streamline your workflow and boost productivity. Whether you're a beginner or an experienced user, these techniques will help you navigate the command line with ease. Join us as we dive into managing log files, executing commands efficiently, and optimizing your system administration skills for success. How to find and delete logs file MORE THAN 30 DAYS OLD # find /path/to/log/ -type f -name \*.log\* -mtime +30 -exec rm {} \; > /dev/null 2>&1 How to find and delete logs file   LESS THAN 30 DAYS OLD # find /path/to/log/ -type f -name \*.log\* -mtime -30 -exec rm {} \; > /dev/null 2>&1 How to one-liner that allows to create a directory and move into it at the same time. # mkdir test-dir && cd $_ How to display size of folder. #du -csbh /path/to/folder How to display output as a table # cat /etc/p

iptables examples

How to allow or denied on iptables firewall on centos. To configure iptables static file on centos.  You may reading link as below: Iptables how to How to reset password on centos 7 Bash script example *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #### Mail port ### -A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 389 -j ACCEPT -s 10.10.9.0/24 -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 465 -j ACCEPT -A INPUT -m state --state NEW -