Rename multiple files in Linux

March 27, 2007

(Below tips are copied from LINUX BY EXAMPLE.com)

Often over time, we will want to reorganize a group of files by renaming them.

To rename *.txt to *.bak
(e.g. to rename ham.txt to ham.bak)

for f in *.txt; do mv "$f" "${f%.txt}.bak"; done

To remove ‘new-’ from new-*
(e.g. to rename new-ham.txt to ham.txt)

for f in new-*; do mv "$f" "${f#new-}"; done

${variable%pattern} vs ${variable#pattern}

The funny-looking symbol, ${f%.txt} is a useful match-and-remove string operator:

If the pattern ‘.txt’ matches the end of variable $f, it will remove the matching part (that’s ‘.txt‘) and return the rest. Try this:

f=new-ham.txt      # define $f as 'new-ham.txt'
echo ${f%.txt}     # display 'new-ham'

What about ${f#new-}? It’s almost the same, but it matches the pattern at the beginning of the variable.

echo ${f#new-}     # display 'ham.txt'

To remove autostart programs from windows

February 22, 2007

Windows XP comes with the System Configurationtool (Msconfig.exe), an excellent way to manage the startup process. To start it:

  1. Click Start, click Run, type Msconfig, and then press Enter.
  2. On the Startup tab, you’ll see a list of all the programs and processes that are set to run when Windows XP loads.
  3. Speed up your overall start time by clearing the check box next to any item you think you don’t need.
  4. Click Apply, and then restart your computer for the changes to take effect.

You can look up each entry at Paul Collins’ Startup Applications List to determine whether you want it to start automatically.

Necessary vim settings in .vimrc

January 18, 2007
  • Convert TAB to spaces

    set tabstop=4
    set shiftwidth=4
    set expandtab

  • Disable backup and swap file
    set nobackup
    set nowritebackup
    set noswapfile

Follow

Get every new post delivered to your Inbox.