Command reference

Commands file.

Quick command reference for mwnn.

1 X server

1.1 Enable/Disable DPMS (Energy Star) features.

  1. Switch off monitor immediately.
    $ xset dpms force off
  2. Disable DPMS.
    $ xset -dpms
  3. Enable DPMS.
    $ xset +dpms
  4. Switch off monitor after 2 seconds of inactivity.
    $ xset dpms 2

2 CD/DVD burn

  1. Create an iso image out of the data that needs to be burnt.
    $ mkisofs -r -V <CD/DVD name> -o filename.iso dir1/ dir2/
  2. Get the device identifier of the CD/DVD burner.
    # cdrecord -scanbus
  3. For non-multisession writes use the following command.
    # cdrecord -v speed=8 dev=1,0,0 -data filename.iso.
  4. For multisession writes use the -multi option.
    # cdrecord -v speed=8 dev=1,0,0 -multi -data filename.iso

3 GPG usage

3.1 Encrypt/Decrypt messages.

  1. Generate a public/private key pair.
    $ gpg --gen-key
  2. If other people would want to send messages to us, we would have to give our public key to them. So we export our public key to a file.
    $ gpg --armor --export "NAME OF THE KEY" > public_key.txt

    Email the key to the people who want to send us messages.

  3. To import other people's public key use the following command:
    $ gpg --import public_key.txt
  4. To encrpyt a message that needs to be sent to another person do the following:
    $ gpg --armor --encrypt message.txt

    A new file called message.txt.asc will be created containing the encrypted data.

  5. To decrypt the data at the recipient's end do the following:
    $ gpg --decrypt message.txt.asc

4 youtube-dl

  1. Use the following command to download high definition video:
    $ youtube-dl -b -d URL
  2. To continue downloading a partially downloaded file use the -c option:
    $ youtube-dl -c -b -d URL
  3. Let youtube-dl decide the file extension (mp4 or flv) based on the type of the video file being downloaded.
    $ youtube-dl -b -o 'sunny_boney_m.%(ext)s'

5 MPlayer

  1. To invoke mplayer in quiet mode use one of the following commands:
    $ mplayer -quiet <media file>


    $ mplayer -really-quiet <media file>
  2. To construct an index (for seeking through a partially downloaded media file) use the following command:
    $ mplayer -quiet -idx <media file>
  3. To get timing information type the letter 'o'.
  4. To flip the video upside-down use the following command:
    $ mplayer -flip <video file>
  5. To start viewing a movie in fullscreen mode use the following command:
    $ mplayer -fs <video file>
  6. Play DVD content
    $ mplayer -nocache dvdnav://

6 Mencoder

  1. Obtain crop information
    $ mplayer dvd://<track number> -chapter 2 -vf cropdetect
  2. Rip a DVD to XviD format
    • 1st Pass
      $ mencoder dvd://<track number> -vf crop=720:352:0:62 -ovc xvid -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=1 -oac copy -o /dev/null
    • 2nd Pass
      $ mencoder dvd://<track number> -vf crop=720:352:0:62,scale=704:304 -ovc xvid -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 -alang en -oac mp3lame -lameopts br=96:cbr:vol=6 -o rang_de_basanti.avi
  3. Rip a VCD
    $ mencoder vcd://<track number> -o movie.avi -ovc lavc -oac lavc
  4. Transcode (convert) videos to MP4 format (so that they becomes playable on IPod).
    $ mencoder input.avi -sws 9 -of lavf -lavfopts format=mp4  -vf scale=576:320,dsize=576:320,harddup  -ovc x264  -x264encopts bitrate=1381:vbv_maxrate=1500:vbv_bufsize=2000:nocabac:me=umh:trellis=1:level_idc=30:global_header:threads=2:pass=1:turbo  -oac faac  -faacopts mpeg=4:object=2:br=160:raw -channels 2 -srate 48000 -o output.mp4
  5. Cut a portion from a video file.
    $ mencoder -ss <start position (in secs)> -endpos <end position/step size (in secs)> <input file> -ovc copy -oac copy -o <output file>


  1. Convert *.avi files to *.mp4 (to be able to play media files on IPod)
    $ ffmpeg -i extreme_ways.avi -s 480x320 -aspect 16:9 -b 768k -ab 64k -ar 22050 -r 30000/1001 extreme_ways.mp4

8 Wireshark

  1. Use editcap to edit *.pcap files.
  2. The -d option lets you remove duplicate packets in a capture.
    $ editcap -d infile.pcap outfile.pcap
  3. To select a particular range of packets do the following:
    $ editcap -r infile.pcap outfile.pcap start-end

    Here start/end indicate the packet range that is required to be included in the outfile.pcap file. The -r option causes the packets whose packet numbers are specified on the command line to be written to the output capture file, instead of discarding them.

  4. To delete a particular range of packets do the following:
    $ editcap infile.pcap outfile.pcap start-end
  5. Start a capture immediately on wireshark startup:
    $ wireshark -k
  6. Start a capture on a particular network interface:
    $ wireshark -i <interface name>
  7. Save the capture to a file:
    $ wireshark -w <filename>
  8. Stop capturing after 'n' seconds:
    $ wireshark -a duration:n

9 SQLite

  1. To execute a set of SQL/meta commands from a file use the following command line:
    $ sqlite3 -init <filename>
  2. To execute a set of SQL/meta commands on SQLite startup add the required commands to the ~/.sqliterc file.

10 GNU Emacs

10.1 Keyboard macros

  1. To start a keyboard macro do the following:
    C-x (
  2. The end a keyboard macro do the following:
    C-x )
  3. To execute a previously defined keyboard macro do the following:
    C-x e
  4. To edit a keyboard macro:
    C-x C-k
  5. Assign a name to the keyboard macro
    C-x C-k n
  6. Get the Lisp code for a named macro
    M-x insert-kbd-macro <RET> macroname <RET>

10.2 Search and replace

  1. To do a regular-expression search & replace do the following:
    M-x replace-regexp <RET> REGEXP <RET> NEWSTRING <RET>
  2. When performing a "search and replace" operation, type the following to insert a newline character,
    C-q C-j

10.3 Registers

  1. To view the contents of a register:
    M-x view-register <RET> <REGISTER>
  2. To save a posistion in a register:
    C-x r <SPC> <REGISTER>
  3. To jump to a posistion saved in a register:
    C-x r j <REGISTER>
  4. To save text in a register:
    C-x r s <REGISTER>
  5. To insert text saved in a register:
    C-x r i <REGISTER>
  6. To save a number in a register:
    C-u <NUMBER> C-x r n <REGISTER>
  7. To increment the number in a register:
    C-u <NUMBER> C-x r + R
  8. Save current window configuration in a register
    C-x r w <REGISTER>

10.4 Rectangles

  1. Create a rectangle region by placing mark on a column and point on another column.
  2. Kill a rectangle region of text.
    C-x r k
  3. Delete a rectangle region of text.
    C-x r d
  4. Yank/Paste previously killed/Cut rectangle region.
    C-x r y
  5. Replace a rectangle region with a string.
    C-x r t STRING

10.5 Org-mode

  1. Use cursor keys to move to previous/next weeks in Agenda mode.
  2. The following #+keywords seem to be helpful:
  3. To assign a specific TODO keyword to an entry in the tree
    C-<EntryNumber> C-c C-t
  4. To insert a Timestamp with repeating interval, insert the timestamp and append +Nd (days), +Nw (weeks), +Nm (months), +Ny (years). The following repeats the task every month on the specified date.
    <2009-11-02 Mon +1m>
  5. To insert a timestamp (with hrs:min):
    C-u C-c .
  6. To specify a different lead time for DEADLINES:
    <2009-11-02 Mon -5d>
  7. To schedule an appointment use a plain timestamp i.e. Don't mark the timestamp with either DEADLINES/SCHEDULED keywords.
  8. Insert a DEADLINE with a timestamp:
    C-c C-d
  9. Insert a SCHEDULE with a timestamp:
    C-c C-s
  10. To view the list of all STUCK projects (projects with no TODO keywords associated with them):
    C-c a #
  11. To sort the table based on the contents of a column, place the cursor on one of the column entries and type the following command.
    C-c ^
  12. Insert a horizontal line below the current line.
    C-c -
  13. For calculation purposes, use $n notation to represent columns. For example, $3 = ($1 + $2) / 2 is a formula that sets the third column with the average of values in first and second columns.
  14. To apply a pre-defined formula on a column use,
    C-c =
  15. To define a formula for a column use,
    C-u C-c =
  16. Create a sparse tree matching a regex.
    C-c / r
  17. Export a sparse tree.
    C-c C-e v
  18. Create a footnote.
    C-c C-x f
  19. Calculate the sum of all the numbers in the current column.
    C-c +
  20. List the references of field in a table.
    C-c ?
  21. Toggle the display of a grid in a table.
    C-c }

10.6 CScope

  1. Add the following lines to your .emacs file.
    (if (file-exists-p "~/software/emacs_extras/xcscope/xcscope.el")
        (add-to-list 'load-path "~/software/emacs_extras/xcscope/")
        (require 'xcscope)
        (setq cscope-do-not-update-database t)))
  2. Copy xcscope.el (from the standard CScope distribution) into one the directories listed under load-path.
  3. Copy the shell script cscope-indexer (from the standard CScope distribution) into one of the directories listed by the PATH environmental variable.
  4. Create a symbol cross-reference file.
    C-c s I
  5. Find all occurences of a symbol.
    C-c s s
  6. Find the global definition of a symbol.
    C-c s g
  7. Find the list of functions calling a particular function.
    C-c s c
  8. Find the functions called by a function.
    C-c s C
  9. Find all occurences of a text string.
    C-c s t
  10. Go to the next result listed in the CScope buffer.
    C-c s n
  11. Go to the previous result listed in the CScope buffer.
    C-c s p

10.7 Server

  1. Do not wait for the Emacs server to return.
    $ emacsclient -n <filename>

10.8 Printing

  1. Print current buffer along with its properties (like faces, etc).
    M-x ps-print-buffer-with-faces

10.9 Flymake configuration

  1. In .emacs file, Set the flymake-buildfile-dirs variable to the directory containing the Makefile.
    (setq flymake-buildfile-dirs "/../")
  2. Add the following lines in the Makefile:
    # Flymake configuration.
    ifneq($(CHK_SOURCES), )
    check-syntax: $(patsubst %.c, %.o, $(shell basename $(CHK_SOURCES)))

    NOTE: There must be a rule for building the C source file.

10.10 Miscellaneous

  1. Align text around a specified character.
    M-x align-regexp
  2. List all lines matching a regular expression.
    M-x occur
  3. To align a paragraph inside a C comment, select the paragraph and type,
  4. To balance all the windows in an emacs session,
    M-x balance-windows

    or you can use the following shortcut

    C-x +
  5. List all key bindings.
    M-x make-command-summary


11.1 Enable local users login

  1. Add the following to /etc/vsftpd.conf

12 Synaptic touchpad

12.1 Enable tap on synaptic touchpad

  1. To list all the Synaptics driver options do the following:
    $ synclient -l
  2. To enable TAP on the touchpad do the following:
    $ synclient TapButton1=1

13 GDB

  1. Display all the elements of an array.
    (gdb) set print elements 0
  2. Remove limits on the size of the call stack.
    (gdb) set height 0
  3. Display the contents of a memory area of size 20 bytes in binary format.
    (gdb) x/20tb gen_ptr

14 Python

  1. To go through the HTML version of python module documentation:
    $ pydoc -p <port number>

    Type in http://localhost:<port number> in a web browser.

  2. Enter interactive mode after executing a script:
    $ python -i <script name>

15 tmpfs

  1. Create a tmpfs
    # mount -t tmpfs -o size=1G,nr_inodes=10k,mode=0700 tmpfs /mnt/mwnn_tmpfs/
  2. Change the size of the tmpfs filesystem on-the-fly:
    # mount -o remount,size=2G /mnt/mwnn_tmpfs/

16 Info pages.

  1. To update info's main page:
    # cd /usr/share/info
    # install-info mod_name.gz dir

17 IP tables

  1. Delete a rule:
    # iptables -D <chain name> <rule number>

18 WGet

  1. Set pre-defined settings in ~/.wgetrc file. Example:
    continue = on
    progress = dot
    timeout = 40
    tries = 100
  2. Download the contents of a remote directory recursively.
    $ wget -r -nH --cut-dirs=5

    The –cut-dirs=5 in the above command would cut the first 5 components of the URL specified as the argument.

19 ARPing

To know the MAC address of a remote machine:

# arping <IP addr>

20 GNU configure

20.1 Installation directory

  1. Installation directory can be specified using the –prefix option.
    $ ./configure --prefix=/usr/local/

20.2 Cross compilation

  1. –build=BUILD
    The system on which the package is built.
  2. –host=HOST
    The system where built programs and libraries will run. For simple
    cross-compilation, only --host=HOST is needed.
  3. –target=TARGET
    Used only when building compiler tools; The system for which the tools will
    create output.
  4. –program-prefix=PREFIX
    Prepend PREFIX to installed program names.
  5. –program-suffix=SUFFIX
    Append SUFFIX to installed program names.
  6. –program-transform-name=PROGRAM
    Run 'sed PROGRAM' on installed program names.
  7. To install the built package in a different directory (so that the built package can be installed on different machines), use the DESTDIR variable when invoking 'make install'.
    $ make DESTDIR=~/built_packages/prg_name install
  8. 'configure' options are passed recursively to all sub-packages. The following command shows the help associated with all sub-packages.
    $ ./configure --help=recursive

21 Git

  1. To resolve merge conflicts, do the following:
    $ git add <filename>
    $ git commit
  2. To perform commits for certain hunks do the following:
    $ git add -i

    Select the patch option and then go ahead and select the hunks to be commited.

  3. To enable auto-completion of Git commands in bash do the following:
    • Copy the file contrib/completion/git-completion.bash (from the standard GIT source distribution) to ~/.git-completion.bash.
      $ cp contrib/completion/git-completion.bash ~/.git-completion.bash
    • Add the following line to your .bashrc file.
      source ~/.git-completion.bash
  4. List the files that was created/modified during each commit.
    $ git whatchanged
  5. Create a tar-ball from a tag.
    $ git archive --format=tar --prefix=git- v1.7.0.2 | bzip2 > git-1.7.0.tar.bz2
  6. Patch generation.
    • Generate patch files for each commit made between HEAD^^^ and HEAD.
      $ git format-patch HEAD^^^..HEAD
    • Generate one patch file for all commits made between HEAD^^^ and HEAD.
      $ git diff HEAD^^^..HEAD > file.patch
  7. Stash
    • Stash away temporary changes.
      $ git stash save <stash message>
    • List all stashes.
      $ git stash list
    • Apply a stash.
      $ git stash apply <stash name>
  8. Log
    • Show all non-merge commits
      $ git log --no-merges
    • Show all commits authored by person X
      $ git log --author=X
    • Show all commits that contain a keyword.
      $ git log --grep=<keyword>

22 Imagemagick

  1. Screenshot of a window
    $ import -window root screenshot.png

23 CScope

  1. Create a symbol cross-reference table only for selected files.
    $ cscope file1.c file2.c
  2. Include source files in other directories (as well as the current directory).
    $ cscope -s dir1, dir2, dir3
  3. Build cross-reference for files listed in a text file.
    $ cscope -i file_list.txt
  4. Include header files present in other directories. By default, CScope searches for include-ed header files in the current directory. To include other directories in the search path, use the -I option.
    $ cscope -I dir

    This option can be specified more than once on the command line.

  5. Specify a name for the file holding symbol cross-reference table.
    $ cscope -f project_sym.out
  6. Do not check for modified source files during start-up.
    $ cscope -d
  7. Build an inverted index database (for quicker symbol look-up).
    $ cscope -q

    The above command would create two more files (in addition to cscope.out). They are and cscope.po.out.

24 GCC

  1. Show the commands executed during each stage of compilation.
    $ gcc -v file.c -o file
  2. Disable removal of "NULL pointer check" code during optimization.
    $ gcc -fno-delete-null-pointer-checks file.c -o file
  3. Insert invocations to user-defined functions at the entry and exit of all the functions in a program.
    $ gcc -finstrument-functions file.c -o file.
  4. Record the gcc command line used to compile sources into the resulting object/executable.
    $ gcc -Wall -frecord-gcc-switches file.c -o file.

    The command line can then be extracted from the object/executable by using the following command.

    $ readelf --string-dump=.GCC.command.line <object/executable>

25 xterm

  1. Increase the number of lines buffered by xterm.
    $ xterm -sl <number of lines>

    The default number of lines buffered is 64.

  2. Disable colored fonts (produced by running applications).
    $ xterm -cm

26 tcpdump

  1. Save packet capture in a file (for later usage)
    $ tcpdump -i <interface name> -s 65535 -w <output file>

    The file can later be opened in wireshark for further analysis.

27 Linux kernel

  1. Insert a kernel module along with any dependencies.
    # modprobe <module name>
  2. Get meta information of a Linux kernel module.
    # modinfo <module name>
  3. Get a list of module specific parameters
    # modinfo -p <module name>
  4. Display kernel slab cache information.
    $ slabtop

27.1 Get kernel state information

NOTE: The following keyboard shortcuts work only when used in 'virtual console' sessions.

  1. Print a register dump.
    AltGr + Scroll lock

    AltGr is the right Alt key.

  2. Print the state of all the processes.
    Ctrl + Scroll lock
  3. Print memory usage details.
    Shift + Scroll lock

If the output does not appear on the screen, use the dmesg command to view the contents of the kernel ring buffer.

28 IPv6

  1. Openssh
    $ ssh -6 <user>@<ipv6 addr>

29 rtorrent

  1. To disable a tracker, select the appropriate tracker from the "Tracker" list and press the "*" key.

30 grep

  1. Invert the selection.
    $ grep -v <pattern>

31 Fedora

  1. Install xterm fonts.
    $ yum install xorg-x11-fonts-misc
  2. Install US-English support for aspell.
    $ yum install aspell-en

32 xz

  1. Extract a *.xz file:
    $ xz -d file.xz
  2. Create a xz compressed tar ball:
    $ tar cJf file.tar.xz file1 file2 file3
  3. Extract a xz compressed tar ball:
    $ tar xJf file.tar.xz

33 Openssl

  1. Encrypt a file using AES algorithm.
    $ openssl enc -aes-256-cbc -salt -in <input file> -out <output file>
  2. Decrypt a file using AES algorithm.
    $ openssl enc -d -aes-256-cbc -in <input file> -out <output file>

34 Curl

  1. Send mail via a GMail account.
    $ curl -n -v --ssl --mail-from <> --mail-rcpt <to-email_id> --url smtp:// -T mail.txt

    The login name and password must be located in the file $HOME/.netrc in the format indicated below:

    machine login <login name> password <password>

    E-mail headers like SUBJECT and TO can be specified at the begining of the mail.txt file.

35 Split and join files

  1. Split a large file into two or more files (for when copying a 4GB+ file onto a USB drive with FAT32 filesystem). The following command splits the Slackware 13.1 iso image into three files (slackwareaa, slackwareab & slackwareac).
    $ split --bytes=2048m slackware-13.1-install-dvd.iso slackware
  2. Join files that have been obtained after spliting a large file using split command.
    $ cat slackwareaa slackwareab slackwareac > slackware-13.1-install-dvd.iso

36 User and group management

  1. Add an user.
    $ useradd -g <initial group> -G group1, group2 {, ...} -m <user name>

    The above command also creates the /home/<username> directory if it does not exist.

  2. Specify a password for a user.
    $ passwd <user name>
  3. The following is an interactive tool to add a user. It allows the administrator to set the password and groups for the new user.
    $ adduser
  4. Delete an existing user account.
    $ userdel -r <user name>

    The -r option is for deleting the user's home directory.

  5. List the groups to which a user belongs to.
    $ groups [user name]
  6. Add a user to a group.
    $ gpasswd -a <user name> <group name>
  7. Delete a user from a group.
    $ gpasswd -d <user name> <group name>
  8. Create a new group.
    $ groupadd <group name>
  9. Delete an existing group.
    $ groupdel <group name>

37 Miscellaneous

  1. Rescan the SCSI subsystem for new devices (useful if your recently plugged-in USB device is not being detected automatically)
    # rescan-scsi-bus
  2. Format a drive with FAT32 as the filesystem type.
    # mkdosfs -n <volume name> <device file> <block count>

    The <block count> can be obtained by using fdisk -l on the <device file>.

  3. Format a drive with EXT3 as the filesystem type.
    # mkfs -t ext3 -v -L <volume name > <device file>
  4. Create backup of all files changed while applying a patch:
    $ patch -b -p0 < valgrind-3.5.0-glibc-2.11.patch
  5. Display the local time equivalent of an UTC time.
    $ date -d 'YYYY-MM-DD HH:MM UTC'
  6. Interactively merge two files.
    $ sdiff file_v1.c file_v2.c -o file_merge.c
  7. Convert online manual pages to pdf files.
    $ man -t sem_open | ps2pdf - sem_open.pdf

    Convert a list of manual pages into a single pdf file,

    $ man -t sem_open sem_unlink sem_post sem_wait | ps2pdf - semaphore.pdf

Author: mwnn

Date: <2010-05-17 Mon 10:19>

HTML generated by org-mode 7.3 in emacs 23