11 November 2022

Sudo on Ubuntu without requiring a password

Using AWS EC2 Ubuntu as a reference. It has a file by the name...
/etc/sudoers.d/90-cloudimg-ubuntu
It has the following content. With this, the user ubuntu can run sudo without a password.
# User rules for ubuntu ubuntu ALL=(ALL) NOPASSWD:ALL

07 April 2022

Secure Copy from Remote Directory

The format to use.
scp -r shortcut:/remote/server/path/file.tar.gz /target/path/
Example:
scp -r shortcut:/home/user/file.tar.gz ~/download

22 March 2022

Systemd or SysVinit

Use the below command to find out which command you should use to manage your Linux services.
ps -p 1 -o comm=

You will either see init (SysVinit) or systemd.

Systemd command SysVinit command
systemctl start service_name service service_name start
systemctl stop service_name service service_name stop
systemctl restart service_name service service_name restart
systemctl status service_name service service_name status
systemctl enable service_name chkconfig service_name on
systemctl disable service_name chkconfig service_name off

22 February 2022

Useful git commands

List config.
git config --list
git config --list --local
git config --list --global
git config --list --system
Set global name and email.
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
Check what's going on
git status
Check changes made to a file
git diff path/to/file
Stage changes
# Stage all
git add .
# Stage one file
git add path/to/file
Untage changes
# Stage all
git reset
# Stage one file
git reset path/to/file
Revert changes made to path/to/file
git checkout path/to/file
Revert all uncommited changes
git checkout .
Commit staged files
git commit -m "Put a message here."
Check commits that had not been pushed.
git log origin/main..main
Check history of path/to/file
git log -p -- path/to/file

29 January 2022

Update directory or file permission recursively in Linux

Change directory permission in my_directory.
find my_directory -type d -exec chmod 755 {} \;
Change file permission in my_directory.
find my_directory -type f -exec chmod 644 {} \;

13 January 2022

Remove duplicate lines in Visual Studio Code

Search and replace in Visual Studio Code.

Search for

^(.*)(\n\1)+$
Replace with
$1

07 January 2022

MongoDB JSON to PHP array

Search and replace in Visual Studio Code.

Search for

\{\n.*\$oid.*"(.*)"\n.*\}
Replace with
new MongoDB\BSON\ObjectId("$1")
Search for
\{\n.*numberDouble.*"(.*)"\n.*\}
Replace with
$1
Search for
\{\n.*numberInt.*"(.*)"\n.*\}
Replace with
$1