Mass changing files’ modification date on Windows

March 2nd, 2012

It’s sometimes useful to be able to change a file’s modification date. Linux makes it easy by simply using the “touch” command. I found this rather useful in cases where files were transferred between servers, which unfortunately do not have their times synchronized.

So, how can this be done on Windows?

Here is the command to issue in order to modify a single file’s modification time:

copy filename,,+

But in most cases, you’d be looking at mass-changing the modification date of files inside a certain directory. To do so, use the following command:

for %f in (c:\path\to\folder\*.*) do copy %f,,+

This would loop over all files containing a “dot” (i.e. extension) in c:\path\to\folder, and changes their modification time to the current system time. If for example you want the above to only go through XML files within that folder, then use *.xml instead of *.*

PS: the above command would work if you’re manually issuing it via the command prompt. However, if you’d like to embed that it in a batch file, make sure to replace %f with %%f. In other words, the command would turn into:

for %%f in (c:\path\to\folder\*.*) do copy %%f,,+

Highlighting “grep” matches

February 21st, 2012

“grep” is a useful Linux tool allowing the user to print lines matching a specific search pattern. Most popular uses is by “piping” the output of one command to “grep” (such as cat /path/to/file | grep findme), or by directly looking for a pattern inside one or more file (e.g. grep findme /path/to/*.txt).

This would print lines that match the search string / expression. However, how to colorize the matching patterns? Simple! Use the --color=always flag, i.e.:

grep --color=always -i findme /path/to/*.txt

Next, if you’re doing lots of “grep” work and don’t want to keep specifying the color flag, you can opt for the following:

Add it to the GREP_OPTIONS environment variable

export GREP_OPTIONS=’--color=always’

Or, if you’re using bash as your shell, add it to /etc/bashrc. Simply edit that file using your preferred editor (e.g. vim, nano, etc.), and add the above export command at the very end of the file. When done, save and exite the editor, then issue the following command, so that the changes take effect: source /etc/bashrc

Determining, via the shell prompt, the Linux distribution in use

January 4th, 2012

SSH is sometimes the only mode of access you have to a server. So how do you instantly determine the distro in use?

The following would work for most popular distributions (RedHat, CentOS, Ubuntu, etc.):

cat /etc/*-release

If the above returns “No such file or directory”, try the following which would work on Debian-based distros:

lsb_release -a

Finally, for kernel-related data, use the following command:

uname -a

You’ll be able to determine the kernel version and release date, whether it’s a 32 or 64 bit hardware and the current machine hostname.

Flushing / clearing DNS in Mac OSX

October 11th, 2011

Below is how to clear / flush the DNS cache in Mac OSX.

(1) Open the terminal (Finder -> Applications -> Utilities -> Terminal)

(2a) In case your operating system is ‘Leopard’ (10.5.*) or ‘Snow Leopard’ (10.6.*), issue the following command:

dscacheutil -flushcache

(2b) Otherwise, for older operating systems, issue the following command:

lookupd -flushcache

This is the equivalent of the following Windows command: ipconfig /flushdns

Deleting a file, the name of which starts with a hyphen (Linux)

May 2nd, 2011

You might have come across a difficulty in deleting a file in Linux whose name starts with a dash/hyphen.

Adding an escape character (e.g. rm -rf \-filename) or quoting the file name (e.g. rm -rf “-filename”) will not do the job.

The solution is simple: explicitly provide the full or relative path to the file. e.g.:

rm -rf /path/to/-file

or the following – if for instance your current working directory is the one containing the file in question

rm -rf ./-file

Mac users: turn colors into negative

March 24th, 2011

Are you a mac user? try the following keyboard combination:

cmd + alt (option) + ctrl + 8

Colors are instantly inverted, giving the entire screen a negative-photography like feel.

Hit the same combination to restore the colors.

Linux: finding files modified or accessed at a certain time

February 20th, 2011

The ‘find’ utility is quite handy when used with the proper parameters. Below is a few ways to find files/folders based on the time they were accessed or modified.

Example 1:

find /path/to/folder -type f -name “*.txt” -mtime -5

This will find ‘files’ (-type f) within the folder /path/to/folder (or one of its sub directories), whose name ends with ‘.txt’, and which were modified (mtime) less than 5 days ago

Example 2:

find /path/to/folder -type d -name “stat*” -mtime +10

This would find ‘directories’ (-type d) within the folder /path/to/folder (or one of its subdirectories), whose name starts with ‘stat’, and which were modified more than 10 days ago

Example 3:

find . -iname “*.pdf” -mtime +2 -mtime -7

This would help you find files or folders in the ‘current directory’ (.), whose name ends with ‘.pdf’ regardeless of the case of that suffix (e.g. example.PDf would be matched), which were modified more than 2 days and less than 7 days ago (i.e. between 3 to 6 days ago).

Example 4:

find / -type f -atime -5 -size +100k

This example makes use of atime, i.e. time of access (as opposed to mtime, which is the time the file was modified). The above command would help you find files in your entire system (/ being the system root, unless your shell is jailed), which were accessed less than 5 days ago, and which are at least 100 kbytes in size.
PS: if you do not specify the ‘b’, ‘k’, ‘m’, etc., the default would be blocks of 512 bytes. For instance, using +100 instead of +100k, means you’re looking for files sized at least 100*512=51200 bytes (50 kbytes).

More examples to be added…

Facebook’s new photo viewer

February 12th, 2011

Facebook recently introduced a new way of browsing photos and albums. The new photo viewer uses the lightbox technique whereby the page is dimmed and a box is overlaid with a larger version of the selected image.

Some of the improvements it brings are the ability to stay on the page without having to go back in your browser’s history (you simply hit the close ‘x’ button and you’re back to where you were), faster photo flipping/browsing and the ability to download a high res version of the image (if available).

For those who hate this lightbox preview, you may switch to the old fashioned way by simply opening the picture in a new tab (hold ctrl key + click) or a new window (hold shift key + click) instead of simply clicking on the picture. You may then continue browsing in the new tab/window the same way you were used to.

Forcing links that open in a ‘new window’ to open in a ‘new tab’

August 7th, 2010

Do you want to force links that open in a new window to open in a new tab instead? The answer is pretty simple.


  • Type the following in the url bar: about:config
  • Edit the following variables:
    • -> 3
    • -> 3
    • -> 0
  • If any of those variables is not yet defined, simply right click and select ‘new->integer’, enter the variable name then its integer value.



  • Go to: tools -> internet options
  • Then make sure you select ‘always open pop-ups in a new tab‘ under ‘when a pop-up is encountered

That’s it!

Enabling telnet in windows vista

November 6th, 2009

Some of you may be missing the good old command-line telnet client. The thing is that vista has this client disabled by default. The good news is that you can easily install/enable it. To do so, follow these steps:

  1. Go to Control Panel
  2. Click on ‘Programs’
  3. Under ‘Programs and Features’, click on ‘Turn windows features on or off’
  4. Wait a bit for the list to be compiled
  5. Tick ‘Telnet client‘ and hit ‘OK’ then wait for it to be installed

You may now open a command prompt and use telnet hostname port

Good luck