Commands file.
Quick command reference for mwnn.
Table of Contents
- 1 X server
- 2 CD/DVD burn
- 3 GPG usage
- 4 youtube-dl
- 5 MPlayer
- 6 Mencoder
- 7 FFMPEG
- 8 Wireshark
- 9 SQLite
- 10 GNU Emacs
- 11 VSFTPD
- 12 Synaptic touchpad
- 13 GDB
- 14 Python
- 15 tmpfs
- 16 Info pages.
- 17 IP tables
- 18 WGet
- 19 ARPing
- 20 GNU configure
- 21 Git
- 22 Imagemagick
- 23 CScope
- 24 GCC
- 25 xterm
- 26 tcpdump
- 27 Linux kernel
- 28 IPv6
- 29 rtorrent
- 30 grep
- 31 Fedora
- 32 xz
- 33 Openssl
- 34 Curl
- 35 Split and join files
- 36 User and group management
- 37 Miscellaneous
1 X server
1.1 Enable/Disable DPMS (Energy Star) features.
-
Switch off monitor immediately.
$ xset dpms force off
-
Disable DPMS.
$ xset -dpms
-
Enable DPMS.
$ xset +dpms
-
Switch off monitor after 2 seconds of inactivity.
$ xset dpms 2
2 CD/DVD burn
-
Create an iso image out of the data that needs to be burnt.
$ mkisofs -r -V <CD/DVD name> -o filename.iso dir1/ dir2/
-
Get the device identifier of the CD/DVD burner.
# cdrecord -scanbus
-
For non-multisession writes use the following command.
# cdrecord -v speed=8 dev=1,0,0 -data filename.iso.
-
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.
-
Generate a public/private key pair.
$ gpg --gen-key
-
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.
-
To import other people's public key use the following command:
$ gpg --import public_key.txt
-
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.
-
To decrypt the data at the recipient's end do the following:
$ gpg --decrypt message.txt.asc
4 youtube-dl
-
Use the following command to download high definition video:
$ youtube-dl -b -d URL
-
To continue downloading a partially downloaded file use the -c option:
$ youtube-dl -c -b -d URL
-
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' http://www.youtube.com/watch?v=yD8DcgpLp_w
5 MPlayer
-
To invoke mplayer in quiet mode use one of the following commands:
$ mplayer -quiet <media file>
OR
$ mplayer -really-quiet <media file>
-
To construct an index (for seeking through a partially downloaded media
file) use the following command:
$ mplayer -quiet -idx <media file>
- To get timing information type the letter 'o'.
-
To flip the video upside-down use the following command:
$ mplayer -flip <video file>
-
To start viewing a movie in fullscreen mode use the following command:
$ mplayer -fs <video file>
-
Play DVD content
$ mplayer -nocache dvdnav://
6 Mencoder
-
Obtain crop information
$ mplayer dvd://<track number> -chapter 2 -vf cropdetect
-
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
-
1st Pass
-
Rip a VCD
$ mencoder vcd://<track number> -o movie.avi -ovc lavc -oac lavc
-
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
-
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>
7 FFMPEG
-
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
- Use editcap to edit *.pcap files.
-
The -d option lets you remove duplicate packets in a capture.
$ editcap -d infile.pcap outfile.pcap
-
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.
-
To delete a particular range of packets do the following:
$ editcap infile.pcap outfile.pcap start-end
-
Start a capture immediately on wireshark startup:
$ wireshark -k
-
Start a capture on a particular network interface:
$ wireshark -i <interface name>
-
Save the capture to a file:
$ wireshark -w <filename>
-
Stop capturing after 'n' seconds:
$ wireshark -a duration:n
9 SQLite
-
To execute a set of SQL/meta commands from a file use the following
command line:
$ sqlite3 -init <filename>
- 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
-
To start a keyboard macro do the following:
C-x (
-
The end a keyboard macro do the following:
C-x )
-
To execute a previously defined keyboard macro do the following:
C-x e
-
To edit a keyboard macro:
C-x C-k
-
Assign a name to the keyboard macro
C-x C-k n
-
Get the Lisp code for a named macro
M-x insert-kbd-macro <RET> macroname <RET>
10.2 Search and replace
-
To do a regular-expression search & replace do the following:
M-x replace-regexp <RET> REGEXP <RET> NEWSTRING <RET>
-
When performing a "search and replace" operation, type the following to
insert a newline character,
C-q C-j
10.3 Registers
-
To view the contents of a register:
M-x view-register <RET> <REGISTER>
-
To save a posistion in a register:
C-x r <SPC> <REGISTER>
-
To jump to a posistion saved in a register:
C-x r j <REGISTER>
-
To save text in a register:
C-x r s <REGISTER>
-
To insert text saved in a register:
C-x r i <REGISTER>
-
To save a number in a register:
C-u <NUMBER> C-x r n <REGISTER>
-
To increment the number in a register:
C-u <NUMBER> C-x r + R
-
Save current window configuration in a register
C-x r w <REGISTER>
10.4 Rectangles
- Create a rectangle region by placing mark on a column and point on another column.
-
Kill a rectangle region of text.
C-x r k
-
Delete a rectangle region of text.
C-x r d
-
Yank/Paste previously killed/Cut rectangle region.
C-x r y
-
Replace a rectangle region with a string.
C-x r t STRING
10.5 Org-mode
- Use cursor keys to move to previous/next weeks in Agenda mode.
-
The following #+keywords seem to be helpful:
#+AUTHOR #+EMAIL #+DATA #+TITLE #+TEXT
-
To assign a specific TODO keyword to an entry in the tree
C-<EntryNumber> C-c C-t
-
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>
-
To insert a timestamp (with hrs:min):
C-u C-c .
-
To specify a different lead time for DEADLINES:
<2009-11-02 Mon -5d>
- To schedule an appointment use a plain timestamp i.e. Don't mark the timestamp with either DEADLINES/SCHEDULED keywords.
-
Insert a DEADLINE with a timestamp:
C-c C-d
-
Insert a SCHEDULE with a timestamp:
C-c C-s
-
To view the list of all STUCK projects (projects with no TODO keywords
associated with them):
C-c a #
-
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 ^
-
Insert a horizontal line below the current line.
C-c -
- 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.
-
To apply a pre-defined formula on a column use,
C-c =
-
To define a formula for a column use,
C-u C-c =
-
Create a sparse tree matching a regex.
C-c / r
-
Export a sparse tree.
C-c C-e v
-
Create a footnote.
C-c C-x f
-
Calculate the sum of all the numbers in the current column.
C-c +
-
List the references of field in a table.
C-c ?
-
Toggle the display of a grid in a table.
C-c }
10.6 CScope
-
Add the following lines to your .emacs file.
(if (file-exists-p "~/software/emacs_extras/xcscope/xcscope.el") (progn (add-to-list 'load-path "~/software/emacs_extras/xcscope/") (require 'xcscope) (setq cscope-do-not-update-database t)))
- Copy xcscope.el (from the standard CScope distribution) into one the directories listed under load-path.
- Copy the shell script cscope-indexer (from the standard CScope distribution) into one of the directories listed by the PATH environmental variable.
-
Create a symbol cross-reference file.
C-c s I
-
Find all occurences of a symbol.
C-c s s
-
Find the global definition of a symbol.
C-c s g
-
Find the list of functions calling a particular function.
C-c s c
-
Find the functions called by a function.
C-c s C
-
Find all occurences of a text string.
C-c s t
-
Go to the next result listed in the CScope buffer.
C-c s n
-
Go to the previous result listed in the CScope buffer.
C-c s p
10.7 Server
-
Do not wait for the Emacs server to return.
$ emacsclient -n <filename>
10.8 Printing
-
Print current buffer along with its properties (like faces, etc).
M-x ps-print-buffer-with-faces
10.9 Flymake configuration
-
In .emacs file, Set the flymake-buildfile-dirs variable to the directory
containing the Makefile.
(setq flymake-buildfile-dirs "/../")
-
Add the following lines in the Makefile:
# Flymake configuration. ifneq($(CHK_SOURCES), ) check-syntax: $(patsubst %.c, %.o, $(shell basename $(CHK_SOURCES))) endif
NOTE: There must be a rule for building the C source file.
10.10 Miscellaneous
-
Align text around a specified character.
M-x align-regexp
-
List all lines matching a regular expression.
M-x occur
-
To align a paragraph inside a C comment, select the paragraph and type,
M-q
-
To balance all the windows in an emacs session,
M-x balance-windows
or you can use the following shortcut
C-x +
-
List all key bindings.
M-x make-command-summary
11 VSFTPD
11.1 Enable local users login
-
Add the following to /etc/vsftpd.conf
anonymous_enable=NO local_enable=YES
12 Synaptic touchpad
12.1 Enable tap on synaptic touchpad
-
To list all the Synaptics driver options do the following:
$ synclient -l
-
To enable TAP on the touchpad do the following:
$ synclient TapButton1=1
13 GDB
-
Display all the elements of an array.
(gdb) set print elements 0
-
Remove limits on the size of the call stack.
(gdb) set height 0
-
Display the contents of a memory area of size 20 bytes in binary format.
(gdb) x/20tb gen_ptr
14 Python
-
To go through the HTML version of python module documentation:
$ pydoc -p <port number>
Type in http://localhost:<port number> in a web browser.
-
Enter interactive mode after executing a script:
$ python -i <script name>
15 tmpfs
-
Create a tmpfs
# mount -t tmpfs -o size=1G,nr_inodes=10k,mode=0700 tmpfs /mnt/mwnn_tmpfs/
-
Change the size of the tmpfs filesystem on-the-fly:
# mount -o remount,size=2G /mnt/mwnn_tmpfs/
16 Info pages.
-
To update info's main page:
# cd /usr/share/info # install-info mod_name.gz dir
17 IP tables
-
Delete a rule:
# iptables -D <chain name> <rule number>
18 WGet
-
Set pre-defined settings in ~/.wgetrc file. Example:
continue = on progress = dot timeout = 40 tries = 100
-
Download the contents of a remote directory recursively.
$ wget -r -nH --cut-dirs=5 ftp://ftp.slackware.com/pub/slackware/slackware-13.0/patches/packages/linux-2.6.29.6-3
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
-
Installation directory can be specified using the –prefix option.
$ ./configure --prefix=/usr/local/
20.2 Cross compilation
-
–build=BUILD
The system on which the package is built.
-
–host=HOST
The system where built programs and libraries will run. For simple cross-compilation, only --host=HOST is needed.
-
–target=TARGET
Used only when building compiler tools; The system for which the tools will create output.
-
–program-prefix=PREFIX
Prepend PREFIX to installed program names.
-
–program-suffix=SUFFIX
Append SUFFIX to installed program names.
-
–program-transform-name=PROGRAM
Run 'sed PROGRAM' on installed program names.
-
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
-
'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
-
To resolve merge conflicts, do the following:
$ git add <filename> $ git commit
-
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.
-
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
-
Copy the file contrib/completion/git-completion.bash (from the
standard GIT source distribution) to ~/.git-completion.bash.
-
List the files that was created/modified during each commit.
$ git whatchanged
-
Create a tar-ball from a tag.
$ git archive --format=tar --prefix=git-1.7.0.2/ v1.7.0.2 | bzip2 > git-1.7.0.tar.bz2
-
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
-
Generate patch files for each commit made between HEAD^^^ and HEAD.
-
Stash
-
Stash away temporary changes.
$ git stash save <stash message>
-
List all stashes.
$ git stash list
-
Apply a stash.
$ git stash apply <stash name>
-
Stash away temporary changes.
-
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>
-
Show all non-merge commits
22 Imagemagick
-
Screenshot of a window
$ import -window root screenshot.png
23 CScope
-
Create a symbol cross-reference table only for selected files.
$ cscope file1.c file2.c
-
Include source files in other directories (as well as the current directory).
$ cscope -s dir1, dir2, dir3
-
Build cross-reference for files listed in a text file.
$ cscope -i file_list.txt
-
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.
-
Specify a name for the file holding symbol cross-reference table.
$ cscope -f project_sym.out
-
Do not check for modified source files during start-up.
$ cscope -d
-
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 cscope.in.out and cscope.po.out.
24 GCC
-
Show the commands executed during each stage of compilation.
$ gcc -v file.c -o file
-
Disable removal of "NULL pointer check" code during optimization.
$ gcc -fno-delete-null-pointer-checks file.c -o file
-
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.
-
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
-
Increase the number of lines buffered by xterm.
$ xterm -sl <number of lines>
The default number of lines buffered is 64.
-
Disable colored fonts (produced by running applications).
$ xterm -cm
26 tcpdump
-
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
-
Insert a kernel module along with any dependencies.
# modprobe <module name>
-
Get meta information of a Linux kernel module.
# modinfo <module name>
-
Get a list of module specific parameters
# modinfo -p <module name>
-
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.
-
Print a register dump.
AltGr + Scroll lock
AltGr is the right Alt key.
-
Print the state of all the processes.
Ctrl + Scroll lock
-
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
-
Openssh
$ ssh -6 <user>@<ipv6 addr>
29 rtorrent
- To disable a tracker, select the appropriate tracker from the "Tracker" list and press the "*" key.
30 grep
-
Invert the selection.
$ grep -v <pattern>
31 Fedora
-
Install xterm fonts.
$ yum install xorg-x11-fonts-misc
-
Install US-English support for aspell.
$ yum install aspell-en
32 xz
-
Extract a *.xz file:
$ xz -d file.xz
-
Create a xz compressed tar ball:
$ tar cJf file.tar.xz file1 file2 file3
-
Extract a xz compressed tar ball:
$ tar xJf file.tar.xz
33 Openssl
-
Encrypt a file using AES algorithm.
$ openssl enc -aes-256-cbc -salt -in <input file> -out <output file>
-
Decrypt a file using AES algorithm.
$ openssl enc -d -aes-256-cbc -in <input file> -out <output file>
34 Curl
-
Send mail via a GMail account.
$ curl -n -v --ssl --mail-from <gmail-username@gmail.com> --mail-rcpt <to-email_id> --url smtp://smtp.gmail.com -T mail.txt
The login name and password must be located in the file $HOME/.netrc in the format indicated below:
machine smtp.gmail.com 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
-
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
-
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
-
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.
-
Specify a password for a user.
$ passwd <user name>
-
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
-
Delete an existing user account.
$ userdel -r <user name>
The -r option is for deleting the user's home directory.
-
List the groups to which a user belongs to.
$ groups [user name]
-
Add a user to a group.
$ gpasswd -a <user name> <group name>
-
Delete a user from a group.
$ gpasswd -d <user name> <group name>
-
Create a new group.
$ groupadd <group name>
-
Delete an existing group.
$ groupdel <group name>
37 Miscellaneous
-
Rescan the SCSI subsystem for new devices (useful if your recently
plugged-in USB device is not being detected automatically)
# rescan-scsi-bus
-
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>.
-
Format a drive with EXT3 as the filesystem type.
# mkfs -t ext3 -v -L <volume name > <device file>
-
Create backup of all files changed while applying a patch:
$ patch -b -p0 < valgrind-3.5.0-glibc-2.11.patch
-
Display the local time equivalent of an UTC time.
$ date -d 'YYYY-MM-DD HH:MM UTC'
-
Interactively merge two files.
$ sdiff file_v1.c file_v2.c -o file_merge.c
-
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
Date: <2010-05-17 Mon 10:19>
HTML generated by org-mode 7.3 in emacs 23