bash

Shell Script Snippets

Useful Bash shell scripts and one-liners for managing files.

Rename multiple files:

for i in *.avi
do
j=`echo $i | sed 's/find/replace/g'`
mv "$i" "$j"
done

Can also be written on a single line as

for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

Finding Multiple Files in a directory
Find and count how many files were modified more than 365 days ago:

find . -mtime +356 | wc -l

Find and delete files that were modified more than 365 days ago:

find . -mtime +365 -exec rm {} \;

Technology:

Shell Script Snippets

Rename multiple files:

for i in *.avi
do
j=`echo $i | sed 's/find/replace/g'`
mv "$i" "$j"
done

Can also be written on a single line as

for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

Finding Multiple Files in a directory
Find and count how many files were modified more than 365 days ago:

Technology:

Edit Shell Path

If you need to add /usr/local/bin to your OS X path for custom applications you've built and installed:

Check what shell you are using:

echo $SHELL

If it's /bin/bash, create or modify ~/.profile, adding the new path:

cat << EOF >> ~/.profile
PATH=/usr/local/bin:\$PATH; export PATH
EOF

If it's /bin/tcsh:

Technology:

Subscribe to RSS - bash

Recent Updates

  • 1 year 1 month ago
  • 1 year 1 month ago
  • 1 year 1 month ago
    php 8.x
  • 1 year 1 month ago
    10.6.7
  • 1 year 1 month ago
    Drop Centos 5/6 stuff