Skip to main content
added 8 characters in body
Source Link
X Tian
  • 10.7k
  • 3
  • 35
  • 51

Generic pattern

As you can see from the answers, the generic pattern is

[Produce a set of file names to work on] | [read each name and run actionCommand]

actionCommand performs the desired action eg mv and generally takes two paramteres original file name and new file name.

producing filename

find is generally used.

To handle filenames with unusual characters the -print0 is used to terminate each string printed with the null character. However the reading sid of the pipe also needs to cooperate and read characters until null is read instead of terminating prematurely after a space.

reading each filename

Some commands can take a -0 option to handle the reading side of a null terminated character string.

The command xargs was designed for this purpose

bash has read -d\0

actionCommand

A general form cmd p1 p2 example mv oldfilename newfilename

producing the new filename

The new filename is usually derived from the original filename.

It can be as simple as appendingaappending a string, eg $oldname.New tr is good for simple translation of characters sed power editiding of filenames

  • tr is good for simple translation of characters
  • sed power editing of filenames

bash command substition

Example $( tr "{}" _ <<< $oldname )

command output substitution $( ) command that is run tr "{}" _ with input read from variable $oldname

Generic pattern

As you can see from the answers, the generic pattern is

[Produce a set of file names to work on] | [read each name and run actionCommand]

actionCommand performs the desired action eg mv and generally takes two paramteres original file name and new file name.

producing filename

find is generally used.

To handle filenames with unusual characters the -print0 is used to terminate each string printed with the null character. However the reading sid of the pipe also needs to cooperate and read characters until null is read instead of terminating prematurely after a space.

reading each filename

Some commands can take a -0 option to handle the reading side of a null terminated character string.

The command xargs was designed for this purpose

bash has read -d\0

actionCommand

A general form cmd p1 p2 example mv oldfilename newfilename

producing the new filename

The new filename is usually derived from the original filename.

It can be as simple as appendinga string, eg $oldname.New tr is good for simple translation of characters sed power editiding of filenames

bash command substition

Example $( tr "{}" _ <<< $oldname )

command output substitution $( ) command that is run tr "{}" _ with input read from variable $oldname

Generic pattern

As you can see from the answers, the generic pattern is

[Produce a set of file names to work on] | [read each name and run actionCommand]

actionCommand performs the desired action eg mv and generally takes two paramteres original file name and new file name.

producing filename

find is generally used.

To handle filenames with unusual characters the -print0 is used to terminate each string printed with the null character. However the reading sid of the pipe also needs to cooperate and read characters until null is read instead of terminating prematurely after a space.

reading each filename

Some commands can take a -0 option to handle the reading side of a null terminated character string.

The command xargs was designed for this purpose

bash has read -d\0

actionCommand

A general form cmd p1 p2 example mv oldfilename newfilename

producing the new filename

The new filename is usually derived from the original filename.

It can be as simple as appending a string, eg $oldname.New

  • tr is good for simple translation of characters
  • sed power editing of filenames

bash command substition

Example $( tr "{}" _ <<< $oldname )

command output substitution $( ) command that is run tr "{}" _ with input read from variable $oldname

Source Link
X Tian
  • 10.7k
  • 3
  • 35
  • 51

Generic pattern

As you can see from the answers, the generic pattern is

[Produce a set of file names to work on] | [read each name and run actionCommand]

actionCommand performs the desired action eg mv and generally takes two paramteres original file name and new file name.

producing filename

find is generally used.

To handle filenames with unusual characters the -print0 is used to terminate each string printed with the null character. However the reading sid of the pipe also needs to cooperate and read characters until null is read instead of terminating prematurely after a space.

reading each filename

Some commands can take a -0 option to handle the reading side of a null terminated character string.

The command xargs was designed for this purpose

bash has read -d\0

actionCommand

A general form cmd p1 p2 example mv oldfilename newfilename

producing the new filename

The new filename is usually derived from the original filename.

It can be as simple as appendinga string, eg $oldname.New tr is good for simple translation of characters sed power editiding of filenames

bash command substition

Example $( tr "{}" _ <<< $oldname )

command output substitution $( ) command that is run tr "{}" _ with input read from variable $oldname

Post Made Community Wiki by X Tian