Using sed to mass rename files

First, I should say that the easiest way to do this is to use the prename or rename commands. On Ubuntu, OSX (Homebrew package rename, MacPorts package p5-file-rename), or other systems with perl rename (prename): rename s/0000/000/ F0000* or on systems with rename from util-linux-ng, such as RHEL: rename 0000 000 F0000* That’s a lot … Read more

How to delete files older than X hours

Does your find have the -mmin option? That can let you test the number of mins since last modification: find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete Or maybe look at using tmpwatch to do the same job. phjr also recommended tmpreaper in the comments.

Open and write data to text file using Bash?

The short answer: echo “some data for the file” >> fileName However, echo doesn’t deal with end of line characters (EOFs) in an ideal way. So, if you’re gonna append more than one line, do it with printf: printf “some data for the file\nAnd a new line” >> fileName The >> and > operators are … Read more

Escape dollar sign in string by shell script

As you know, a dollar sign marks a variable. You have to take it into account when you are typing it. You can escape the dollar ./dd.sh “sample\$name.mp4” or just type it with single quotes ./dd.sh ‘sample$name.mp4’ To check if there is a dollar sign in a variable, do [[ $variable == *\$* ]] && … Read more