Archive

Archive for the ‘Uncategorized’ Category

Delete Files Older than X Days

May 5th, 2009 grady No comments

The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.

Command Syntax
        find /path/to/files* -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Explanation:

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.
Categories: Uncategorized Tags:

SSH Escape Sequences

May 5th, 2009 grady No comments

Yes, SSH has an escape sequence, much like telnet’s strl-] sequence. Remember those times when you, say, restart a daemon, go to log out of the server, but are left hanging? SSH escape sequence!

It’s tunable in /etc/ssh/ssh_config on the client-side, and of course in your ~/.ssh/config, but by default, the EscapeChar is the ~ key. So, if you ssh into a box. and type:
~?
 You’ll be presented with this list:

                Supported escape sequences:
                ~. – terminate connection
                ~B – send a BREAK to the remote system
                ~C – open a command line
                ~R – Request rekey (SSH protocol 2 only)
                ~^Z – suspend ssh
                ~#  - list forwarded connections
                ~& - background ssh (when waiting for connections to terminate)
                ~? – this message
                ~~ – send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.)

You can use ~. to kill the connection… or ~^Z to suspend it.

A particularly interesting one is the command line option, or “~C”. With that, you can get an ssh command line, with the following options:

  • -Lport:host:hostport    Request local forward
  • -Rport:host:hostport    Request remote forward
  • -KRhostport             Cancel remote forward

 That is, you can forward ports using your existing SSH connection, rather than starting up a new one. Cool!
 Another helpful way out of “locked” terminals is screen’s ctrl-a ctrl-k

Categories: Uncategorized Tags:

HOWTO: Reset a lost OS X password

May 5th, 2009 grady No comments

I’ve you’ve forgotten your Mac’s admin account password, don’t worry. Assuming you haven’t locked out OpenFirmware, it’s a pretty simple task to change your password back to something you know.
Here’s how:

  • Hold Apple+S when booting to enter single user mode
  • #sh /etc/rc
  • #passwd yourusername
  • #reboot

If you can’t recall your user name, you can either look in the /Users folder (the directories are named by user), or run “niutil -list . /users”.
Also, on older systems the /etc/rc script isn’t available, apparently. If that second step fails, try mounting and starting the base services manually:

  • #/sbin/fsck -y
  • #/sbin/mount -uw /
  • #/sbin/SystemStarter

I’ve had to do this a couple of times for friends when they’ve bought a second hand machine, and once when I had a momentary brain lapse and forgot my own password. Works like a charm, though you’ll loose any passwords stored in your keychain.

Categories: Uncategorized Tags:

Tree Command for Mac

March 2nd, 2008 grady No comments

Tree Command for Mac: “find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|; |;g’”

(Via Murphy Mac.)

Categories: Uncategorized Tags: