13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 8 ■ USING THE COMMAND LINE BETTEREither type this on the command line (in which case it will work only within that particular terminalwindow until it’s shut down) or, to make it a permanent function, add it to your ~/.bashrc and thenopen a new terminal window.■ Note If you don’t want to open a new terminal window, type source ~/.bashrc. However, this can sometimescreate problems with settings such as $PATH, because they are repeatedly redefined and thus grow steadilylonger.Then type the following:lds cn jkempThis will run an LDAP search for any entries with a cn value of jkemp (ldapsearch "(cn=jkemp)").This both saves typing and avoids having to remember which way the ( and " go in an LDAP searchcommand (and having to type it accurately once you’ve remembered it!).A function is basically a shell script, so you can use a function to do pretty much anything you canwrite a shell script to do. This means that you can get pretty complicated and even recursive. Thefollowing code will go recursively through the directory or directories you enter on the command line,changing any .html files into .shtml files, which is useful if you’re moving wholesale to using server-sideincludes in your web site.01 #!/bin/bash02 # JK 24.07.200903 if [ -z "$1" ]; then04 echo "Usage: $0 {directories-to-iterate over}"05 echo "Iterates over all files in directories changing .html to .shtml"06 exit 107 fi0809 cwd="$PWD"10 arg="$1"1112 function rename_recursive()13 {14 cd "$arg"15 for file in `ls`; do16 if [ -d "$file" ]; then17 rename_recursive "$file"18 else19 if [[ "$file" =~ .*\.html ]]; then20 oldname="`basename $file`"21 newname="`basename $file .html`.shtml"22 mv "$file" "$newname"23 fi24 fi25 done175Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!