- Eg.
echo "Today is $(date) and I am $(whoami)
-
date
andwhoami
are both commands
-
- Using double quotes for arguments
- echo Today is
$(date) and I am $ (whoami)
- This is multiple arguments but they still all get printed
- echo "Today is
$(date) and I am $ (whoami)"
- Single arg
- echo 'Today is $(date)'
- Output: Today is $(date)
- Single quotes will suppress embedded commands
- echo
date
- It will print the date.
date
is treated as a command and is evaluated - Older syntax, won't be used much
- echo Today is
man grep
- tool: egrep (grep -E)
- print every line in files provided as args that contain the regex pattern
- Match zero or one of the precending identifier
- To match
cs246
andcs 246
cs ?246
- To match
cs246
and246
(cs)?246
- To match
- Match zero or more of the preceding identifier
*
- Not the same as globbing wildcard
(cs)*246
- Match
cs246
cscs246
246
- Match
- Match any character (only a single char)
.
- To match any number of anything
.*
- To search for special identifiers you can escape with
\
\(\)
will match()
- Match one or more occurences
+
sc+
will matchsc
sccc
sccccc
but nots
- Match the start of the line
^
^tobe
will matchtobesssss
but notsssstobe
- Match end of the line
$
-
tobe$
will matchddddddtobe$
but notdddtobeddd
-
^tobe$
will matchtobe
but notdddtobeddd
grep searchtext myfile.txt
- Search for
searchtext
in myfile.txt
grep "searchtext|Searchtext" myfile.txt
- Or
grep "(s|S)earchtext" myfile.txt
- Search for
searchtext
orSearchtext
in myfile.txt
grep "[sS]earchtext" mufile.txt
- Same as above,
[]
mean to match any char between them [^sS]
means to match nots
and notS
grep -i "searchtext" myfile.txt
- Same as above, but
-i
forces case-insensitivity
- Print all words from /usr/share/dict/words that start with an e and consist of 5 characters
egrep "^e.{4}$" /usr/share/dict/words
egrep "^e....$" /usr/share/dict/words
- Lines of even length
egrep "^(..)*$" /usr/share/dict/words
- Filenames from cur directory whose name contains exactly one
a
ls | egrep "^[^a]*a[^a]*$"
ls -l
- long listing- Eg.
-rw-r--r-- 1 rethy staff 2433 Sep 13 15:29 sept_13.md -rw-r--r-- 1 rethy staff 1351 Sep 9 15:37 sept_6.md
- see below - shortcut - owner - group - size - date last modified - filename
-rw-r--r--
- first bit - type of file - ordinary or directory (
-
for ordinary file,d
for directory) - Nine following bits of three bits each (owner bits - single owner, group bits - all users that belong to the same group to which the file belongs, other bits - all other users not in group)
- r (read) w (write) x (execute)
- first bit - type of file - ordinary or directory (
- Ordinary files
r
read the file, cat the filew
modify the contentsx
can execute the program
- Directories
r
ls, tab completionw
add/remove filesx
can search the directory, enter it, navigate into it
chmod {mode} {file}+
- Add or remove mode to file
u
(owner)g
(group)o
(other)a
(all three)chmod a+x {file}+
- add executable permission for everyonechmod u-rw {file}+
- remove read/write permission from ownerchmod u= {file}+
- remove all permissions from owner (still has permission to re-add these permissions)