Get your own free workspace
View
 

ShellScriptingSnippets

Page history last edited by PBworks 5 years, 7 months ago
  • Proper way to read a file in

 

while read f; do

echo $f # or whatever it is you need to do with file

done < /tmp/file.txt

 

  • Strip comments and blank lines from file

 

sed -e 's;#.*;;' -e '/^ *$/d' /tmp/file-with-comments

 

  • Convert filenames to all lowercase

 

for file in *; do mv $file `echo $file | tr A-Z a-z` done

 

  • Empty files in current directory

 

find . -name \* -exec rm "{}" \; -exec touch "{}" \;

 

  • Find suid and sgid programs

 

find / -type f \(-perm -04000 -o -perm -02000 \)

 

  • Find Yesterdays Date

 

echo `TZ=GMT+29 date +"%D"`

Comments (0)

You don't have permission to comment on this page.