Commands by eduo (4)

  • Finder compresses to ZIP but always includes extraneous metadata files (__MACOSX and .DS_Store) files and folders that may confuse other programs. One alternative is creating them and then editing the ZIP. This can work standalone or in an automator script accepting multiple selections (files or folders) and creating one zip per argument/selected file without that metada.

    echo "$@" for f in "$@"; do FILENAME=${f##*/};FILEPATH=${f%/*}; cd "${FILEPATH}"; zip -r "${f}".zip "${FILENAME}" -x "*.DS_Store" -x "__MACOSX"; done; afplay /System/Library/Sounds/Sosumi.aiff
    eduo · 2018-10-20 12:27:50 493
  • Group membership in OS X is a mish-mash of standards that end up meaning there's almost a half-dozen of ways to belong to a group, what with group inheritance and automatic assignment. This means there's no easy command to find out all groups a user belongs to. The only sensible way then is to list all users and then query each user for membership. NOTE: This is a function. Once input you can execute it by calling with a groupname. Show Sample Output

    members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };
    eduo · 2012-05-20 11:34:33 8
  • Line can be modified as needed. This considers weekdays to be Mon-Fri. If run any working day it'll provide a parameters for the next working day for "at". "beep" provided as a sample command. This can be modified easily to include wait time. If you need something to run "D" days after today: # D=4;if [ $(date +%u --date="${D} days") -lt 5 ];then AT="+${D} days";else AT="next monday";fi; echo "beep" | at noon ${AT}

    if [ $(date +%u) -lt 6 ];then AT="tomorrow"; else AT="next monday";fi;echo "beep" | at ${AT}
    eduo · 2011-06-01 14:15:11 9
  • Useful for use in other scripts for renaming, testing for extensions, etc. Show Sample Output

    eduo · 2009-06-10 16:11:38 13

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

Cleanup firefox's database.
Sqlite database keeps collecting cruft as time passes, which can be cleaned by the 'vacuum;' command. This command cleans up the cruft in all sqlite files relating to the user you have logged in as. This command has to be run when firefox is not running, or it will exit displaying the pid of the firefox running.

Search through files, ignoring .svn
By putting the "-not \( -name .svn -prune \)" in the very front of the "find" command, you eliminate the .svn directories in your find command itself. No need to grep them out. You can even create an alias for this command: $ alias svn_find="find . -not \( -name .svn -prune \)" Now you can do things like $ svn_find -mtime -3

list block devices
Shows all block devices in a tree with descruptions of what they are.

Unbelievable Shell Colors, Shading, Backgrounds, Effects for Non-X
I've been using linux for almost a decade and only recently discovered that most terminals like putty, xterm, xfree86, vt100, etc., support hundreds of shades of colors, backgrounds and text/terminal effects. This simply prints out a ton of them, the output is pretty amazing. If you use non-x terminals all the time like I do, it can really be helpful to know how to tweak colors and terminal capabilities. Like: $ echo $'\33[H\33[2J'

Recursively list all of the files in a directory, group them by extension and calculate the average of the file sizes in each group
Here's an annotated version of the command, using full-names instead of aliases. It is exactly equivalent to the short-hand version. # Recursively list all the files in the current directory. Get-ChildItem -Recurse | # Filter out the sub-directories themselves. Where-Object { return -not $_.PsIsContainer; } | # Group the resulting files by their extensions. Group-Object Extension | # Pluck the Name and Count properties of each group and define # a custom expression that calculates the average of the sizes # of the files in that group. # The back-tick is a line-continuation character. Select-Object ` Name, Count, @{ Name = 'Average'; Expression = { # Average the Length (sizes) of the files in the current group. return ($_.Group | Measure-Object -Average Length).Average; } } | # Format the results in a tabular view, automatically adjusted to # widths of the values in the columns. Format-Table -AutoSize ` @{ # Rename the Name property to something more sensible. Name = 'Extension'; Expression = { return $_.Name; } }, Count, @{ # Format the Average property to display KB instead of bytes # and use a formatting string to show it rounded to two decimals. Name = 'Average Size (KB)'; # The "1KB" is a built-in constant which is equal to 1024. Expression = { return $_.Average / 1KB }; FormatString = '{0:N2}' }

share internet connection with only one network interface
the below command create a alias for share your internet connection with another. $ifconfig eth0:1 Its obviously necessary too activate the iptables post-routing and ip forwarding, as root: $modprobe iptable_nat $iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE $echo 1 > /proc/sys/net/ipv4/ip_forward Be sure that the alias is not your active real ip range

Create a new file

Timer with sound alarm
I'd prefer this one, you have to install espeak to get this running

Print Asterisk phone logs
Prints a log of phonecalls placed from/to an asterisk server, formated into an easily readable table. You can use partial number/queue matches, or use .* to match everything.

This command can be used to extract the IP address of the network.
can be used within a script to configure iptables for example: iface=$2 inet_ip=`ifconfig "$iface" | grep inet | cut -d: -f2 | cut -d ' ' -f1` ipt="sudo /sbin/iptables" ......................... ---------------------------------------------------------------------------------------------------------------- $ipt -A INPUT -i $iface ! -f -p tcp -s $UL -d $inet_ip --sport 1023: --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT ---------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------- $ipt -A OUTPUT -o $iface -p tcp -s $inet_ip -d $UL --sport 3306 --dport 1023: -m state --state ESTABLISHED,RELATED -j ACCEPT -----------------------------------------------------------------------------------------------------------------

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: