#!/bin/bash
###############################################
# 2014_05May_09 - john meister
# copyright john meister 2014 http://LinuxMeister
#
# script to remove spaces in file names and replace with underscore
#
# cleans up web pages by eliminating special characters and
# allows sorts to work properly
#
# to use place this script in your path and
# make it executable, then cd to the directory
# and execute by the saved name
###############################################
#
###############################################
# removes spaces, special characters, slashes, and _-_ but NOT caps ####
###############################################
for f in *
do
mv -v "$f" `echo $f | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | sed 's/_-_/_/g'`
done
###############################################
# VARIATIONS: (substitue the "mv -v" line above...
###############################################
###############################################
# ### removes spaces only
# mv "$f" `echo $f | tr ' ' '_'`
###############################################
# ### removes spaces, special characters, slashes, caps and _-_ ####
# mv -v "$f" `echo $f | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
###############################################
###############################################
### removes characters and spaces using READ:
###############################################
# ls | while read -r FILE
# do
# mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
# done
###############################################
# remove only spaces using read:
###############################################
# ls | while read -r FILE
# do
# mv -v "$FILE" `echo $FILE | tr ' ' '_' `
# done
###############################################
|
The Art of Linux System Administration published by O'Reilly Media Study Guide for the LPIC-2 Certification Exams |
![]() Wagoneers FULL SIZE JEEPS JeepMeister "Jeep is America's -Enzo Ferrari MeisterTech Diesels + |
One Page Overview of Linux Commands click for an image of the 5 essential Linux commands An Intro to Linux |
at Midway Auto on SR9 in Snohomish, or at Northland Diesel in Bellingham, WA |