Here is another installment of Command Line Gems, I present you with the “Not” The best Linux Commands.
1) Save an HTML page, and covert it to a .pdf file
wget $URL | htmldoc --webpage -f "$URL".pdf - ; xpdf "$URL".pdf &
2) backup and synchronize entire remote folder locally (curlftpfs and rsync over FTP using FUSE FS)
curlftpfs ftp://YourUsername:YourPassword@YourFTPServerURL /tmp/remote-website/ && rsync -av /tmp/remote-website/* /usr/local/data_latest && umount /tmp/remote-website
connect to a remote server using ftp protocol over FUSE file system, then rsync the remote folder to a local one and then unmount the remote ftp server (FUSE FS)
it can be divided to 3 different commands and you should have curlftpfs and rsync installed
3) Do some Perl learning…
podwebserver& sleep 2; elinks 'http://127.0.0.1:8020'
Prerequisites: module Pod::Webserver installed. You can install it typing:
sudo perl -MCPAN -e 'install Pod::Webserver'
You can replace elinks with your fav browser. For FF:
podwebserver& sleep 2; firefox -remote 'openurl( http://127.0.0.1:8020/, new-tab )'
If you have Firefox open, this will pop-up the index web in a new tab.
4) Serve current directory tree at http://$HOSTNAME:8080/
twistd -n web –path .
5) Convert (almost) any video file into webm format for online html5 streaming
ffmpeg -i input_file.avi output_file.webm
6) Compare an archive with filesystem
tar dfz horde-webmail-1.2.3.tar.gz
and you quickly know the files you changed
7) tar via network
tar cfX - exclude_opt_weblogic . | ssh tmp-esxsb044 "cd /opt/weblogic ; tar xf -"
8) download and install the software package in one step
rpm -ivh 'http://www.website.com/path/to/desired_software_package.rpm'
9) Download all images from a site
wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" http://example.com/images
This recursively downloads all images from a given website to your /tmp directory. The -nH and -nd switches disable downloading of the directory structure.
10) check site ssl certificate dates
11) get all pdf and zips from a website using wget
wget –reject html,htm –accept pdf,zip -rl1 url
If the site uses https, use:
wget --reject html,htm --accept pdf,zip -rl1 --no-check-certificate https-url
12) Download an entire static website to your local machine
wget –recursive –page-requisites –convert-links www.moyagraphix.co.za
13) Quickly share code or text from vim to others.
:w !curl -F "sprunge=<-" http://sprunge.us | xclip
Sprunge.us is a code/text sharing site like pastebin, but it is easy to post stuff from the command line.
How it works:
:w !commandIn vim, w writes the current tab to a file when a filename is given afterwards, but if !command is given, the output is piped to the stdin of command.
curl -F "sprunge=<-" http://sprunge.uscurl is an HTTP client. The -F option does an HTTP post to the given address. The data in the quotes is passed in the post. The “sprunge=” part sets up a fieldname – the part that follows is what is associated with the name. The “<” tells curl to send data from the file descriptor that follows it. The “-” in bash is a file descriptor that points to stdin instead of an actual file; in this case, stdin is being piped in from vim. After we send the HTTP post to sprunge.us, it will give back a url that points to the data you just sent.
| xclipxclip is a utility that lets you put stuff in your clipboard or selection buffer. This part uses a bash pipe ( | ) to redirect the stdout of the previous command to the stdin of the next command. So, we’re capturing the URL that curl gave us and putting it into the selection buffer, ready to paste into IRC or a forum.
Of course, for this to work, you must have curl (which comes by default on most distroes), and xclip installed.
If you prefer to use ctrl-v (paste from clipboard) instead of middle-click (paste from selection buffer), look up options on xclip – you can do that.
14) Create an SSH tunnel for accessing your remote MySQL database with a local port
ssh -CNL 3306:localhost:3306 firstname.lastname@example.org
15) Extract dd-image from VirtualBox VDI container and mount it
Tested with NTFS and found on this site:
The first 32256 bytes is the MBR
16) Forward port 8888 to remote machine for SOCKS Proxy
ssh -D 8888 email@example.com
Simply change your web browser’s proxy settings to point to a SOCKS proxy at port 8888 and you’re good to go.
17) Dump a web page
curl -s http://google.com | hexdump -C|less
Useful to browse dangerous web sites.
18) Edit a google doc with vim
google docs edit –title “To-Do List” –editor vim
Google just released a new commend line tool offering all sorts of new services from the commend line. One of them is uploading a youtube video but there are plenty more google services to interact with.
Download it here: http://code.google.com/p/googlecl/
This specific command courtesy of lifehacker:http://lifehacker.com/5568817/
Though all can be found in manual page linked above.
19) Colorful man
apt-get install most && update-alternatives –set pager /usr/bin/most
That command installs “most” and make this command as the default man reader. The “most” works like “less” (the current man reader), but it render colors for manpages and may do more things. Read “man most”.
You can see a preview here: http://www.dicas-l.com.br/dicas-l/20090718.php
20) Mirror a directory structure from websites with an Apache-generated file indexes
lftp -e "mirror -c" http://example.com/foobar/
wget/curl/friends are not good with mirroring files off websites, especially those with Apache-generated directory listings. These tools endlessly waste time downloading useless index HTML pages. lftp’s mirror command does a better job without the mess.
21) Convert images to a multi-page pdf
convert -adjoin -page A4 *.jpeg multipage.pdf
The linux package imagmagick is required for this command
22) printing barcodes
ls /home | head -64 | barcode -t 4×16 | lpr
64 elements max on 16 rows, 4 cols.
GNU Barcode will adapt automagically the width and the eight of your elements to fill the page.
Standard output format is PostScript.
23) convert a web page into a png
This requires the command-line print extension (see #2861 for more details). I use it to make up complex images with formatted text using CSS and whatnot. It’s a lot slicker than imagemagick for certain things. Now imagine using a local webserver with PHP and a database to generate the images. Oh, the possibilities…
24) Watch the progress of ‘dd’
pkill -USR1 ^dd$
The ‘dd’ command doesn’t provide a progress when writing data. So, sending the “USR1” signal to the process will spit out its progress as it writes data. This command is superior to others on the site, as it doesn’t require you to previously know the PID of the dd command.
25) Hex math with bc
echo 'obase=16; C+F' | bc
To do hex to binary: echo ‘ibase=16; obase=2; 16*16’ | bc # prints: 111100100
To do 16*16 from decimal to hex: echo ‘ibase=10; obase=16; 16*16’ | bc # prints: 100
You get the idea… Alternatively, run bc in interactive mode (see man page)