Things I always forget

I really don’t understand why, but there is a strange list of stuff, that for some reason I can not memorize. So this list is mainly for my personal usage.

Foreword – this list is kinda embarasing for a person that calls himself an IT, probably it will make many people laugh, but for some reason every time I must make any of these simple operations – I search google for confirmation, and some comfort. I don’t want to overwrite that essential config file, instead of making a symlink of it 🙂 This list will grow with time, when I remember the next thing my brain refuses to remember.


Sysadmin    MySQL    Git    Dev


Sysadmin stuff:

First of all – as mentioned above I can not remember the proper way to create a symlink. Every fuckin’ time I search google in fear I can screw things up. To create or update symlink:

ln -sf /path/to/file /path/to/symlink
Next we move to another embarrassment - archiving:
tar -cvf name.tar /path/to/file1 /path/to/file2 /path/to/file3

Let’s continue on with chmod:

Example: chmod o-w (deny others from editing the file)
Example: chmod u+rwx (give the owner full control)
Exmaple: chmod +rwx (give everyone full control)
Example: chmod +x (allow anyone to execute the file)

Key:
r - Read
w - Write
x - Execute

u - The owner of the file
g - The group that the file belongs to
o - Anybody who is not one of the above
a - All users

+ - Add permissions
- - Remove permissions

                                : The first octet represents permissions for the owner.
        r w x  T                : The second octet represents permissions for the group.
Owner:  4 2 1  7                : The third octet represents permissions for everyone else.
Group:  0 0 0  0                : For each octet, start at 0 and:
Other:  0 0 0  0                : +4 for read permission.
                                : +2 for write permission.
Command: chmod 700              : +1 for execute permission.

You, who are reading this (not reffering to my alter ego, he’s always mocking me regardless) – can stop laughing now. I assume non IT people had already left this borefest. So moving on….

grep anyone?

egrep is the same as grep -E fgrep is the same as grep -F rgrep is the same as grep -r

grep '^fred' /etc/passwd                    # find 'fred', but only at the start of a line
grep '[FG]oo' *                              # find Foo or Goo in all files in the current dir
grep '[0-9][0-9][0-9]' *                     # find all lines in all files in the current dir with three numbers in a row
grep -rnw '/path/to/somewhere/' -e 'pattern' # find all files in path containing pattern

some sed

sed -i -e 's/search/replace/g' file.txt
sed -i 's/search/replace/g' ./*

How to exit vim

You don't! Vim exits only when it decides!
Or when your actions have pleased the gods of Linux!
Or if Linus likes your code (haha)

Add ‘/’ on tab press in Ubuntu/Debian based OS

Customize your readline by putting commands in an .inputrc file:

Create or edit ~/.inputrc and add these lines:

include /etc/inputrc
set mark-symlinked-directories on

Customize your readline by putting commands in the .bashrc file (or in the .profile file):
Edit ~/.bashrc and add this line:

bind 'set mark-symlinked-directories on'

Customize the readline for all users by creating a .sh file into the directory /etc/profile.d:
Create a file /etc/profile.d/mark-symlinked-directories.sh which should looks like:

#!/bin/sh
bind 'set mark-symlinked-directories on'




Log-in/Log-out. That’s it.

VirtualBox symlinks

That’s a bit off and strange, but Oracle’s VirtualBox has issues with symlinks in rw shared directories. To fix this you need to execute this command for every shared directory on every virtual machine:

VBoxManage setextradata "VM Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/{sharename} 1




mySQL:

Create user

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

Change user password

ALTER USER 'userName'@'localhost' IDENTIFIED BY 'New-Password-Here';

Grant privileges to a database:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

Git:

Setting the default editor for git:

git config --global core.editor "vim"




Dev:

Ternary operator – for some reason my brain is too stubborn in remembering this. I have it written on a sticky note and glued on my monitor

check ? true : false

$valid = true;
$x = $valid ? 'yes' : 'no'; //it will get the value 'yes'




MySQL constraint actions

I’ll be back!