25 Best Linux Commands For 2011

Here at blog.urfix.com we are kicking off the new year with a new server. Our last server got HN’D. Our poor plug computer could not take the load from being in the front page of Hacker News and finally melted. taking our chances again here are the 25 Best Linux commands for 2011

1) send a circular

echo “dear admin, please ban johnlame” | wall

Broadcast Message from root@urfix.com
(/dev/pts/2) at 20:32 …

dear admin, please ban johnlame

2) Find usb device

diff <(lsusb) <(sleep 3s && lsusb)

I often use it to find recently added or removed device, or using find in /dev, or anything similar.

Just run the command, plug the device, and wait to see him and only him

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) 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.

5) send a circular part 2

wall <<< “Broadcast This”


6) 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

7) Compare copies of a file with md5

cmp file1 file2

8) 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.

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) rename files according to file with colums of corresponding names

xargs -n 2 mv < file_with_colums_of_names

Maybe simpler, but again, don’t know how it will work with space in filename.

11) Create a new file

> file

12) stderr in color

mycommand 2> >(while read line; do echo -e “\e[01;31m$line\e[0m”; done)

13) 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.

14) Make vim open in tabs by default (save to .profile)

alias vim=”vim -p”

I always add this to my .profile rc so I can do things like: “vim *.c” and the files are opened in tabs.

15) Look for English words in /dev/urandom

head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt && wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt -O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt

16) Find a CommandlineFu users average command rating

wget -qO- www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> ‘/num-votes/{S+=$2; I++}END{print S/I}’

17) Set laptop display brightness

echo <percentage> > /proc/acpi/video/VGA/LCD/brightness

Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video).

cat /proc/acpi/video/VGA/LCD/brightnessto discover the possible values for your display.

18) Send your terminfo to another machine

infocmp rxvt-unicode | ssh 10.20.30.40 “mkdir -p .terminfo && cat >/tmp/ti && tic /tmp/ti”

I frequently use this trick to send my terminal settings to HPUX and older RHEL systems.
This is due to the fact that terminfo support for rxvt-unicode (my preferred terminal app) does
not exist on many older Linux and Unices.

19) Efficient remote forensic disk acquisition gpg-crypted for multiple recipients

dd if=/dev/sdb | pigz | gpg -r <recipient1> -r <recipient2> -e –homedir /home/to/.gnupg | nc remote_machine 6969

Acquires a bit-by-bit data image, gzip-compresses it on multiple cores (pigz) and encrypts the

data for multiple recipients (gpg -e -r). It finally sends it off to a remote machine.

20) Look up a unicode character by name

exec 5< <(grep -i “$*” $(locate CharName.pm));while read
<&5;do h=${REPLY%% *};/usr/bin/printf “\u$h\tU+%s\t%s\n”  “$h”  “${REPLY##$h }”;done

21) strips the first field of each line where the delimiter is the first ascii character



cut -f2 -d`echo -e '\x01'` file

22) shell equivalent of a boss button

cat /dev/urandom | hexdump -C | highlight ca fe 3d 42 e1 b3 ae f8 | perl -MTime::HiRes -pnE “Time::HiRes::usleep(rand()*1000000)”

Nobody wants the boss to notice when you’re slacking off. This will fill your shell with random data, parts of it highlighted.

Note that ‘highlight’ is the Perl module App::highlight, not “a universal sourcecode to formatted text converter.” You’ll also need Term::ANSIColor.

23) Open Remote Desktop (RDP) from command line having a custom screen size

xfreerdp –plugin rdpsnd -g 1280×720 -a 24 -z -x m -u $username -p $password 10.20.30.40

This example uses xfreerdp, which builds upon the development of rdesktop. This example usage will also send you the remote machine’s sound.

24) Show memory stats on Nexenta/Solaris

echo ::memstat | mdb -k

25) 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.

Have fun with these new commands and may the new year bring you and yours prosperity and joy.

2 Comments

  1. Pingback: Tweets that mention 25 Best Linux Commands For 2011 -- Topsy.com

Leave Comment

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.

UrFix's Blog