Skip to content

Instantly share code, notes, and snippets.

@ManishLSN
Created December 27, 2017 06:14
Show Gist options
  • Save ManishLSN/10079caf50af1e3da199eaa547c7337f to your computer and use it in GitHub Desktop.
Save ManishLSN/10079caf50af1e3da199eaa547c7337f to your computer and use it in GitHub Desktop.
willl keep all usefull commands here
# for setting node path in windows
setx NODE_PATH "%NODE_PATH%;C:\Users\winbdows 7\AppData\Roaming\npm\node_modules"
@manishjaingit
Copy link

manishjaingit commented Nov 28, 2018

zip file but exclude some directory.

zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*

@manishjaingit
Copy link

to check lets encrypt expiry.

echo | openssl s_client -connect <you server here>:443 2>/dev/null | openssl x509 -noout -dates

@manishjaingit
Copy link

manishjaingit commented Feb 15, 2019

for creating symlinks / shortcut path

sudo ln -s <path of the actuall folder> <symlink name with the path or (if you are on same directory so simply folder name)>

@manishjaingit
Copy link

manishjaingit commented Feb 19, 2019

for search in all places,

sudo find ./ -xdev -type f -print0 | xargs -0 grep -H "800x600"

for saving output in a file.

SomeCommand > SomeFile.txt

https://askubuntu.com/a/420983/652975

@manishjaingit
Copy link

manishjaingit commented Apr 9, 2019

To insert the record in the log file by php.

$value) { if (preg_match('/^HTTP_/',$name)) { $name = strtr(substr($name,5),'_',' '); $name = ucwords(strtolower($name)); $name = strtr($name,' ','-'); $headerList[$name] = $value; } } $data = sprintf("%s %s %s\n", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PROTOCOL']); foreach ($headerList as $name => $value) { $data .= $name.': '.$value."\n"; } $data .= "\n"; $data .= "\n now we will show request data"; $data .= var_export($_REQUEST, true); file_put_contents($targetFile, $data.file_get_contents('php://input')."\n"); } logRequest("tmp/post-".time().".log"); ?>

@manishjaingit
Copy link

to setup htpasswd in nginx server.

sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd nginx
cat /etc/nginx/.htpasswd
sudo nano /etc/nginx/sites-available/default

then add this two line in location code

    auth_basic "Private Property";
    auth_basic_user_file /etc/nginx/.htpasswd;

then restart the server.
sudo service nginx reload

and your username would be: nginx
and password:

@manishjaingit
Copy link

to set time on ubuntu server.

sudo dpkg-reconfigure tzdata

@manishjaingit
Copy link

for find node (number of files) in a directory.

for i in $(find -maxdepth 1 -type d); do echo -ne "${i/.\/}\t"; find $i -printf "%i\n" | sort -u | wc -l; done | awk '{ print $2,$1}' | sort -k2

@manishjaingit
Copy link

Find and replace in all files.
first, go that folder path. then

With the g flag to replace all the occurrences on a line.
find ./ -type f -exec sed -i 's/string1/string2/g' {} \;

For global case insensitive:
find ./ -type f -exec sed -i 's/string1/string2/gI' {} \;

@manishjaingit
Copy link

find and kill any port number.

Find:
lsof -i :3000
Kill:
kill -9

@manishjaingit
Copy link

to find last 30 days changes in files

find app/ -type f -mtime -2 -exec ls -l {} \; > last30days.txt

@manishjaingit
Copy link

to search

grep -rl "Mindestbestellmenge" app/design/

@manishjaingit
Copy link

for find latest edited / modified file name

find ./ -printf '%T+ %p\n' | sort -r | head

@manishjaingit
Copy link

manishjaingit commented Aug 8, 2022

for search word in a file and display that line

sudo grep -R fastcgi_pass /etc/nginx/sites-enabled/ | grep -Ev '#\s+fastcgi_pass'

@manishjaingit
Copy link

replace in particular file use this command.

sudo sed -i --follow-symlinks \ 's|php7.4-fpm.sock|php8.0-fpm.sock|g' \ /etc/nginx/sites-enabled/default

here in the last line you just need to write file path

@manishjaingit
Copy link

uninstall the particular version

sudo apt -y purge php7.4*

@manishjaingit
Copy link

manishjaingit commented Sep 20, 2022

understanding docker. you can run simple hello word page on plane machine.
https://github.com/karthequian/docker-helloworld

sudo docker pull karthequian/helloworld:latest
sudo docker run -p 80:80/tcp "karthequian/helloworld:latest"

for listing all docker

sudo docker ps -a

to load container that configuration saved in yml file.

sudo docker-compose -f /srv/docker-compose.yml up -d

@manishjaingit
Copy link

if have multiple php installed on server and wanted to choose which version is primary in use.

sudo update-alternatives --config php

@manishjaingit
Copy link

manishjaingit commented Dec 19, 2022

#For breaking files into multiple parts use this command from the git bash command line.

split prod-db-backup-220920221.sql -l 100000

#This will break your file into lines of 1lakh line per file.

if you wanted to break it in memory so you can also do it by command

into files of size 500MB each: split myLargeFile.txt -b 500m

@manishjaingit
Copy link

list out the last updated files.

find . -type f -newermt "-24 hours" 
find . -type f -newermt "-10 minutes" 
find . -type f -newermt "1 day ago" 
find . -type f -newermt "yesterday"

@manishjaingit
Copy link

to kill particular port.
sudo npx kill-port 5432

@manishjaingit
Copy link

clear memory cache from Linux ubuntu.
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

@manishneedsmet
Copy link

for renew the letsencrypt certificates.

sudo certbot renew

@mjainavas
Copy link

mjainavas commented Feb 15, 2024

Create alias in ubuntu

nano ~/.bashrc

write something alias like below.

alias apachelog='cd /var/log/apache2'
alias cronlog='cd /var/log/mysite/cron'
alias egrep='egrep --color=auto'
alias fdate='date "+%Y%m%d.%H%M%S"'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias n='nano'
alias site='cd /var/www/vhosts/mywebsite/httpdocs'
alias sitelog='cd /var/log/mywebsite/httpdocs'
alias findinsite="searchin(){ find /var/www/vhosts/mywebsite/httpdocs/ -xdev \( -path '*/.git/*' -o -path '*/.svn/*' -o -path '*/assets/css/*' -o -path '*/assets/js/*' \) -prune -o -type f -exec grep -H -e \"\$*\" {} +;}; searchin"
alias findincrm="searchincrm(){ find /var/www/vhosts/mywebsite/crm-v2/ -xdev ! -path '/var/www/vhosts/mywebsite/crm-v2/.git/*' ! -path '/var/www/vhosts/mywebsite/crm-v2/old_vendor/*' -type f -exec grep -H -e \"\$1\" {}>

After saving the file, please run source cmd to get it executable.

source ~/.bashrc

then you can run this directly like
findinsite HelloWorld

@manishjaingit
Copy link

for renew the letsencrypt certificates.

sudo certbot renew

To check SSL Date range:

echo | openssl s_client -connect 13.xxx.xxx.91:443 2>/dev/null | openssl x509 -noout -dates

@manishjaingit
Copy link

Find all files based on extensions related

find . -name \*.log -ls | sort -r -n -k7

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