Set default editor

export EDITOR=vim

We can set this variable in the .profile or .bashrc file.

chmod Numerical permissions

#PermisionrwxBinary
7read, write, and executerwx111
6read and writerw-110
5read and executer-x101
4read onlyr--100
3write and execute-wx011
2write only-w-010
1execute only--x001
0none---000

A permission have 3 numbers: owner, group and anyone else. An example, 744 stands for; the owner can read, write and execute, group and anyone else can read only the file.

source

Append Current Date To Filename in Bash Shell

To get the current date in mm_dd_yyyy format use the following date format syntax:

date +"%m_%d_%Y"

You can store this to a variable name:

now=$(date +"%m_%d_%Y")

or

now=`date +"%m_%d_%Y"`

Finally, you can create a filename as follows:

now=$(date +"%m_%d_%Y")
echo "Filename : /nas/backup_$now.sql"

You can create a shell script as follows:

#!/bin/bash
_now=$(date +"%m_%d_%Y")
_file="/nas/backup_$_now.sql"
echo "Starting backup to $_file..."
# mysqldump -u admin -p'myPasswordHere' myDbNameHere > "$_file"

source

How can I delete duplicate lines in a file in Unix?

$ awk '!seen[$0]++' file.txt

seen is an associative-array that Awk will pass every line of the file to. If a line isn’t in the array then seen[$0] will evaluate to false. The ! is a logical NOT operator and will invert the false to true. Awk will print the lines where the expression evaluates to true. The ++ increments seen so that seen[$0] == 1 after the first time a line is found and then seen[$0] == 2, and so on. Awk evaluates everything but 0 and "" (empty string) to true. If a duplicate line is placed in seen then !seen[$0] will evaluate to false and the line will not be written to the output

source

How to check spelling at the Linux command line with Aspell

To check the spelling of a file, just type:

$ aspell check file.txt

source

How to use unicode characters in Windows command line?

In powershell type:

chcp 65001

It will change the code page to UTF-8. Also, you need to use Lucida console fonts.

(I use this to build a hakyll project on Windows)

Another answer at Windows 10 terminal encoding.

source

tar usage

$ tar -czf filename.tar.gz file-1 [file-2 file-3 ...]  # creates a tar.gz o tgz file
$ tar -ztvf filename.tar.gz                            # list the content of a tar.gz or .tgz file
$ tar -xzf filename.tar.gz                             # extract the content of a tar.gz or .tgz file

How do I scroll in tmux?

Ctrl-b then [ then you can use your normal navigation keys to scroll around (eg. Up Arrow or PgDn). Press q to quit scroll mode.

source