Friday, October 19, 2012

Renice

You can change the priority of a process by changing how "nice" it is to other antagonising processes.

just type

renice <priority> -p <pid>

where priority is from 0 to 19 

Earn free space in Dropbox



Just click the link below and verify your school email. You can earn up to 25GB free!!!

https://www.dropbox.com/spacerace?r=NTE2MzE4ODk5



Monday, October 15, 2012

peed Up Computers Running Ubuntu


10 Tips To Speed Up Computers Running Ubuntu 12.04/Linux Mint 13 (Maya)


In this guide, I will try to introduce 11 tips that can be useful for those having old computers with low RAM and want to speed up their system for better performance. These tips are workable under Ubuntu 12.04 or older and any other Ubuntu-based system (Linux Mint 13, for example). If you have more tips, you can mention them in the comment form given below.


1. Preload

Preload is a daemon that runs in the background (invisible) that detects most used applications and store them in cache so that they can be called quickly, which will result in quick system load time. To install it on Ubuntu 12.04/Linux Mint 13, run this command:

sudo apt-get install preload

The default settings for Preload are enough, but if you want to use your own configuration, you can edit this file:

sudo gedit /etc/preload.conf

For Linux Mint, edit the file as follows:

sudo pluma /etc/preload.conf

To monitor preload's log file, run this command:

sudo tail -f /var/log/preload.log

2. Clean Up APT Cache

You need to clean up not needed apt sources from time to time with this command:

sudo apt-get autoclean 

3. Disabling Unnecessary Startup Applications

- There are many applications that are configured to start automatically as the system starts. You can manage these applications by opening Startup Application from the Unity dash under Ubuntu 12.04:


For Linux Mint, the window will look like this:


Check off not needed applications (Bluetooth, Desktop sharing, WiFi, etc.) from the given list with careful attention to some applications that are needed for your system to start.

- You can also use BUM (Boot Up Manager) to disable unnecessary services and applications. You can install it with this command:

sudo apt-get install bum

4. Adjust Swappiness

To check your current used Swappiness, run this command:

cat /proc/sys/vm/swappiness

The default value is 60, to change it, edit this file:

sudo gedit /etc/sysctl.conf

For Linux Mint:

sudo pluma /etc/sysctl.conf

Search for this line (if not present, just add it):

vm.swappiness=10

Save your file and exit. Changes will take effect once you reboot your system.

5. Disable Hibernation/Sleep Functions (Not Recommended)

If you don't need to hibernate (sleep mode) your system, you can disable it as follows at your own risk:

- Edit this file with this command:

sudo gedit /etc/initramfs-tools/conf.d/resume

- For Linux Mint:

sudo pluma /etc/initramfs-tools/conf.d/resume

- Comment (add at the beginning) now this line:

RESUME=UUID=****

- It should be like this:

#RESUME=UUID=***



- Save your file and reboot your system.

6. Speed Up Boot Time By Disabling The Grub Boot Menu

When starting your system, the screen will stop at the Grub2 boot menu. If you want to disable it, you can follow these instructions:

- Open the terminal and edit this file on Ubuntu 12.04:

sudo gedit /etc/default/grub

- For Linux Mint:

sudo pluma /etc/default/grub

- Search now for this line and set its value to zero:

GRUB_TIMEOUT=0



- Save the file and close it. The Grub2 boot menu will not show up in the next system rebooting, but you can call it by holding down the Shift key while rebooting.

7. Get Reliable Performance with ZRAM

If you have an old computer with low RAM, you can optimize it using ZRAM, which will create on your system a compressed block device that mimics a swap disk to reduce disk thrashing (aka paging). To install it under Ubuntu 12.04/LinuxMint 13, run this sequence of commands from the terminal:

sudo add-apt-repository ppa:shnatsel/zram
sudo apt-get update
sudo apt-get install zramswap-enabler

8. Use all CPU Cores For System Startup

If your computer is equipped with a multi-core CPU, you can configure your system to use all available cores during startup by following these instructions:

- Edit this file:

sudo gedit /etc/init.d/rc

- For Linux Mint:

sudo pluma /etc/init.d/rc

- Search now for the first instance of this line:

CONCURRENCY=none

- And replace it with this one if needed:

CONCURRENCY=makefile

Save your file and exit.

9. Disabling Visual Effects

If your computer is a bit old, you can get rid of unwanted visual effects using Compizconfig Settings Manager. To install it under Ubuntu 12.04, run this command:

sudo apt-get install compizconfig-settings-manager

Start it now and head to the Effects section, then disable all enabled effects:


10. Use TMPFS To Reduce Disk I/O

The /tmp folder receives a lot of hard disk read/write operations. You can simply use your system RAM instead of your hard disk to speed up read/write operations for the /tmp folder. To do this, you can follow these instructions:

- Open the terminal and edit the /etc/fstab file with this command:

sudo gedit /etc/fstab 

or

sudo pluma /etc/fstab

- At the end of the file, add these two lines:

# Move /tmp to RAM
tmpfs /tmp tmpfs defaults,noexec,nosuid 0 0


Save your file and exit. Restart now your system to apply the new changes.

Monday, September 10, 2012

SSH on Ubuntu



So let’s say you have a private LAN running in your secret underground lab. Maybe you’ve got a Linux box hardwired to a WiFi router, and maybe a Mac or Linux laptop floating around somewhere, and you need a quick way to transfer files or execute shell commands remotely.
What you need is SSH, the Secure Shell. SSH is a powerful tool which allows secure remote login over insecure networks. It provides an encrypted terminal session with strong authentication of both the server and client using public-key cryptography. This tutorial will cover the basics of SSH’s most useful features:
  • Logging into a remote computer over a secure connection.
  • Transferring files and directories between computers over a secure connection.
  • Enabling public-key authentication.
  • Passwordless authentication for use with scripts and cron jobs.
The following assumptions are made about the reader:
  • You know what a terminal/command line/shell is and how to start a session.
  • You have at least a basic familiarity with Linux/Mac command-line syntax.
  • You’re on a private LAN with access to at least two Linux/Mac computers (or, you have a user account on a remote server that accepts SSH connections).
As always, comments, corrections, and suggestions for improvement are appreciated.

Installing OpenSSH

The Ubuntu (and MacOS X) flavor of SSH is called OpenSSH, a free, open-source implementation of the ssh protocol. It consists of two basic components, an openssh-clientand an openssh-server. SSH clients communicate with SSH servers over encrypted network connections.
The openssh-client software should already be installed by default on Ubuntu. If you want to be able to accept SSH connections as well as request them, you’ll need the server software as well. The easiest way to ensure you have both is simply to run:
sudo apt-get install openssh-client openssh-server

Using SSH to Log into a Remote Computer

Once OpenSSH is installed, you can login to a remote SSH server by using the ssh command:
ssh remoteuser@remotebox
where remoteuser is the username of the remote account you’re trying to access, andremotebox is the remote server’s hostname or IP address.
For example, if you know that your Kubuntu desktop box (now running openssh-server) has a user account named joebanks and that the IP address of that computer on your private LAN is192.168.0.12, you could login remotely to that account from your Linux/Mac laptop by typing:
ssh joebanks@192.168.0.12
If you’re unsure of a computer’s local IP address, try running ifconfig on that machine. This will display the status of the active network interfaces, and the local IP address of that device will be listed after inet addr. It will most likely be in the form of 192.168.0.xx.
Or, if you’ve got a web hosting account that allows shell access (e.g., DreamHost) with a domain name like cooldomain.com, your syntax might look like:
ssh joebanks@cooldomain.com
Now, the first time an SSH client encounters a new remote server, it will report that it’s never seen the machine before, by printing the following message:
The authenticity of host 'remotebox (192.168.0.12)' can't be established.
RSA key fingerprint is 53:b4:ad:c8:51:17:99:4b:c9:08:ac:c1:b6:05:71:9b.
Are you sure you want to continue connecting (yes/no)?
This is just an extra security measure to ensure that you’re actually connecting to the machine you think you are. If you type yes (the most common response), you’ll see the following:
Warning: Permanently added 'remotebox' (RSA) to the list of known hosts.
Subsequent login attempts to this machine will omit the warning message. You’ll then be asked for the remoteuser‘s password:
remoteuser@remotebox's password:
And after correctly entering it, like magic, you’ll be logged into the remote machine, and instead of your local machine’s command prompt, you’ll see the following:
remoteuser@remotebox:~$
And, voila! You can execute commands on the remote machine just as you would on your local box. To close the connection to the remote server, type exit, or use Ctrl-D.

Copying Files

To transfer files and directories from your local machine to the remote server and vice-versa, you’ll use SSH’s “secure copy” command, or scp. To copy a single file from your local machine to the server, use the following syntax:
scp file.txt remoteuser@remotebox:/directory
where file.txt is the name of a file in the current directory of your local machine,remoteuser@remotebox is the username and hostname or IP address of the server (just like in the above ssh examples, and /directory is the directory path on the server where you want your file copied.
For example, if you want to copy the local file.txt to the /home/joebanks/docs directory on the server you logged into above, you’ll run the following command from a local terminal session:
scp file.txt joebanks@192.168.0.12:/home/joebanks/docs
By “local terminal session,” I mean that you DO NOT first ssh in to the remote computer and then run thescp command. Secure copy opens the ssh tunnel on its own. Since secure copy uses the ssh protocol for a secure connection, whenever you run the scp command, you’ll be prompted for a password (or passphrase) if the ssh connection requires it.
You can be as verbose as you want with the local and remote filenames and directories, even changing the filename in the process, like so:
scp ~/docs/oldfile.txt joebanks@192.168.0.12:/home/joebanks/docs/newfile.txt
To copy a file from the server to your local machine, use the following syntax:
scp remoteuser@remotebox:file.txt /local/directory
where remoteuser@remotebox is the username and hostname or IP address of the server,file.txt is a file in the /home/remoteuser directory, and /local/directory is the local directory path into which the file will be copied.
Again, you can be as verbose as necessary, for example:
scp joebanks@192.168.0.12:~/docs/newfile.txt /home/joe/downloads

Copying Directories

To copy an entire directory (and all of its contents) from the local machine to the remote server, use the recursive -r switch, like so:
scp -r /local/directory remoteuser@remotebox:/remote/directory
where /local/directory is the path to the local directory you want copied, and/remote/directory is the remote directory into which you want the directory to be copied.
To copy an entire directory (and all of its contents) from the remote server to the local machine, use the following:
scp -r remoteuser@remotebox:/remote/directory /local/directory
where /remote/directory is the path to the remote directory you want copied, and/local/directory is the local directory into which you want the directory to be copied.

Stop Typing the Stupid IP Address All Day, Will You?

By now you’re no doubt getting sick of typing joebanks@192.168.0.12 or whatever. It sure would be nice to type something shorter. Let’s fix that.
OpenSSH uses a client configuration file, located at ~/.ssh/config, to simplify some of the tedious typing associated with logging into remote machines. To edit (or create) that file, we’ll use the nano text editor, but you can use vi, emacs, kate or whatever:
nano ~/.ssh/config
The simplest configuration file might look something like this:
Host volcano
  HostName 192.168.0.12
This associates the Host volcano with the HostName (or IP address) 192.168.0.12, so now to login you’ll only need to type:
ssh joebanks@volcano
That’s cool, but let’s get a little more lazy, shall we? How about this:
Host BigWoo
  HostName 192.168.0.12
  User joebanks
Now all we need to type is:
ssh BigWoo
Far out! You can add as much configuration data as you need to this Host, and as many different Hosts as you like. And this shorthand will also work with all the scp examples:
scp file.txt BigWoo:
To learn more visit the OpenSSH docs, or run man ssh_config.

Public-Key Authentication

To increase the security of your SSH session, or to set up passwordless authentication, you can enable SSH’s built-in public-key cryptography. Then, instead of entering the remoteuser‘s password on each login attempt, SSH will initiate a challenge-and-response protocol which attempts to match an encrypted public key (stored on the server) with a protected private key (stored on the local machine). This completely eliminates the need to send sensitive information (like a password) over the network, encrypted or not.
To generate a public/private key pair on your local machine, open a terminal and type:
ssh-keygen -t dsa
You’ll see the following message:
Generating public/private dsa key pair.
Enter file in which to save the key (~/.ssh/id_dsa):
Hit Enter. This selects the default location. Next you’ll see:
Enter passphrase (empty for no passphrase):
Enter a secure passphrase, ideally something unique and unguessable. Unlike a password, a passphrase is usually a phrase or complete sentence, with spaces and punctuation if you like. The longer and more obscure the phrase, the stronger it is.
Note: It is also acceptable to just hit Enter at this point, thereby selecting no passphrase. This can be appropriate in some instances (see below), but you should be aware that it is not as secure. While sshwill still use an encrypted public/private keypair (which is almost certainly more secure than typing the remote user’s password like you’ve been doing), anyone gaining access to your local account will thereby also gain unfettered access to any remote hosts which recognize your public key.
After typing a passphrase and hitting Enter, you’ll see:
Enter same passphrase again:
Enter the same passphrase again. And finally:
Your identification has been saved in ~/.ssh/id_dsa.
Your public key has been saved in ~/.ssh/id_dsa.pub.
The key fingerprint is:
42:ac:8a:81:31:81:e5:7b:d2:01:42:2d:64:32:0f:dd localuser@localbox
Now copy your public key, which is stored in the local file ~/.ssh/id_dsa.pub to the remote machine, by running the following command from a local terminal session:
ssh-copy-id -i ~/.ssh/id_dsa.pub remoteuser@remotebox
You’ll be prompted for the remoteuser‘s password one last time, and then you’ll see the message:
Now try logging into the machine, with "ssh 'remoteuser@remotebox'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
MacOSX Users: If the ssh-copy-id method doesn’t work with your version of OpenSSH, try the following command:cat ~/.ssh/id_dsa.pub | ssh remoteuser@remotebox 'cat >> .ssh/authorized_keys'
Or, if the ~/.ssh directory doesn’t yet exist on the remote machine, you can create the directory andcopy the public key all in one swell foop, like so:cat ~/.ssh/id_dsa.pub | ssh remoteuser@remotebox 'mkdir .ssh; cat >> .ssh/authorized_keys'
Once the ~/.ssh/authorized_keys file on the remote machine contains your public key, you’ll be prompted for your passphrase at each login attempt, rather than the remoteuser‘s system password, like so:
Enter passphrase for key '~/.ssh/id_dsa':
Finally, it’s a good idea to change the permissions of the ~/.ssh directory and the~/.ssh/id_dsa file on your local machine, to disable any outside access to your private key.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_dsa

Passwordless Authentication for Automated Tasks

You can use ssh and scp in shell scripts and cron jobs to automate repetitive tasks, such as remote backups of critical files. To do so, however, you’ll need to implement some sort of passwordless authentication scheme, so that scripts can run without human intervention.
Two methods are presented below, the first is the easiest to implement (and possibly the most prevalent), while the second is the most secure.

Method 1: Sans Passphrase

If you want your scripts to have access to the ssh command without requiring a password or passphrase, simply go through the steps outlined above for enabling public-key authentication, but instead of entering a passphrase when prompted, simply press Enter.
The ssh-keygen program will generate a public/private key pair for you that will allow password- and passphrase-less access to any remote server which has your public key stored in its authorized_keys file.
Is this secure? Well, no. And yes. It’s probably more secure than typing in the remoteuser‘s password and sending it over the network. Sure it’s encrypted, but it could still be intercepted.
Public-key authentication sends no password or passphrase data over the network. The “challenge” sent by the server is encrypted with your public key, and can only be decrypted with your private key, which only you have.
However, as mentioned above, if someone gains access to your local computer, they’ll also have access to every remote server with your public key.
So, you’ll need to decide the level of security required. In my opinion, if you’re only communicating with machines on a private LAN, under your control, behind a router’s firewall, then this method is adequate. Others may disagree.

Method 2: Using ssh-agent and keychain

The “proper” and secure way to achieve passwordless authentication is by using the ssh-agentand keychain daemons to store your passphrase between terminal sessions, so you don’t need to type it every time.
Setup of this method is beyond the scope of this article, but the following tutorials will walk you through the entire process, as well as the theory behind it:

Go Forth and SSHify!

I hope this tutorial serves as a gentle introduction to the Secure Shell. For further reading and advanced topics, check out the references listed below, and browse the OpenSSH Documentation. Thanks for reading.

References

  1. SSH Tutorial for Linux
  2. SSH: Ubuntu Community Documentation
  3. Secure Communications with OpenSSH
  4. Getting Started with SSH
  5. Indiana University Knowledge Base: SCP
  6. Example Syntax for Secure Copy
  7. Bash Reference Manual
  8. <div dir="ltr" style="text-align: left;" trbidi="on">
  9. <br /></div>

Thursday, August 2, 2012

Libre Office: Images slow down performace

If you find yourselves editing large documents with mane images, chances are the whole process will be slow and full of crashes and frustration. Here are some methods to change this:

1. Image cache is to small. Go to: Tools > Options... > LibreOffice > Memory → change 'Graphics cache' to 100 MB


2. As you write the images are fairly large, then the most improvement would be gained by only showing replacement frames instead of the actual picture. So if you don't rely on seeing the actual image, but are fine with a placeholder, then toggle Tools|Options → LibreOffice Writer → View, Display: [ ] Graphics and Objects

(File|Page preview will alwas show the image no matter what the setting is in editing mode.)

And you can also add the graphcis on/off toggle to your toolbar using Tools|Customize → Toolbars, Add-button, Category "View", Command "Graphics on/off"

And while you mention you'd want to preserve the original images, I mention the Presentation Minimizer extension nevertheless (shipped by default with LibreOffice). In Impress choose Tools|Minimize Presentation… to open the dialog that lets you set the desired output format (screen, projector, print) and whether to create a new copy or modify the current file, etc.

3. And last but not least, the advise that fits almost every time: Install more RAM :-)


from: http://ask.libreoffice.org/question/93/images-slow-down-performace/

Sunday, July 15, 2012

Modify Ubuntu

Today I bumped onto this website: http://modifyubuntu.com

It is really well structured and it includes really good solutions that work! Enjoy!

p.s. I am expected to be exploiting all those options one by one! ;)

Ubuntu swappiness. Improve ubuntu performance


Ubuntu swappiness. Improve ubuntu performance. vm.swappiness=10. sysctl.conf
If you are looking to squeeze every last bit of performance out of Ubuntu, you can change swappiness value. Swappiness can have a value between 0 and 100. A recommended setting for swappiness is 10.

By adding swappiness=10 to the sysctl.conf file, you will see quite an improvement in Ubuntus performance. To add this please follow the instructions.

Open your terminal and enter the following command:

sudo gedit /etc/sysctl.conf
If you are using Kubuntu swap gedit for kate.
sudo kate /etc/sysctl.conf
You will be prompted to enter your root password. After entering your password the sysctl.conf file will appear. Scroll to the bottom of the file and add the following code.
vm.swappiness=10
Save the file. Next time you reboot you should see an improvement in Ubuntu's performance. Here is a screenshot of the sysctl.conf file

 



http://www.techheadz.co.uk/219.html

Ubuntu : update-apt-xapi takes lot of cpu usage


Ubuntu : update-apt-xapi takes lot of cpu usage
Problem : The process "update-apt-xapi" causes increase in CPU utilization to 100%

There are 2 ways to check this problem :

1.  One is to go to the System Monitor and click on the Processes tab. Sort by %CPU Used and the offending process should pop to the top.

2. The other way is to executed a terminal and type “top” w/o the quotes. Top is a great little application that lists the top users of CPU time, plus gives a bunch of great info at the top of the terminal screen like total uptime, CPU info, process statistic

What is update-apt-xapi?
The actual name of the package is "update-apt-xapian-index". It helps in maintaing an index of packages, and this helps speed up searching for packages in Synaptic, and possibly in other package managers as well.

Solutions :

There are 3 possible solution to solve this problem :

Note: Use method 2 and 3 only if 1 does not works.


1. Edit /etc/cron.weekly/apt-xapian-index

This method will do following things :
a) Run process with the lowest system priority.
b) Update the index and not built it again (faster)

i) sudo gedit /etc/cron.weekly/apt-xapian-index

ii) replace the line
nice $IONICE -c 3 $CMD --quiet
by
nice -n 19 $IONICE -c 3 $CMD --update --quiet

iii) Save And exit And you are done.

In depth detail of changing  cron file can be found here:(Not important)
----------------------------------------------------------------------------------------------------------------------------------
Cron is a utility for scheduling tasks to run at certain times. System tasks run weekly are, unsurprisingly, stored in the /etc/cron.weekly directory. You can also set up personal tasks to run pretty much whenever you want. For that, have a look at man crontab.

Looking at the internals of the code we're using here, the first line, the "crunchbang" line (#!), tells the system what executable to use to run the contents -- in this case, /bin/sh, or your basic shell.

The next two lines establish two shorthand variables. Variables in shell scripts are generally defined in ALL CAPS for easy readability. This is more of a best practice than any hard-and-fast requirement. When referenced later in the script, the variable names are prefixed with a $. Here, CMD is simply shorthand for the path to the update-apt-xapian-index binary, and IONICE is shorthand for the path to the ionice utility for getting or setting a process's I/O scheduling class and priority.

In the if statements, the -x checks to see if the next argument exists, so if [ -x $CMD ] will check to see if /usr/sbin/update-apt-xapian-index exists in the filesystem.

nice -n is basically how you assign a priority to a process. An important caveat, however, is that nice is just that -- a high nice value (up to a maximum of -n 19) means the process is nice and gets out of the way, and a low nice value (down to a minimum of -n -20) means the process is *not* nice and barges to the front of the line to be the first to use system resources. Niceness defaults to 10 if not otherwise specified, and apparently the default update-apt-xapian-index setup does not specify any value.

ionice is new in this fix. It works along similar lines, affecting a process's input/output niceness, only using the flag -c for "class". The ionice man page describes -c:

Quote:
-c class
The scheduling class. 0 for none, 1 for real time, 2 for best-effort, 3 for idle.
Finally, we have the two options passed to update-apt-xapian-index itself, --update and --quiet. --quiet just tells it to not generate much text, only outputting for fatal errors, which makes sense for a background process. --update is new here in this fix together with the nice value and the ionice prioritization, and is a real kicker: it tellsupdate-apt-xapian-index to only update those items in the index that have actually changed. This seems like a no-brainer, since the index includes *every* package installed in the system, but unfortunately the default update-apt-xapian-index setup in a fresh install of Jaunty, Karmic, or Lucid all leave this option out, meaning thatupdate-apt-xapian-index will rebuild the ENTIRE package index every time it runs. No wonder it eats up so much memory and CPU time! With --update, it should take much less resources and much less time.
----------------------------------------------------------------------------------------------------------------------------------

2.  Making the weekly update script non-executable

It turns out that it installs itself to run weekly by adding a script to /etc/cron.weekly/. That’s easy to fix simply by making the script non-executable through file permission change:

sudo chmod 644 /etc/cron.weekly/apt-xapian-index

3.  Remove update-apt-xapi package
sudo apt-get autoremove --purge apt-xapian-index
sudo apt-get autoremove --purge

Note : Purging apt-xapian-index causes the quick search feature in Synaptic to become inoperative.

Tuesday, July 10, 2012

Reset the network adapter from the command line

If you really want to reset the network adapter you usually need to unload and reload the kernel module that it uses.
If you just want to reconfigure it you can usually do:
sudo /etc/init.d/network-manager restart
But if you just want a new dhcp lease (that's the technical name for obtain a new IP from the router), you just need to use:
sudo dhclient -v eth1

https://help.ubuntu.com/10.04/internet/C/troubleshooting-wireless.html

Monday, July 9, 2012

Make Thunar the default file management to make utility run even faster


Introduction

The default file manager in Ubuntu is Nautilus. Some people prefer other file managers. Unfortunately, it's difficult to make other file managers the default, especially since Nautilus manages the desktop icons in Gnome (Ubuntu's desktop environment).

Disclaimer

The first version of this script has been written by a non-programmer. It has been tested and works but, as you can see from the comments in the script, it could still be tweaked to be "better".

Script to change Thunar to be the default file manager

To run this script, paste this block of code into a text file and save it as a file nameddefaultthunar in your home folder.
Toggle line numbers
#!/bin/bash

## Originally written by aysiu from the Ubuntu Forums
## This is GPL'ed code
## So improve it and re-release it

## Define portion to make Thunar the default if that appears to be the appropriate action
makethunardefault()
{
## I went with --no-install-recommends because 
## I didn't want to bring in a whole lot of junk,
## and Jaunty installs recommended packages by default.
echo -e "\nMaking sure Thunar is installed\n"
sudo apt-get update && sudo apt-get install thunar --no-install-recommends

## Does it make sense to change to the directory?
## Or should all the individual commands just reference the full path?
echo -e "\nChanging to application launcher directory\n"
cd /usr/share/applications
echo -e "\nMaking backup directory\n"

## Does it make sense to create an entire backup directory?
## Should each file just be backed up in place?
sudo mkdir nonautilusplease
echo -e "\nModifying folder handler launcher\n"
sudo cp nautilus-folder-handler.desktop nonautilusplease/

## Here I'm using two separate sed commands
## Is there a way to string them together to have one
## sed command make two replacements in a single file?
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-folder-handler.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-folder-handler.desktop
echo -e "\nModifying browser launcher\n"
sudo cp nautilus-browser.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop --browser/thunar/g' nautilus-browser.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-browser.desktop
echo -e "\nModifying computer icon launcher\n"
sudo cp nautilus-computer.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-computer.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-computer.desktop
echo -e "\nModifying home icon launcher\n"
sudo cp nautilus-home.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-home.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-home.desktop
echo -e "\nModifying general Nautilus launcher\n"
sudo cp nautilus.desktop nonautilusplease/
sudo sed -i -n 's/Exec=nautilus/Exec=thunar/g' nautilus.desktop

## This last bit I'm not sure should be included
## See, the only thing that doesn't change to the
## new Thunar default is clicking the files on the desktop,
## because Nautilus is managing the desktop (so technically
## it's not launching a new process when you double-click
## an icon there).
## So this kills the desktop management of icons completely
## Making the desktop pretty useless... would it be better
## to keep Nautilus there instead of nothing? Or go so far
## as to have Xfce manage the desktop in Gnome?
echo -e "\nChanging base Nautilus launcher\n"
sudo dpkg-divert --divert /usr/bin/nautilus.old --rename /usr/bin/nautilus && sudo ln -s /usr/bin/thunar /usr/bin/nautilus 
echo -e "\nRemoving Nautilus as desktop manager\n"
killall nautilus
echo -e "\nThunar is now the default file manager. To return Nautilus to the default, run this script again.\n"
}

restorenautilusdefault()
{
echo -e "\nChanging to application launcher directory\n"
cd /usr/share/applications
echo -e "\nRestoring backup files\n"
sudo cp nonautilusplease/nautilus-folder-handler.desktop .
sudo cp nonautilusplease/nautilus-browser.desktop .
sudo cp nonautilusplease/nautilus-computer.desktop .
sudo cp nonautilusplease/nautilus-home.desktop .
sudo cp nonautilusplease/nautilus.desktop .
echo -e "\nRemoving backup folder\n"
sudo rm -r nonautilusplease
echo -e "\nRestoring Nautilus launcher\n"
sudo rm /usr/bin/nautilus && sudo dpkg-divert --rename --remove /usr/bin/nautilus
echo -e "\nMaking Nautilus manage the desktop again\n"
nautilus --no-default-window &

## The only change that isn't undone is the installation of Thunar
## Should Thunar be removed? Or just kept in?
## Don't want to load the script with too many questions?
}



## Make sure that we exit if any commands do not complete successfully.
## Thanks to nanotube for this little snippet of code from the early
## versions of UbuntuZilla
set -o errexit
trap 'echo "Previous command did not complete successfully. Exiting."' ERR


## This is the main code
## Is it necessary to put an elseif in here? Or is
## redundant, since the directory pretty much
## either exists or it doesn't?
## Is there a better way to keep track of whether
## the script has been run before?
if [[ -e /usr/share/applications/nonautilusplease ]]; then 

restorenautilusdefault 

else

makethunardefault

fi;

Then paste these commands into the terminal
chmod +x defaultthunar
./defaultthunar


from: