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

Lines in file that do not match

grep -vn "boo" a_file

The number of arguments supplied to a script


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.


Send content of a file

mail -s 'Subject-Here' < input.file

Select an arbitrary column of text in UNIX

cut -d : -f 5 /etc/passwd

-d is for delimeter.

Global 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

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

             -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

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


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

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

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

Redirect stdout and stderr to file

  $ command-name &>file

Shutdown (turn off) computer over SSH

sudo shutdown -h now

Symbolic link a new app

ln -s ../registration/ registration

Ruby 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

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.
  echo "File \\"$1\\" is identical to file \\"$2\\"."
  echo "File \\"$1\\" differs from file \\"$2\\"."

Add a user on Ubuntu

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


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/
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/ | 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
Last edited by Artem Dudarev, 2013-10-13 02:01:37. Edit