commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Here's my version. It's a bit lengthy but I prefer it since it's all Bash.
You can use ordinary printf to convert "%23%21%2fbin%2fbash" into "#!/bin/bash" with no external utilities, by using a little known printf feature -- the "%b" specifier converts shell escapes. Replace % with \x and printf will understand the urlencoded string.
BASH's printf has an extension to set a variable directly, too. So you get to convert urlencoded strings from garble to plaintext in one step with no externals and no backticks.
List the full path of some files.
You can add ".*" on the end if you want to display hidden files.
Better awk example, using only mplayer, grep, cut, and awk.
Parses /etc/group to "dot" format and pases it to "display" (imagemagick) to show a usefull diagram of users and groups (don't show empty groups).
Converts a number of bytes provided as input, to a human readable number.
Converts IP octets to hex using printf command. Useful for generating pxeboot aliases in the pxelinux.cfg folder.
poorman's ifstat using just sh and awk. You must change "eth0" with your interface's name.
when you can do it , avoid pipe
I find it useful when I want to add another crontab entry and I need to specify the appropriate PATH.
I give ''whichpath'' a list of programs that I use inside my script and it gives me the PATH I need to use for this script.
''whichpath'' uses associative array, therefore you should have Bash v4 in order to run it.
See sample output.
WIDTHL=10 and WIDTHR=60 are setting the widths of the left and the right column/bar. BAR="12345678" etc. is used to create a 80 char long string of "="s. I didn't know any shorter way.
If you want to pipe results into it, wrap the whole thing in ( ... )
I know that printing bar graphs can be done rather easily by other means. Here, I was looking for a Bash only variant.
Calc the rough time from Twitter. Now with leading Zeroes.
usage: mem memcache-command [arguments]
where memcache-command might be:
exptime argument is set to 0 (no expire)
flags argument is set to 1 (arbitrary)
also works in vim
Among other things, this allows the sorting of comment descriptions and command lines retrieved as text from CommandLineFu.com.
rename file name with fixed length nomeric format pattern
Replace service --status-all 2>&1 by service --status-all 2>/dev/null to hide all services with the status [ ? ]
Watch the temperatures of your CPU cores in real time at the command line. Press CONTROL+C to end.
GORY DETAILS: Your computer needs to support sensors (many laptops, for example, do not). You'll need to install the lm-sensors package if it isn't already installed. And it helps to run the `sensors-detect` command to set up your sensor kernel modules first. At the very end of the sensors-detect interactive shell prompt, answer YES to add the new lines to the list of kernel modules loaded at boot.
This command will delete all branches in your git repository other than next and master. I use this to cleanup my git repos after making multiple branches and merging them back into next. It's much faster than individually deleting each expired branch using:
git branch -D <branch_name>
this leaves the cursor at the bottom of the terminal screen, where your eyes are.
ctrl-l moves it to the top, forcing you to look up.