^
https://unix.stackexchange.com is indeed your friend.
I <B the many alternatives that are given in
https://unix.stackexchange.com/question ... mmand-line and also this
I always use $ less "your file here" , as it is very simple, provides a built in interactive grep command, and gives you an easy to use interface that you can scroll with the arrow keys.
(highlighting by me) - these are my precise reasons for using
less that often.
Since I have lots of aliases and functions, I have them in their own file:
Code: Select all
guest@rava:~$ /bin/ls -o --time-style=long-iso /usr/local/bin/aliasset | cut -c 19-$(expr 18 + $(tput cols))
10619 2023-10-20 11:33 /usr/local/bin/aliasset
As you can see, currently it holds 37 aliases and 15 functions:
Code: Select all
guest@rava:~$ grep "^alias " /usr/local/bin/aliasset|wc
37 168 1882
guest@rava:~$ grep "^function " /usr/local/bin/aliasset|wc
15 237 1703
The "^" is a special character meaning "beginning of a line" (while "$" would be the special character meaning "end of a line")
More precise it means "start / end of the string" but in this case, that is also "start / end of a line"
And it is auto-loaded for guest and root via this snippet in their respective .bashrc :
Code: Select all
guest@rava:~$ grep aliasset .bash*
.bashrc:. /usr/local/bin/aliasset
(Since I do not check if /usr/local/bin/aliasset is available that would produce an error if its not available; but on all of my systems that's not an issue
since I use aliasset longer than Porteus exists. Currently its version is "V3.6.47 (2023-10-20)")
And out of security-reasons, aliasset is readable by guest, but only writeable by root:
Code: Select all
guest@rava:/usr/local/bin$ ls -l aliasset
-rw-r--r-- 1 root root 10619 2023-10-20 11:33 aliasset
Having the aliases and functions in their own external file has one more advantage: when I created a new alias or a new function and added it to an updated aliasset, I can load that into one already running terminal via a simple
Code: Select all
guest@rava:~$ . /usr/local/bin/aliasset
Typed that is a mere
. /u[TAB]
lo[TAB]
b[TAB]
ali[TAB]
And when there would be some error or syntax error in the newest created /usr/local/bin/aliasset - executing
. /usr/local/bin/aliasset would only give an error on that one terminal, and in the worst case scenario would only mess up that one terminal. Then I repair the coding error in /usr/local/bin/aliasset or revert it to its previous version, and all is good. The other already running terminals or virtual terminals are not affected.
────────────────────────────────────────────────────────────────────────
More on special characters and regex in general I collected in my help.regex help script:
Code: Select all
guest@rava:~$ help.regex
help.regex V0.1
Character classes
. any character except newline
\w \d \s word, digit, whitespace
\W \D \S not word, digit, whitespace
[abc] any of a, b, or c
[^abc] not a, b, or c
[a-g] character between range from a to g
Anchors
^abc$ start / end of the string
\b \B word, not-word boundary
Escaped characters
\. \* \\ escaped special characters
\t \n \r tab, linefeed, carriage return
\u00A9 unicode escaped (c)
Groups & Lookaround
(abc) capture group
\1 backreference to group #1
(?:abc) non-capturing group
(?=abc) positive lookahead
(?!abc) negative lookahead
Quantifiers & Alternation
a* a+ a? 0 or more, 1 or more, 0 or 1
a{5} a{2,} exactly five, two or more
a{1,3} between one & three
a+? a{2,}? match as few as possible
ab|cd match ab or cd
(The original help.regex makes coloured output but that cannot be displayed using [
code
] )
HTH.