Skip to content

Instantly share code, notes, and snippets.

@mehrshaddarzi
Last active November 24, 2023 11:36
Show Gist options
  • Save mehrshaddarzi/5e6464ca07c0728b12b0f6ecbbd4cb0c to your computer and use it in GitHub Desktop.
Save mehrshaddarzi/5e6464ca07c0728b12b0f6ecbbd4cb0c to your computer and use it in GitHub Desktop.
all commandline in ssh linux server

Example 1

#!/bin/bash
echo "Bash version ${BASH_VERSION}..."
for i in {0..10..1}
  do 
     echo "Welcome $i times"
     sleep 2
done

Example 2

#!/bin/bash
#https://www.cyberciti.biz/faq/unix-linux-appleosx-bsd-shell-appending-date-to-filename/

for i in {0..10..1}
  do 
  	now=$(date +"%m_%d_%Y_%H_%M_%S")
     echo "Welcome $i times" > "/home/admin/public_html/bash/$now.txt"
     echo "/home/admin/public_html/bash/$now.txt File is Saved"
     sleep 2
done

Example 3

#!/bin/bash
#https://www.cyberciti.biz/faq/unix-linux-appleosx-bsd-shell-appending-date-to-filename/

for i in {0..11000..1}
  do 
  	now=$(date +"%m_%d_%Y_%H_%M_%S")
    wget --spider "https://wp-dev.ir/risknews-migration-api/create_post/?user_login=mehrshad&user_pass=5p64g49" 2>&1
    if grep --quiet "200 OK" wget-log; then
    echo "ok"
    else
    echo "notok"
    fi
    
    echo "Save post $i times" > "/home/admin/public_html/bash/$now.txt"
    sleep 2
done

Run Single Bash File

bash post.sh

Run in Baskgorund

# https://stackoverflow.com/questions/17385794/how-to-get-the-process-id-to-kill-a-nohup-process
nohup sh post.sh & >/dev/null 2>&1

Kill Background

kill xxx {PID}

Get List PID

ps -ef
mysql -h localhost -u root -p [database_name]
show databases;
create database `ali`;
drop database `ali`;
source C://path//to//file.sql; [Import SQL File, First use database then source in MariaDB]
mysqldump -uUSERNAME -p DATABASE > backup.sql
show tables;
drop table `tablename`;

Create Databse With Import File Without MariaDB Area

mysql -u username -p new_database < data-dump.sql

Export Databse

mysqldump -u USERNAME -p DATABASE_NAME > backup.sql

https://stackoverflow.com/questions/22278217/mysqldump-gzip-commands-to-properly-create-a-compressed-file-of-a-mysql-databa
/usr/bin/mysqldump -u USER -pPASSWD DBNAME | gzip > ~/backups/db.$(date +%F.%H%M%S).sql.gz

With Parameter:

mysqldump --opt --user=username -p --host=yourMySQLHostname --no-tablespaces dbname > nameofyourbackup.sql

Setup Cron Jbo in Cpanel

wget -q -O --no-cache https://xxx.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1	
/usr/bin/mysqldump --user=xxx --password=xxx --host=localhost db_name | gzip > /home/xxx/.backup-database/backup.sql.gz
/usr/bin/mysqldump --user=xxx --password=xxx --host=localhost db_name > /home/xxx/.backup-database/backup.sql

Check Ram and CPU and Space

df -h
free -m
cat /proc/cpuinfo
cat /proc/meminfo

Check Version

https://linuxconfig.org/how-to-check-centos-version

hostnamectl

zip folder

zip -r filename.zip foldername/
nohup zip -r backissue.zip Backissues/ &
https://www.howtogeek.com/414082/how-to-zip-or-unzip-files-from-the-linux-terminal/

unzip file

unzip [filename.zip] -d destination/
tar -xvf archive.tar
tar -zxvf archive.tar.gz
rar x archive.rar

remove file

rm [filename]

Download file

wget [url with http://]

download big file in background

wget -bqc http://bay.uchicago.edu/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

change chomd file

chomd 755 file.zip

Edit File

[server]$ vim test.html

It now shows -- INSERT -- on the bottom left:

When finished editing the file, click the ESC key. This takes you out of INSERT mode and -- INSERT -- disappears from the bottom left of your terminal.

To save the file, type in a colon followed by wq. For example:

:wq

Click 'Enter' to save.

Remove file

rm myFile.txt myFile1.txt myFile2.txt

rm -rf foldername/

rm -rf *

Move file or folder

mv configuration.php-dist configuration.php

mv includes/* ./

mv -u includes/* admin/includes

copy file or folder

cp configuration.php-dist configuration.php

cp -R includes/ includes_backup/

cp -Rf includes/ admin/includes/

New folder

mkdir myDirectory

this place

pwd

Import Databse

mysql -u USERNAME -p DATABASE < backup.sql

check sercurity User

clamscan -ir /home/user_name_from_direct_admin/ > /home/user_name_from_direct_admin/scan_result.txt

infinite Task and Bash File

https://unix.stackexchange.com/questions/521497/how-should-i-run-a-cron-command-which-has-forever-loop https://askubuntu.com/questions/88091/how-to-run-a-shell-script-in-background

CronTab

https://www.youtube.com/watch?v=llUw3RtD-Yw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment