Commands by amosshapira (1)

  • The command is useful when, e.g., booting an existing system with a rescue or installation CD where you need to chroot into the hard-disk and be able to do stuff which accesses kernel info (e.g. when installing Ubuntu desktop with LVM2 you need to mount and chroot the hard disk from a shell window in order to install packages and run initramfs inside chroot). The command assumes that /mnt/xxx is where the chroot'ed environment's root file system on the hard disk is mounted.

    for i in sys dev proc; do sudo mount --bind /$i /mnt/xxx/$i; done
    amosshapira · 2009-04-20 16:52:14 1

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Verify/edit bash history command before executing it
Bash history commands are those that begin with the character ! (eg. the most popular 'sudo !!' Explained here => By default bash immediately executes the history command. Setting this shell option will make bash first allow you to verify/edit an history command before executing it. To set this option permanently, put this command in ~/.profile or ~/.bashrc file. To unset this option issue following command. $shopt -u histverify

Archive a directory with datestamp on filename
A useful bash function: gztardir() { if [ $# -ne 1 ] ; then echo "incorrect arguments: should be gztardir " else tar zcvf "${1%/}-$(date +%Y%m%d-%H%M).tar.gz" "$1" fi }

Quick directory bookmarks
Set a bookmark as normal shell variable $ p=/cumbersome/path/to/project To go there $ to p This saves one "$" and is faster to type ;-) The variable is still useful as such: $ vim $p/ will expand the variable (at least in bash) and show a list of files to edit. If setting the bookmarks is too much typing you could add another function $ bm() { eval $1=$(pwd); } then bookmark the current directory with $ bm p

Backup a remote database to your local filesystem
I have this on a daily cronjob to backup the database from (awesome hosts by the way) to my local drive. Note that (on my Ubuntu system at least) you need to escape the % signs on the crontab.

Swap the two last arguments of the current command line
Say you just typed a long command like this: $ rsync -navupogz --delete /long/path/to/dir_a /very/long/path/to/dir_b but you really want to sync dir_b to dir_a. Instead of rewriting all the command line, just type followed by , and your command line will read $ rsync -navupogz --delete /very/long/path/to/dir_b /long/path/to/dir_a

List all Samba user name

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

View all date formats, Quick Reference Help Alias
If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command. # creating a date-based ssh-key for $ ssh-keygen -f ~/.ssh/`date [email protected]$HOSTNAME-%m-%d-%g` -C '[email protected]' $ # /home/gpl/.ssh/[email protected] # create a tar+gzip backup of the current directory $ tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g'

check for write/read permissions
su www-apache/ftp user and then check readable: find ~/ -type d \( -wholename '/dev/*' -o -wholename '/sys/*' -o -wholename '/proc/*' \) -prune -o -exec test -r {} \; -exec echo {} readable \; 2>/dev/null check writable: find ~/ -type d \( -wholename '/dev/*' -o -wholename '/sys/*' -o -wholename '/proc/*' \) -prune -o -exec test -w {} \; -exec echo {} writable \; 2>/dev/null

Print your cpu intel architecture family

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: