Commands by px (3)

  • This one-liner will use strace to attach to all of the currently running apache processes output and piped from the initial "ps auxw" command into some awk. Show Sample Output

    ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
    px · 2011-03-14 21:45:22 7
  • This one-liner is for cron jobs that need to provide some basic information about a filesystem and the time it takes to complete the operation. You can swap out the di command for df or du if that's your thing. The |& redirections the stderr and stdout to the mail command. How to configure the variables. TOFSCK=/path/to/mount FSCKDEV=/dev/path/device or FSCKDEV=`grep $TOFSCK /proc/mounts | cut -f1 -d" "` MAILSUB="weekly file system check $TOFSCK " Show Sample Output

    ( di $TOFSCK -h ; /bin/umount $TOFSCK ; time /sbin/e2fsck -y -f -v $FSCKDEV ; /bin/mount $TOFSCK ) |& /bin/mail $MAILTO -s "$MAILSUB"
    px · 2010-10-24 00:35:23 1
  • Use GNU/screen as a terminal emulator for anything serial console related. screen /dev/tty eg. screen /dev/ttyS0 9600 MacOSX: Cheat Sheet: Show Sample Output

    screen /dev/tty<device> 9600
    px · 2010-07-20 09:12:13 3

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

Picture Renamer
jhead is a very nice tool to do all sorts of things with photographs, in a batch-oriented way. It has a specific function to rename files based on dates, and the format I used above was just an example.

Reload all sysctl variables without reboot
Use `sysctl -p` without argument will only load /etc/sysctl.conf, but user configs always put in /etc/sysctl.d/*.conf, `sysctl --system` will load all the config files

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

replace recursive in folder with sed

Search for a process by name
ps and grep is a dangerous combination -- grep tries to match everything on each line (thus the all too common: grep -v grep hack). ps -C doesn't use grep, it uses the process table for an exact match. Thus, you'll get an accurate list with: ps -fC sh rather finding every process with sh somewhere on the line.

Display condensed log in a tree-like format.
Display condensed log in a tree-like format.

Rename files in batch

launch bash without using any letters
I don't know why anyone would use this, I was just messing around tonight and managed to start bash without using any letters and thought I would share. It's pretty simple, first it tries to execute "-" redirecting stderr to stdout which prints the error "bash: -: command not found" to standard output, then I try to execute "bash: -: command not found" which produces the output "bash: bash: -: command not found: command not found". lastly, (on the other side of the semicolon) I use the underscore environment variable which refers to the last command run ("bash: -: command not found") and take out everything after the first ":" character using brace expressions and your left with "bash"

Twitter update from terminal (pok3's snipts ?)
Found it on snipt, pok3, is it yours? I put my user = m33600, the password and the status was my robot message: Settima robot message: ALARM ZONE 3 (sent via command line). Now bots may have their identity on twitter...

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

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: