Posts

Showing posts from December, 2018

File count recursively in a directory

Command find DIR_NAME -type f | wc -l

Generate SSH RSA key

Sample ssh-keygen -t rsa

List first/last files in a directory

Sample ls -1t | head -5 ls -1t | tail -5

Fix locale error in Debian OS SSH connection

Solution export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 export LANGUAGE=en_HK.UTF-8 export LANG=en_HK.UTF-8 export LC_ALL=en_HK.UTF-8 locale-gen en_HK.UTF-8 locale-gen en_US.UTF-8 en_HK.ISO-8859-1en_HK.UTF-8 en_US.ISO-8859-1 en_US.ISO-8859-15 en_US.UTF-8 dpkg-reconfigure locales

Silent output in Cron job

Solution xxxxxxx > /dev/null

Error: rm: argument list too long

Solution find . -name "filename*" | xargs mv -t /home/directory find . -name "*.tmp" -delete

LVM partition fdisk a Linux hard-drive

Sample fdisk -l fdisk /dev/sdb root@Mega:~# fdisk /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): "enter" Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): "enter" Using default value 2610 Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. root@Mega:~# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created root@Mega:~# vgdisplay --- Volume group --- VG Name Mega VG Size 19.76 GiB root@Mega:~# vgextend Mega /dev/sdb1 Volume group "Mega" successfully extended root@Mega:~# pvscan PV /dev/sda5 VG Mega lvm2 [19.76 GiB / 0 free] PV /dev/sd...

Sample script for updating current IP in dd-wrt, Open-wrt and other linux based OS

Sample Script (Cloudflare) #!/bin/bash GET_LATEST_IP="curl ifconfig.co" LATEST_IP=`$GET_LATEST_IP` #echo $LATEST_IP CLOUDFLARE="curl -X PUT \"https://api.cloudflare.com/client/v4/zones/ZONE-ID/dns_records/DNS-RECORD-ID\" -H \"X-Auth-Email: AUTH-EMAIL-ADDRESS\" -H \"X-Auth-Key: AUTH-KEY\" -H \"Content-Type: application/json\" --data '{\"type\":\"A\",\"name\":\"DOMAIN-NAME\",\"content\":\"$LATEST_IP\",\"ttl\":1,\"proxied\":false}'" RESPONSE=`$CLOUDFLARE` #echo $RESPONSE Sample ID Format ZONE-ID: xxx517f1e30dbxxxc1f8be73xxx6ab2a DNS-RECORD-ID: xxxd3db8axxx026xxx95876a77703fe1 AUTH-EMAIL-ADDRESS: name@email.com AUTH-KEY: xxxa30184b74axxx8b3e67xxx5d426fe7xx16 DOMAIN-NAME: xxx.yyy.com Get Latest IP curl ifconfig.co > /root/ip Get ZoneID curl -X GET "https://api.cloudflare.com/client/v4/zones" \ -H "X-Auth-Email: AUTH-EMA...

Reset Debian Password

Solution In the boot menu, edit the default kernel scripts by pressing "e" (select the kernel file you need to edit). Local the line with the keyword starting with "kernel" or "linux", at the end of the line, insert: init=/bin/bash Then save and reboot (usually Ctrl-X or F10). You can then mount the hard-drive in the booted kernel, with: mount -o remount / And then perform password change with: passwd Reference https://www.itzgeek.com/how-tos/linux/debian/how-to-reset-root-password-on-debian-9-stretch.html