Set cursor in terminal mode

https://stackoverflow.com/questions/44534678/how-to-change-cursor-shape-depending-on-vi-mode-in-bash

Works in bash 4.4+: place the following to .inputrc:

set show-mode-in-prompt on
set vi-cmd-mode-string "\1\e[2 q\2"
set vi-ins-mode-string "\1\e[6 q\2"

Split tar file

https://unix.stackexchange.com/questions/61774/create-a-tar-archive-split-into-blocks-of-a-maximum-size

tar cvzf - foo | split -b 2500m - foo.tgz.
cat sda1.backup.tar.gz.* | tar xzvf -

Print current month calendar

cal

Kill several process based on part of name

pkill -9 -f dev_appserver

Cron job to run every 5 minutes

https://crontab.guru/every-5-minutes

crontab -e
*/5 * * * *

Make ipython keybindings like vim

https://stackoverflow.com/questions/10394302/how-do-i-use-vi-keys-in-ipython-under-nix

Set it in ~/.inputrc

set editing-mode vi
set keymap vi
set convert-meta on

Unmount USB drive

https://unix.stackexchange.com/questions/45820/how-to-umount-a-usb-drive

sudo umount /media/usb

List connected devices

To find connected USB drive

https://askubuntu.com/questions/60115/how-to-find-full-path-of-device-ive-connected

df -h

Restart network manager

sudo systemctl restart network-manager.service

Change real name for linux user

Real name is displayed in ubuntu switch user screen.

https://askubuntu.com/questions/558669/renaming-user-name

usermod -c “New_real_name” newname

Vim bindings in bash

http://www.techrepublic.com/blog/linux-and-open-source/using-vi-key-bindings-in-bash-and-zsh/

set -o vi

to ~/.bashrc

Save to a different file name with wget

http://www.electrictoolbox.com/wget-save-different-filename/

wget -O example.html URL

Generate random alphanumeric string

shell/bash generate random alphanumeric string

# bash generate random 32 character alphanumeric string (upper and lowercase) and 
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)

# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

Use any delimiter in sed substitute command

How to replace strings containing slashes with sed?

s:?page=one&:pageone:g

You can use any character as a delimiter that's not part of either string. Or, you could escape it with a backslash.

rsh

rsh is a different command in Unix and Linux. In Unix this is restrictive shell.

Lines in file that do not match

http://www.uccs.edu/~ahitchco/grep/

grep -vn "boo" a_file

The number of arguments supplied to a script

http://www.tutorialspoint.com/unix/unix-special-variables.htm

$#

File that runs command when login

The file /etc/profile is maintained by the system administrator of your UNIX machine and contains shell initialization information required by all users on a system.

/etc/profile

http://www.tutorialspoint.com/unix/unix-environment.htm

Send content of a file

http://www.cyberciti.biz/faq/email-howto-send-text-file-using-unix-appleosx-bsd/

mail -s 'Subject-Here' you@cyberciti.biz < input.file

Select an arbitrary column of text in UNIX

http://www.tech-recipes.com/rx/161/select-an-arbitrary-column-of-text-in-unix/

cut -d : -f 5 /etc/passwd

-d is for delimeter.

Global Bash Variables

http://www.thegeekstuff.com/2010/05/bash-variables/

Global variables are also called as environment variables, which will be available to all shells. printenv command is used to display all the environment variables.

Find and delete files in a given directory recursively

find . -name '*.pyc' -delete

Make user sudoer (admin)

adduser <username> sudo

Ignore errors in Makefile

http://www.gnu.org/software/make/manual/html_node/Errors.html#Errors

- in the beginning of the line to ignore errors @ to suppress output

     clean:
             -rm -f *.o

Crontab to pull wiki each hour

To edit the list of cronjobs you can run:

crontab -e

My crontab to pull my wiki every 15th minute of each hour:

15 * * * * cd $HOME/projects/wiki/ && git pull > /dev/null 2>&1

http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/

To list all scheduled commands:

chrontab -l

Note: not sudo crontab -e, since it is for a root user. I am not sure if it has permissions to pull from Github.

Kill several processes

/grepwww.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/

kill -9 `ps ux | awk ‘/java/ && !/awk/ {print $2}`

http://unix.stackexchange.com/questions/50555/kill-many-instances-of-a-running-process-with-one-command

ps aux | pkill -9 -f dev_appserver

Check processes to be killed with

ps aux | pgrep -f dev_appserver

Find and remove

Find and remove all files that have (1).jpg in them with confirmation from a user.

find -name *(1).jpg -exec rm -i {} \;

Compress files under Linux

http://www.cyberciti.biz/howto/question/general/compress-file-unix-linux-cheat-sheet.php

tar -zcvf {.tgz-file} {files}
tar -zcvf pics.tar.gz *.jpg *.png

Redirect stdout and stderr to file

http://www.cyberciti.biz/faq/redirecting-stderr-to-stdout/

$ command-name &>file

Shutdown (turn off) computer over SSH

http://www.cyberciti.biz/faq/shutdown-ubuntu-linux-computer/

sudo shutdown -h now

Symbolic link a new app

ln -s ../registration/ registration

Ruby on Bluehost

http://giangnd.wordpress.com/2010/10/25/install-and-use-your-custom-gems-on-bluehost/

In ~/.bashrc:

export GEM_HOME=$HOME/ruby/gems
export GEM_PATH=$GEM_HOME:/usr/lib64/ruby/gems/1.8
export GEM_CACHE=$GEM_HOME/cache
export PATH=$PATH:$HOME/ruby/gems/bin

Compare files

http://tldp.org/LDP/abs/html/filearchiv.html

cmp $1 $2 &> /dev/null  # /dev/null buries the output of the "cmp" command.
#   cmp -s $1 $2  has same result ("-s" silent flag to "cmp")
#   Thank you  Anders Gustavsson for pointing this out.
#
# Also works with 'diff', i.e.,   diff $1 $2 &> /dev/null

if [ $? -eq 0 ]         # Test exit status of "cmp" command.
then
  echo "File \\"$1\\" is identical to file \\"$2\\"."
else  
  echo "File \\"$1\\" differs from file \\"$2\\"."
fi

Add a user on Ubuntu

http://www.howtogeek.com/howto/ubuntu/add-a-user-on-ubuntu-server/

You can use the -d option to set the home directory for the user. The -m option will force useradd to create the home directory. We’ll try creating a user account with those options, and then use the passwd command to set the password for the account. You can alternatively set a password using -p on the useradd command, but I prefer to set the password using passwd.

sudo useradd -d /home/testuser -m testuser
sudo passwd testuser

Skype in Ubuntu 11.10

echo foreign-architecture i386 | sudo tee /etc/dpkg/dpkg.cfg.d/multiarch
sudo apt-get install libxss1:i386 libqtcore4:i386 libqt4-dbus:i386
sudo apt-get remove --purge skype
sudo apt-get install skype:i386

ok, here's an interesting twist.... Scribus works when I run it as root with gksudo scribus-ng

I used sudo skype.

SSH login without password

via http://linuxproblem.org/art_9.html

To login from A to B without a password:

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password: 

Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 

Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B hostname
B