Linux
General tips
- When you get a "file system is read only" error on a USB drive (mounted at sdb1) try unmounting and remounting as read/write with the following command:
sudo mount -o remount,rw /dev/sdb1. - Linux interprets #! (called a shebang), when they are the first two characters in a text file, as indicating that the file is a script and the rest of the line gives the absolute path of the interpreter. E.g. Bash
#!/bin/sh; Python 3.1#!/usr/bin/python3.1.
Bash/zsh Command Line
- Make the command-line prompt reflect Version Control using vcprompt.
- Terminal Multiplexer Byobu
(Man Page;
Add new terminal:
F2; Scroll through terminals:F3andF4). - Change your password:
passwd - Repeatedly run command:
watch -d -n 0.5 [command] - Count number of files in current directory:
ls -l | wc -l - Search for string in files (include sub-directories):
grep -rl "string" *. - Delete all empty
.xmlfiles:find . -name "*.xml" -size 0 -exec rm {} \;. - Recursively remove folders and their contents:
rm -rf. - List files with / added to directory names and * to executables:
ls -F. - Mass rename:
zmv -n (*).txt $1.tmp(-noption shows result but does not make the change) - Checksum:
md5sum ubuntu-10.04-desktop-i386.iso. - Find which executable will be used:
which python. - Change to the previous working directory:
cd -. - Substitution:
!$Repeats last argument of previous command;!!Repeat previous line command;^foo^bar^Repeat the previous shell command but replace string "foo" with "bar". echo $?: Display exit code.su userid: Switch User.- traceroute and ping combined:
mtr google.com. - Run graphical application as root:
gksudo nautilus. - Create link:
ln [-s] file [link]. - Reconnect to network connection by restarting network manager service:
sudo service network-manager restart. - Monitor several logs:
tail -f [logfile1] [logfile2].... df: Show disk usage.- Job Control:
jobsList background jobs;bg [jobspec]Run job in background;fg [jobspec]Bring specific or most recent job to foreground;kill %1Kill first listed job.
Ultimate Linux Shutdown Process
If all is stuck, and even Ctrl+Alt+backspace does not work, remember this mnemonic: Raising Skinny Elephants Is Utterly Boring:
- ALT+SysRq+r (put keyboard in raw mode)
- ALT+SysRq+s (sync the disk)
- ALT+SysRq+e (terminate all processes)
- ALT+SysRq+i (kill all processes)
- ALT+SysRq+u (remount all file systems read only)
- ALT+SysRq+b (reboot the system)
(SysRq is the same button as print screen on most keyboards)
Less drastically, you can use ALT+SysRq+k to kill all processes on the current virtual console (has the effect of restarting the X server).
SysRq is disabled by default so you will have to edit /etc/sysctl.conf and change the kernel.sysrq value to 1 (and then reboot) to enable these shortcut keys.
Ubuntu
Settings
- Bulk change file associations:
sudo vi /usr/share/applications/defaults.list:%s/gedit/geany/gChange default text editor from gedit to geany.
- Prevent keyobard resetting to US layout after reboot:
- In
dconf-editor, navigate todesktop > ibus > general. - Enable
use-system-keyboard-layout.
- In
- Disable auto-open of Nautilus on drive mount:
gsettings set org.gnome.desktop.media-handling automount-open false - Stop Wifi being activated after boot (from):
sudo vi /etc/rc.local- Add line:
rfkill block wifi - Also, to keep Bluetooth deactivated):
rfkill block bluetooth
- Enable
Ctrl+Alt+Backspaceto restart the X server, to recover after the Desktop Environment freezes:sudo dpkg-reconfigure keyboard-configuration- Accept first 5 keyboard options.
- Choose
Yesto useControl+Alt+Backspaceto terminate the X server.
OpenDNS
Add OpenDNS servers by editing /etc/dhcp3/dhclient.conf and appending the following line to the document:
prepend domain-name-servers 208.67.222.222,208.67.220.220;
Logout Keyboard Shortcut
To re-enable Control+Alt+Backspace shortcut to kill the X server:
- Open Keyboard preferences.
- Choose Layouts Tab.
- Press Options Button.
- Find "Key sequence to kill the x server' option on list.
- Tick to enable.
Monitor Network Usage
- Install vnstat:
sudo apt-get install vnstat. - Create database:
sudo vnstat -u -i eth0. - Show monthly usage:
vnstat -m.
Lost Password
Steps to recover lost password in Ubuntu:
- Choose your Recovery Mode from Grub menu.
- On the Recovery Menu choose "Drop to root shell prompt".
- At the command prompt enter
ls /hometo list Userids. (optional) - Enter
passwd <userid>to change the password of that Userid. - Enter
exit. - On the Recovery Menu choose "Resume Normal Boot".