Bash System¶
These functions interact with the operating system, and help improve the user experience.
opal:bak¶
Create a backup of a file or directory
# Create filename.txt filename.txt.bak
$ opal:bak filename.txt
# Create a backup of the wordpress directory.
# wordpress.tar.gz gets created.
$ opal:bak wordpress
opal:extract¶
“un-compress” a file from a variety of common formats.
There are multiple supported file types: .tar.bz2, .tar.gz,
.bz2, .rar, .gz, .tar, .tbz2, .tgz, .zip,
.Z, and .7z. The actual support is based on the commands that
you have installed.
#
$ opal:extract wordpress.tar.gz
# Display lines 100 through 140.
$ opal:numseg error.log 100 140
opal:numseg¶
Display a numbered segment of a file
When only the start_line is specified, a range of 10 lines before and after that line will be numbered and displayed. when start_line and end_line are specified, those lines and all those between will be numbered and displayed. This is great for displaying a small section of a file, so one can discuss a section of text or code without being tied to your editor.
Example:
# Display lines 90 - 110. Line 100 is the middle line of content
$ opal:numseg error.log 100
# Display lines 100 through 140.
$ opal:numseg error.log 100 140
opal:seg¶
Display a segment of a file
When only the start_line is specified, a range of 10 lines before and after that line will be displayed. When both $start and $end are specified, those lines and all those between will be displayed
# Display lines 90 - 110. Line 100 is the middle line of content
$ opal:seg error.log 100
# Display lines 100 through 140.
$ opal:seg error.log 100 140
opal:locate¶
Display the file path and line number where the function is defined.
Discover where you’ve defined a bash function.
# Learn where the opal:today function is defined.
$ opal:locate opal:today
opal:describe¶
Display the definition of a function.
# Learn where the opal:today function is defined.
$ opal:describe opal:today
opal:show¶
A wrapper around the declare command. Display all data of a specified type.
# Display a list of all bash functions
$ opal:show names
opal:swap¶
Change the contents of two files
This is useful when testing two different versions of a file, and the filename is signicant to its operation. A config file is a good example.
# Learn where the opal:today function is defined.
$ opal:swap file1.txt file2.txt
opal:touchx¶
Make it easy and fast to create a file of a defined type
Inspired by the touch command which creates an empty file. This helps create files with default content.
# Create a Git Keep file and make it executable.
$ opal:touchx .gitkeep
# Create a PHPinfo file file and make it executable.
$ opal:touchx info.php phpinfo
opal:truncate¶
Remove the contents of a file without deleting the file.
There are times when you want the file to remain, but only clear out the contents. This is useful when dealing with large log files taking up too much space.
# Remove the contents of a large file.
$ opal:truncate error.log