Get only regex matches from grep in Linux console

To get only the matches from a regex in grep use the option o.

example.txt

Get every number that is after $$b

 

Important: No regex grouping like ‘(\$\$b.*)’ is permitted.

Rename multiple files with prefix or suffix in Linux console

Add a suffix

Exmpale to add an underscore “_” at the end each text file:

Add a prefix

Exmpale to add an underscore “_” in front of text each file name:

[alert type=”info”]Make sure you run those commands in Bash shell.[/alert]

Alternative: Add suffix with find command

Exmpale to add an underscore “_” at the end each text file:

Alternative: Add prefix with find command

Exmpale to add an underscore “_” in front of text each file name:

[alert type=”info”]This will run in any shell and you can easily define the set of files that should be renamed by using the name or iname parameter for find.[/alert]

Watch file system changes for a directory in Linux console

Sometimes it is very useful to see how content of a directoy changes; If you have a cron that writes into a directoy.

Updates ls content of current directory every second

Highlights updates of ls of current directoy every 5 seconds

Iterating over an array in Bash

Iterating over an array in Java

compress and umcompress with tar

#uncompress tar.gz

#uncompress tar.gz into folder

#uncompress bzip2 file

#compress to tar.gz

#compress to bzip2