commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
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:
This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler.
htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O.
The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here: http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml
apt-get is pretty aggressive when it downloads, potentially hogging the bandwidth of your network. The 25 is in KB, change this to your needs.
Just copy and paste the code in your terminal.
Note : sudo apt-get for debian versions , change as per your requirement .
Source : www.h3manth.com
This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files.
Alternately, you can do this to follow a specific list of log files:
sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}
To ensure that it will never come back, you can edit /etc/modprobe.d/blacklist
Add "blacklist pcspkr" sans quotes
Next time you are leaching off of someone else's wifi use this command before you start your bittorrent ...for legitimate files only of course.
It creates a hexidecimal string using md5sum from the first few lines of /dev/urandom and splices it into the proper MAC address format. Then it changes your MAC and resets your wireless (wlan0:0).
Scan for open ports on the target device/computer (192.168.0.10) while setting up a decoy address (192.168.0.2). This will show the decoy ip address instead of your ip in targets security logs. Decoy address needs to be alive. Check the targets security log at /var/log/secure to make sure it worked.
gemInst.sh:
#!/bin/bash
for i in $@; do
if [ "$1" != "$i" ]
then
echo /newInstall/gem install $1 -v=\"$i\"
/newInstall/gem install $1 -v="$i"
if [ "$?" != "0" ]
then
echo -e "\n\nGEM INSTALL ERROR: $1\n\n"
echo "$1" > gemInst.err
fi
fi
done
sudo ipfw pipe 1 config bw 50KByte/s
Set the bandwidth (bw) limit to any number you want. For example you could have a 15kb pipe for X application and then a 100kb pipe for another application and attach things to those pipes. If a port isn’t attached to a pipe, it runs at full speed. Change the number (in this case 1) to a different number for a different pipe.
The next step is to attach your port.
sudo ipfw add 1 pipe 1 src-port 80
In this case anything on port 80 (http) will be set to a limit of 50Kbyte/s. If you want to attach a second port to this pipe, repeat the command but change the port number at the end.
src : http://www.mactricksandtips.com/2008/12/throttling-bandwidth-on-a-mac.html
adobe updater keeps popping up. (normal update fails, probably due to insufficient rights)
(src: http://aricsblog.blogspot.com/2007/12/adobe-updater-crashes-on-mac-os-x-and.html)
sudo pmset -a hibernatemode 1 sets hiberate on.
sudo pmset -a hibernatemode 0 sets hibernate off.
from the pmset man page:
0001 (bit 0) enables hibernation; causes OS X to write memory state to
hibernation image at sleep time. On wake (without bit 1 set) OS X will
resume from the hibernation image. Bit 0 set (without bit 1 set) causes
OS X to write memory state and immediately hibernate at sleep time.
I often change my MacBook's sleep state. So I created a function for bash to make it a little easier.
Usage:
hibernate (on | off)
"hibernate on" will set your laptop to hibernate if the lid is closed.
"hibernate off" will set your laptop to sleep if the lid is closed.
### note : "proper" indentation isn't preserved on the website
function hibernate()
{
case "${1}" in
on)
sudo pmset -a hibernatemode 1
echo Hibernate mode on.
;;
off)
sudo pmset -a hibernatemode 0
echo Hiberate mode off.
;;
*)
echo "I'm sorry Dave, but I can't do that."
;;
esac
}
To make things easier, add the proper line in your /etc/sudoers file so that your user may invoke pmset without a password. Here's how mine looks:
bwayne luna = NOPASSWD: /usr/bin/pmset
Don't forget that you must edit sudoers with `sudo visudo` from Terminal.app, and not by another text editor.
Sorry this is so Mac OS specific.
will purge:
only installed apps: /^ii/!d
avoiding current kernel stuff: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d
using app names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/
avoiding stuff without a version number: /[0-9]/!d
eth0 = the name of the interface
00:01:02:03:04:05 = the new mac adresse
the same thing for wireless card $ sudo iwconfig eth1 hw ether 00:01:02:03:04:05
Create a temporary file that acts as swap space. In this example it's a 1GB file at the root of the file system. This additional capacity is added to the existing swap space.
Schedule your Mac to sleep at any future time.
Also wake, poweron, shutdown, wakeorpoweron. Or repeating with
sudo pmset repeat wakeorpoweron MTWRFSU 7:00:00
Query with
pmset -g sched
Lots more at http://www.macenterprise.org/articles/powermanagementandschedulingviathecommandline
ec commits changes to etckeeper
must have etckeeper installed with bzr to use this
place inside bashrc
can be used from any directory to commit changes
Shred can be used to shred a given partition or an complete disk. This should insure that not data is left on your disk
Shows the UUID of a filesystem or partition that can be used in kernel root options and in fstab.
Run it without the -u option to generate more information. eg:
~/ sudo vol_id /dev/sda2
ID_FS_USAGE=other
ID_FS_TYPE=swap
ID_FS_VERSION=2
ID_FS_UUID=27fca13d-97b7-4d28-882c-6d03353f0a82
ID_FS_UUID_ENC=27fca13d-97b7-4d28-882c-6d03353f0a82
ID_FS_LABEL=
ID_FS_LABEL_ENC=
Installing most OSX apps is just a matter of dropping it in /Applications, either GUI-wise or with cp -r. However, many packages are distributed in "mpkg" format, and those have to be installed with an installer. If you don't want to go to the trouble of firing up VNC to install an mpkg, you can use the "installer" command.
This will install an application from a .mpkg it to /Applications system-wide. To install a program for just one user, replace "-target /" with "-target username".
Purge all configuration files of removed packages
Useful for removes a package and its depends, for example to remove the gnome desktop environment, also configuration files will be removed, you should be carefully and sure that you want to do this.