11 Not Sick Linux Commands

1) Create a pdf version of a manpage

man -t manpage | ps2pdf – filename.pdf

Quick and dirty version. I made a version that checks if a manpage exists (but it’s not a oneliner). You must have ps2pdf and of course Ghostscript installed in your box.

Enhancements appreciated :-)

2) Bind a key with a command

bind -x '"\C-l":ls -l'

the -x option is for binding to a shell command

3) Use file(1) to view device information

file -s /dev/sd*

file(1) can print details about certain devices in the /dev/ directory (block devices in this example). This helped me to know at a glance the location and revision of my bootloader, UUIDs, filesystem status, which partitions were primaries / logicals, etc.. without running several commands.

See also:

file -s /dev/dm-* file -s /dev/cciss/*etc..

4) Single use vnc-over-ssh connection

ssh -f -L 5900:localhost:5900 your.ssh.server "x11vnc -safer -localhost -nopw -once -display :0";
vinagre localhost:5900

This command

1. SSH into a machine
2. Tunnels VNC port to your local computer (“-L 5900:localhost:5900”)
3. Runs a single use vnc server (“x11vnc -safer -localhost -nopw -once -display :0”)
4. Goes into the background (“-f”)
5. Runs VNC viewer on the local computer connecting to the remote machine via the newly created SSH tunnel (“vinagre localhost:5900”)

5) Stop Flash from tracking everything you do.

for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done

Brute force way to block all LSO cookies on a Linux system with the non-free Flash browser plugin. Works just fine for my needs. Enjoy.

6) A child process which survives the parent’s death (for sure)

( command & )

Test scenario:

* Open xterm (or konsole, …)

* Start xeyes with: ( xeyes & )

* Close the xterminal

The xeyes process should be still running.

 

7) Compare copies of a file with md5

cmp file1 file2

8) backup delicious bookmarks

curl --user login:password -o DeliciousBookmarks.xml -O 'https://api.del.icio.us/v1/posts/all'

Useful script to backup all your delicious bookmarks. With decilicious shutting down soon , it could be useful

9) Run a program transparently, but print a stack trace if it fails

gdb -batch -ex “run” -ex “bt” ${my_program} 2>&1 | grep -v ^”No stack.”$

For automated unit tests I wanted my program to run normally, but if it crashed, to add a stack trace to the output log. I came up with this command so I wouldn’t have to mess around with core files.

The one downside is that it does smoosh your program’s stderr and stdout together.

10) back ssh from firewalled hosts

ssh -R 5497:127.0.0.1:22 -p 62220 user@public.ip

host B (you) redirects a modem port (62220) to his local ssh.

host A is a remote machine (the ones that issues the ssh cmd).

once connected port 5497 is in listening mode on host B.

host B just do a

ssh 127.0.0.1 -p 5497 -l user

and reaches the remote host’ssh. This can be used also for vnc and so on.

11) Rename HTML files according to their title tag

perl -wlne'/title>([^<]+)/i&&rename$ARGV,"$1.html"' *.html

The above one-liner could be run against all HTML files in a directory. It renames the HTML files based on the text contained in their title tag. This helped me in a situation where I had a directory containing thousands of HTML documents with meaningless filenames.

4 thoughts on “11 Not Sick Linux Commands”

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.