Linux
Handy Linux tips
Listen to pandora in Europe: install squid proxy
http://www.cyberciti.biz/faq/access-pandora-radio-using-proxy-server-outside-usa/
Interestingly, the firefox connection settings should choose HTTP Proxy instead of 'SOCKS host'.
Bypass blocked website from work computer
http://www.panix.com/~ruari/censorship.html
ssh -D 4096 remoteip
This will require you to enter the password and leave you in the remote machine. Now in the firefox, we need to go to Edit -> Preferences -> Advanced -> Network tab -> Settings... Check 'Manual proxy configuration' (The default is 'Use system proxy settings') and enter 'localhost' for SOCKS Host and '4096' for the Port. Don't enter 'localhost' in the HTTP Proxy.
On Windows, we can use Putty. In short, in the left-hand panel, navigate through Connection > SSH > Tunnels. Enter 4096 in the Source Port box and select the Dynamic radio button. Click Add and “D4096″ will appear in the Forwarded Ports list. The setting in the firefox end is the same.
Graphical way to display disk usage
For example, to use xdiskusage, we run apt-get install xdiskusage and launch it by xdiskusage ~/.
Display directory size with sorting and human readable
du -k ~/ --max-depth=1 --exclude ".*" | sort -nr | cut -f2 | xargs -d '\n' du -sh
The --exclude is to hide hidden directories.
Note that the 'du' commands may be cheating. See the following screenshot.
The discrepancy is explained by 'sector'. See http://askubuntu.com/questions/122091/difference-between-filesize-and-size-on-disk.
$ sudo dumpe2fs /dev/sda1 | grep -i "block size" dumpe2fs 1.41.14 (22-Dec-2010) Block size: 4096
To show a file size in terms of blocks, we can use
ls -s
So for example, if a file takes 150 blocks, and if a block takes 4096 bytes, then the file takes 150*4096/1024 KB on disk.
Apache benchmark (ab) testing
ab -n 100 -c 10 http://taichi.selfip.net:81/ ab -n 100 -c 10 http://taichi.selfip.org/
rsync with non-standard port
Use -e option
rsync -avz -e "ssh -p 23" mydir user@remoteip:
rsync with progress bar
Use --progress option.
rsync -avz --progress file1 file2
scp with non-standard port
Use -P argument.
ssh -P 23 myfile user@remoteip:
The device is busy
See http://ocaoimh.ie/2008/02/13/how-to-umount-when-the-device-is-busy/
# fuser -m /dev/sdc1 /dev/sdc1: 538 # ps auxw|grep 538 donncha 538 0.4 2.7 219212 56792 ? SLl Feb11 11:25 rhythmbox
Another handy one is:
umount -l /dev/sdwhatever
Kill a process
kill -9 PID
Create an ext3 file system on a USB flash drive
umount /dev/sdb1 (depending on the device of course) sudo mkfs.ext3 /dev/sdb1
Port forwarding
For example, we like to use source port number 8080, destination port 80 (the http port), and destination server www.ubuntuforums.org.
ssh -L 8080:www.ubuntuforums.org:80 <host>
Where <host> should be replaced by the name of your laptop. The -L option specifies local port forwarding. For the duration of the SSH session, pointing your browser at http://localhost:8080/ would send you to http://www.ubuntuforums.org/.
To stop the ssh session, use ps -ef to find the process id and kill it.
Add a new user with home directory
adduser xxx
adduser is better than useradd since useradd does not create home directory and it does not even ask the password for new user. adduser will interactively ask user information.
To delete the user, use
deluser xxx
Compress a folder without full path name
Suppose we want to compress the folder ~/Documents and its subfolders. We want to include Documents folder name but not /home/brb/Documents name.
tar -czvf tmp.tar.gz -C ~/ Documents tar -tzvf tmp.tar.gz
Show folder size for one level only
du --max-depth=1 -h
Soft link
ln -s /full/path/of/original/file /full/path/of/soft/link/file
Backup
- Use dropbox folder.
If we don't want to install dropbox software, we can install bash dropbox uploader: http://www.andreafabrizi.it/?dropbox_uploader
I install it under ~/Downloads/andreafabrizi-Dropbox-Uploader-cdc2466 directory
Sample usages:
./dropbox_uploader.sh list / ./dropbox_uploader.sh upload ~/Desktop/ConfigurateNote.txt
Running crontab as root
Use sudo crontab -e to edit. After saving it, no need to initialize it. Use sudo crontab -l to list the cron job.
Mount usb drive
Run
fdisk -l
OR
dmesg | grep -i "SCSI"
to confirm the USB device is detected.
Now suppose the usb device is found in dev/sdb1.
mkdir /mnt/usb mount -t vfat -o rw,users /dev/sdb1 /mnt/usb
The above mount command assumes the usb drive has Windows vfat partition and users give non-root users the ability to unmount the drive. If the USB drive is partitioned linux ext2/3, we can merely run mount command as
mount /dev/sdb1 /mnt/usb
At the end, run umount command like
umount /mnt/usb
To make the mounting automatically, edit the file /etc/fstab.
/dev/sdb1 /mnt/usb vfat defaults 0 0 /dev/sdb1 /mnt/usb ext3 defaults 0 0
and run
mount -a
run commands in a background and allow log off
nohup /path/to/script >output 2>&1 &
vi keys
- editmode / insert: "i"
- editmode / append: "a"
- leave edit mode: "ESC"
- save: ":w"
- quit: ":q"
- save and quit: ":wq"
- quit without saving: ":q!"
Some helps
U-boot
http://www.denx.de/wiki/U-Boot
Debian/Ubuntu
Set static IP
root@debian:~# cat /etc/network/interfaces auto lo eth0 iface lo inet loopback iface eth0 inet dhcp
Now edit the file /etc/network/interfaces
# The primary network interface auto eth0 iface eth0 inet static address 192.168.0.100 gateway 192.168.0.1 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255
After it, restart network
/etc/init.d/networking restart
Change IP address from the command line
/sbin/ifconfig eth0 192.168.1.17 netmask 255.255.255.0 up /sbin/ifconfig eth0
Dyndns
See https://help.ubuntu.com/community/DynamicDNS
nano /etc/ddclient.conf
daemon=600 protocol=dyndns2 use=web, web=checkip.dyndns.com, web-skip='IP Address' server=members.dyndns.org login=YOURNAME password='YOURPASSWORD' taichi.selfip.net
And run ddclient -daemon=0 -debug -verbose -noquiet to confirm it is working.
webmin
See http://www.webmin.com/deb.html
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.600_all.deb dpkg --install webmin_1.600_all.deb
The install will be done automatically to /usr/share/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/. Or if accessing it remotely, replace localhost with your system's IP address.
Virtual box
Install guest addition for virtualbox See the link [1]
apt-get update apt-get install build-essential module-assistant m-a prepare cd Downloads tar xzvf /media/cdrom0/VMwareTools-9.2.0-799703.tar.gz cd vmware-tools-distrib ./vmware-install.pl [Accept all default] shutdown -r now
virtual machine software benchmark
Emulation vs virtualization
Virtualization allows users to configure virtual machines outfitted with similar hardware and processors as the host system, whereas emulation simulates different hardware and processor configurations in software.
Emulators are what allow you to run old Commodore 64 or NES games on a PC, for example.
Remote desktop connection
- Go to System -> Preference -> Remote desktop. Allow other uses to view your desktop & uncheck you must confirm each access & require user to enter this password.
- Go to System -> Preference -> Monitor. Change monitor resolution to 1280 x 720.
Instal sshd
apt-get update apt-get install openssh-server
Install LAMP
See the page [2]
apt-get install apache2 a2enmod rewrite apt-get install mysql-server [I choose branch name as MYSQL root password] apt-get install php5 php-pear php5-suhosin apt-get install php5-mysql /etc/init.d/apache2 restart
Another instruction including how to set up user directories for Apache web server http://wiki.debian.org/LaMp
apt-get install mysql-server mysql-client mysql_secure_installation apt-get install apache2 apache2-doc apt-get install php5 php5-mysql libapache2-mod-php5 apt-get install python libapache2-mod-python
The apache configuration file is in /etc/apache2/apache2.conf.
For PHP, it is also useful to install php for command line.
sudo aptitude install php5-cli
Restarting apache before testing on web browser
/etc/init.d/apache2 restart
Install mediawiki
And also the link http://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Debian_GNU/Linux
aptitude install mediawiki php5 apache2 mediawiki-extensions libapache2-mod-php5
This will install latex. After the end, we can use Synaptic package manager to see what were installed. Now following the instruction in https://help.ubuntu.com/community/MediaWiki, we remove the '#' from the third line so that it reads 'Alias /mediawiki /var/lib/mediawiki':
sudo nano /etc/mediawiki/apache.conf sudo /etc/init.d/apache2 restart
Now we can start mediawiki by opening a browser and pointing it to http://localhost/mediawiki.
We need to enter
Site config admin username: WikiSysop password: Database config Database name: wikidb DB username: DB password: Superuser name: root Superuser password: [depend on how it was chosen when installing MYSQL]
Press the button of "Installing mediawiki". We will be welcomed to the wiki page. Following the instruction,
For security reason, I remove new account creation and anonymous editing. I also remove edit counters.
Backup and Restore mediawiki
See docs.google.com note. The process involves 3 parts: mediawiki system, mysql and images.
Install moinmoin
- Comparison of mediawiki vs moinmoin http://www.wikimatrix.org/compare/MediaWiki+MoinMoin
- Comparison of wiki software http://en.wikipedia.org/wiki/Comparison_of_wiki_software
- Moinmoin website http://moinmo.in/
- moinmoin was used by Bioconductor, ubuntu, etc.
MYSQL security
Just execute mysql_secure_installation from the command line.
- You can set a password for root accounts.
- You can remove root accounts that are accessible from outside the local host.
- You can remove anonymous-user accounts.
- You can remove the test database, which by default can be accessed by anonymous users.
See http://www.mysql-optimization.com/mysql-secure-installation-program.html
Compiling R
Use the following command to download required components before building any R packages. See also ubuntu package for R
sudo apt-get build-dep r-base
Package maintenance
https://help.ubuntu.com/community/AptGet/Howto#Maintenance_commands To show package information
apt-cache show <package_name>
To list files in a package.
dpkg -L <package_name>
To list racing games package
apt-cache search racing game
The following command list all packages installed in the system
apt-cache pkgnames
Remote desktop connection
If vino failed, then try teamviewer. It works fine. After launching it, the software automatically creates an ID and password. We can change the password so it is fixed. Then launch the software on the client. Use the partner's ID and password to connect to it.
View logs
- Apache /var/log/apache2/access.log
Torrent
Popular search sites
- torrentz
- thepiratebay
- isohunt
- kickass torrents
Torrent client: transmission-cli
Torrent client: rtorrent
Install webmin
apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python wget http://prdownloads.sourceforge.net/webadmin/webmin_1.600_all.deb dpkg --install webmin_1.600_all.deb
File does not exist: /var/www/favicon.ico from /var/log/apache2/error.log
The reason? You have not created a favicon, also known as a website icon, for your website. It’s the icon that displays in the address bar of your web browser when you connect to a website. A web browser will request this icon file from every website.
If you choose to create one. Use a program such as Gimp and create a 16×16 pixel image and save it as a .ico filetype. Then upload that file to the DocumentRoot of your website. You will need one for each VirtualHost. If you don’t have Gimp, there are online resources such as favicon.cc where you can create a .ico file and download it for your own use.
As you know by now, not having a favicon.ico file, won’t stop web browsers from requesting it each time. But you can tell Apache not to log the event as an error message. You will still see the request in the access.log, but at least you will have a cleaner error.log file.
Add the following block of code to each VirtualHost, or at least the ones which don’t have a favicon file.
Redirect 404 /favicon.ico <Location /favicon.ico> ErrorDocument 404 "No favicon" </Location>
Don’t forget to restart apache after making the change. If you want make a “global” change, which would apply to any and all VirtualHosts, you can create a file in Apache’s conf.d folder with a name such as nofavicon.conf and then add that block of code to the file. That would disable favicon across the board and save you from having to edit each VirtualHost.
Or, you create an empty file with the name “favicon.ico” in the directory root of Apache (for exemple /var/www/).