Linux Notes

In case of catastrophic data loss or system failure, I've decided that it's safest for me to put a few notes in a public place. Some of these are distro-specific, so know that I use [K]Ubuntu and Fedora.

Bash Shortcuts (some of these actually libreadline shortcuts)

Ctrl-A Go to the beginning of the line you are currently typing on
Ctrl-E Go to the end of the line you are currently typing on
Ctrl-L Clears the Screen, similar to the clear command
Ctrl-U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl-H Same as backspace
Ctrl-R Search history
Ctrl-C Stop whatever you are running via SIGINT
Ctrl-D Exit the current shell || Send EOF
Ctrl-Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl-W Delete the word before the cursor
Ctrl-K Clear (cut) the line after the cursor
Ctrl-Y Paste the cut from Ctrl-K
Ctrl-T Swap the last two characters before the cursor
Alt-T Swap the last two words before the cursor
Alt-F Move cursor forward one word on the current line
Alt-B Move cursor backward one word on the current line
Alt-. Gives you the last argument of the last command (pressing again goes further back)
Esc Last object. For example: cat /etc/fstab -> vi <Esc> -> vi /etc/fstab

Useful Commands to know

Clear screen: $ clear
Show end of file: $ tail
Display routing table: $ netstat -rn
Add user to sudo: $ username -S sudo
Zip directory with password: $ zip -e -r dir/
Have Firestarter (or other service) start in runlevels 3, 4, and 5: $ chkconfig --levels 345 firestarter on
Check swap: # cat /proc/swaps
Check processors: # cat /proc/cpuinfo
Switch to English temporarily: $ export LANG=C
Symlinkng: $ ln -s /path/to/existing/file /path/to/new/link
Changing file time: $ touch -d '3 Jan 2007 15:47:00' file.jpg
Find out top 10 directories eating up your disk space: # du -csh * –max-depth=0 | sort -rn | head -10
Find Harddisk Capacity on the box: # fdisk -l | grep -iE ‘mb|gb|tb’
Find out performance of hard disk: # hdparm -t -T /dev/hda
Tunnel GUI through ssh: $ ssh -X
Hardware Information: # dmidecode
Dell Fan Contro: # i8kctl
Find what version (and other info) of package is installed: $ dpkg -s packageName
ls in reverse-time order: $ ls -lrt
Change default web browser: $ sudo update-alternatives --config x-www-browser

Reset forgotten password

Add "rw init=/bin/bash" to the kernel line in grub.

# passwd username

Create an ISO image from CD

  1. Insert CD, but do not mount. Verify if cd is mounted or not with mount command:
    # mount
  2. If CD was mouted automatically unmout it with umount command:
    # umount /dev/cdrom
  3. Create CD-ROM ISO image with dd command:
    # dd if=/dev/cdrom of=/home/user/cdimg.iso

Make and extract encrypted tarball from directory

$ tar -zcvf - folder/ | openssl des3 -salt -k PASSWORD | dd of=mybackup.tbz
$ dd if=mybackup.tbz | openssl des3 -d -k PASSWORD | tar zvxf -

Advantages: No need to make / deflate tarball when encrypting / decrypting.
Disadvantages: Password is part of the commands to make and deflate encrypted file. Therefore, it is visible on the screen and added to History. Note that upon decrypt both the original folder and an unencrypted tarball will be created (verify this).

Encrypt and extract tarball with openssl

$ openssl enc -aes-256-cbc -salt -in stuff.tar.gz -out stuff.tar.gz.enc -pass pass:PassWordHere
$ openssl enc -d -aes-256-cbc -in stuff.tar.gz.enc -out stuff.tar.gz

Advantages: Password is not part of the command to deflate.
Disadvantages: Password is part of the command to make encrypted file. Therefore, it is visible on the screen and added to History. Additionally, this method adds an extra step (making / deflating tarball) to the encrypt / decrypt process.

Extract different types of tarball

$ tar -xzf file.tar.gz
$ tar -xjf file.bz2

Mount an .iso

# mkdir /media/iso
# modprobe loop
# mount filename.iso /media/iso -t iso9660 -o loop

Forcefully unmount CD/DVD Rom or any other mounted partitions

# fuser -km /dev/cdrom

Delete a file securely, first overwriting it to hide its contents

$ shred -n 200 -z -u filename
$ srm filename
$ wipe filename

Spoof MAC Address

# ifconfig eth0 down
# ifconfig eth0 hw ether 00:00:00:00:00:00

Find and Kill processes

$ ps ux (processes owned by current user)
$ ps -e (all processes on machine)
$ kill 1234 (kill process #1234)
$ pkill firefox

Check Tempurature

$ cat /proc/acpi/thermal_zone/THM/temperature
$ acpi -V
$ sudo sensors

Search for files by content

$ find . -exec grep -q "search" '{}' \; -print     // print path of files that contain the text "search" recursively
$ grep "search" *    // print lines of files in pwd that contains the text "search"
$ grep -i "search" `find . -name "*" -print`    // print lines of files that contain the text "search" recursively and case insensitive
$ grep -i -n 'searchTerm' *    // Find files containing search terms

Date Published: 2008-05-08
Date Revised: 2008-07-17

Date Revised: 2009-05-17


notes, linux, kde, compiz, ubuntu, firefox, thunderbird Dotan Cohen's personal notes notes, linux, kde, compiz, ubuntu, firefox, thunderbird
[email protected] [email protected] [email protected] [email protected] [email protected]

eXTReMe Tracker