ex / utils

Some utility files and documents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Utils

List all files in repo

$ svn list --verbose -R path/to/repo >> fileList.txt

Fast deletion Windows folder

$ rmdir /s/q C:\folder\path

Export database

$ mysqldump -u YourUser -p YourDatabaseName > exportedFile.sql

mySQL copy a table

$ CREATE TABLE myTable_copy LIKE myTable; 
$ INSERT myTable_copy SELECT * FROM myTable;

SVN diff ignoring whitespace and EOL

$ svn diff path/to/file --diff-cmd /usr/bin/diff -x "-w"

SVN revert recursively current directory

$ svn revert . --depth=infinity

Disk usage: du

$ du -h -d1 /usr/svn/

For windows: https://learn.microsoft.com/en-us/sysinternals/downloads/du

$ du64 -nobanner -l 1 "C:\path"

Obtaining root access

sudo su -

Making file executable: chmod

$ chmod +x script.pl

Accessing apache2 logs

sudo usermod -aG adm YourUserName
nano /var/log/apache2/access.log

Killing perl process in linux

https://serverfault.com/questions/836578/killing-a-perl-process-in-linux

$ ps -ef | grep backup
user  1234  0 Feb02 ?        01:13:31 /usr/bin/perl ...

$ sudo kill 1234

SVN local path

svn ls file:///C:/Path/To/SvnDir    

Downloading a file with curl

curl http://some.url --output some.file

Downloading a file from Google Drive

https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive

Replace FILEID and FILENAME:

$ wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt

Deleting full directories recursively and forcefully (DON'T USE THIS IN /ROOT)

$ sudo rm -rf dirs_*

Silently extracting protected 7z file

$ nohup 7z x file.7z -o"/mnt/efs/path" -pPASSWORD -y &

Keep process running after SSH disconnection

$ nohup long-running-process &
to see the log:
$ tail -f nohup.out

Install 7zip in AWS Linux

https://gist.github.com/marcesher/7168642

$ sudo yum-config-manager --enable epel
$ sudo yum install -y p7ip
$ sudo cp /usr/bin/7za /usr/bin/7z

HTTP SVN server

http://northwaygames.com/setting-up-subversion-on-amazon-ec2-for-free/

https://meetawaiszafar.medium.com/install-configure-svn-server-on-ubuntu-20-04-with-apache2-6dcd7d9a49e9

sudo a2enmod dav_svn
sudo a2enmod authz_svn

<Location /svn>
   DAV svn
   SVNParentPath /var/www/svn
   AuthType Basic
   AuthName "Authorization SVN"
   AuthzSVNReposRelativeAccessFile authz
   AuthUserFile /etc/apache2/dav_svn.passwd
   Require valid-user
</Location>

https://askubuntu.com/questions/767504/permissions-problems-with-var-www-html-and-my-own-home-directory-for-a-website

sudo chown -R www-data:www-data /var/www/svn
sudo chmod -R 775 /var/www/svn
    
## First create pwd file
sudo htpasswd -m -b /etc/apache2/dav_svn.passwd [newuser] [newpwd]

Testing POST apis with curl

curl -d "param1=value1&param2=value2" -X POST http://localhost:8081/postMethod

curl -d "{\"key1\":\"value1\"}" -H "Content-Type: application/json" -X POST http://localhost:8081/echo

router.post( '/echo', ( req, res ) => {
    logger.debug( `echo/ ${JSON.stringify( req.body )}` );
    res.send( req.body );
} );    

Adding mysql super user with remote access

https://stackoverflow.com/questions/6239131/how-to-grant-remote-access-permissions-to-mysql-server-for-user/27644973

CREATE USER 'user'@'localhost' IDENTIFIED BY 'pwd';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;

CREATE USER 'user'@'%' IDENTIFIED BY 'pwd';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;

SHOW GRANTS FOR user;
FLUSH PRIVILEGES;

Ignoring a directory on a checked out SVN repo

svn update --set-depth exclude folderToIgnore

Deleting temporary files in linux

https://serverfault.com/questions/232525/df-in-linux-not-showing-correct-free-space-after-file-removal/232526

df
lsof | grep deleted
killall -9 gdrive
du -hs * | sort -rh | head -10

Creating svn service in Windows

sc create svnserve binpath="\"C:\pathTo\svnserve.exe\" --service -r D:\repoPath" displayname="SVN Server" depend=Tcpip start=auto

Compressing folder

sudo apt-get install zip unzip -y
zip -r OUTPUT.zip FOLDER

Show system info

cat /var/run/motd.dynamic

Logging crontab

https://www.cyberciti.biz/faq/how-to-check-cron-logs-in-ubuntu-linux/

$ sudo nano /etc/rsyslog.d/50-default.conf

Uncoment the line (i.e. remove #):
cron.*                          /var/log/cron.log

$ sudo service rsyslog restart
$ sudo service cron restart    

Scheduling: crontab

http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/

$ sudo crontab -e

## minute : hour : day_of_month : month : day_of_week : command
15 10,13,17 * * 1-6 /usr/svn/back.pl > /usr/svn/back.log 2>&1
1 1 * * 2-6 /home/utils/backup_mantis.pl 2>&1
0 23 * * 7 /usr/svn/backfull.pl > /usr/svn/backfull.log 2>&1
@reboot /home/utils/rebootmail.pl

Change user and group owner (recursive)

$ chown -R username:group /path/directory/

Send file by FTP

$ curl -T my-local-file.txt ftp://ftp.example.com --user username:password

Download file by FTP

$ curl --user username:password 'ftp://ftp.host.com/file' -o '/path/to/download'

Simlinks

Windows
mklink [[/d] | [/h] | [/j]] <Link> <Target>
$ mklink /D C:\xampp\htdocs\www C:\dev\html\project\build
Linux
$ ln -s /path/target /path/symlink

GIT: changing previous commit metadata (author, etc)

https://stackoverflow.com/questions/3042437/how-to-change-the-commit-author-for-one-specific-commit

git rebase -i <HASH_OF_COMMIT_BEFORE_THE ONE_WE_WANT_TO_CHANGE>
## change 'pick' to 'edit' on the editor, [ESC] + :wq (to close vim)
git commit --amend --author="Author Name <email@address.com>" --no-edit
git rebase --continue
git push -f

About

Some utility files and documents

License:MIT License