Home » Linux » Archive by category "Fedora" (Page 3)

Deleting files in Linux that are x-days old

Since I’m not running a PHP version provided by my distribution I’m responsible for cleaning up old session files myself. Aside from PHP another Perl webapp I run also doesn’t clean up its own session files. Luckily cleaning up these old files is something that’s very easy to do under Linux.

find /tmp/sess_* -mtime +2 -exec rm {} \;

In this example I’m only taking files that are at least 2 days old. Add this to your crontab and your session directory should stay nice and tidy.

vimdiff shorcut keys

I usually use KDiff3 when viewing the differences between files and merging stuff together. But from time to time I’ve found vimdiff to be a nice alternative, especially when I’m logged in through SSH on a server. The problem is I don’t use it that often so I tend to forget the key combinations. So instead I listed them here for future reference.

  • do – diff obtain
  • dp – diff put
  • [c – previous difference
  • ]c – next difference
  • :diffupdate – diff update
  • :syntax off – syntax off
  • zo – open folded text
  • zc – close folded text

Original source: http://hack2live.blogspot.nl/2009/02/vimdiff-shortcut-keys.html

f.lux – Better lighting for your computer

I don’t remember how I bumped into this one, but f.lux is a really nice piece of software that adapts your screens colors depending on the time of the day. After the sun has set it transitions your screen to a warmer color palette that’s a lot easier on the eyes when the lighting in your room gets less as well. It’s especially nice in the evening as you’re not really looking into a big source of light anymore. Well, you are, but it’s not that blueish light anymore and if you’re using a laptop reducing the¬†brightness improves it even more.

flux-shot

F.lux is available for Windows, Linux, Mac OSX and iOS (requires jailbreak) and is freely available from http://stereopsis.com/flux/.

Using tmux – shortcuts

Even though Windows 7 is my main OS I use terminals a lot. I don’t mean the Windows command prompt in this case, though I actually use that a lot as well. The terminal I’m talking about now is Bash, which I use on my Raspberry Pi, VPS’s and virtual machines. To connect to these systems I use PuTTY.

The biggest benefit tmux gives is not having to open several terminals. Instead you use tabs (windows) or you split the current window. When I’m working on a project which has its own dedicated virtual machine (through Vagrant) I usually log in, create a 2×2 grid, setup 2 panes for tailing log files, another connects to MySQL and the 4th is available for regular terminal stuff.

Another nice feature is being able to detach your current session and return to it later. I do that with my Raspberry Pi for instance. Inside my tmux session I run irssi (an IRC client) and instead of having to reconnect all the time I just detach the session when I’m done, and recover it whenever I need to hop on IRC again.

Key in using tmux effectively is knowing the shortcuts. Memorizing them improves productivity a lot. So to help you get started I listed the main ones below.

  • ctrl+b % or ctrl+b " for pane splitting
  • ctrl+b space for changing pane orientation
  • ctrl+b n for next window
  • ctrl+b arrow keys for pane selection (older versions only support up/down)
  • ctrl+b , for renaming window
  • ctrl+b d for detaching session (close without shutting it down)
  • tmux a to resume a detached sessions

Am I missing any neat shortcuts? Let me know by dropping it in the comments.

Find and replace in multiple files with sed

Nice usage of find and sed to find and replace text. I used it to update the copyright notices in my projects.

Just change the *.pl part to the file type you want.

find . -name "*.pl" -exec sed -i "s/2012/2013/g" '{}' \;

Source: Wikia