Administering Networking OS — Command Lines #4
College Online Material
Published in
2 min readMar 16, 2021
CLI or Basic Shell
The CLI
- Text-based interface
- Access via a terminal (GUI and Virtual)
- Commands passed to a shell
- Shell prompt (sysadmin@localhost/~)
Shell Features
- Command history — the ability to re-execute previous commands quickly
- Scripting — create programs by placing the command
- Alias — create a shortcut to longer commands
- Variables — store info that can be used to modify the functionality of the shell or commands
Understanding Command Structure
Command Format
- Basic format
command [options] [arguments]
Option change the behavior of commands
Arguments are used to provide addition info for a command
Command Options
- Vary based on command
- Older option formate:
-a
-abc = -a -b -c$ls -al
- Newer (GNU) option format: — all
Command History
- View the previous command:
history
- Bring up the previous command
up arrow
- Modify previous commands:
left right
- Execute a previous command: !<num>
Variables
Shell Variables
- Use to store the sys. info
- View with the
echo
command
$ echo $HISTSIZE
- Modify
$ HISTSIZE = 500
- Place command in ~/.bashrc to make permanent
Path Variable
- Determines where command are execute
$ echo $PATH
/c/Users/User Account/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/
Command Path
Find Command
- Hard to determine where a command is located
- Instead of searching directories in the PATH variable manually, use the which command
$ which cal
/usr/bin/cal$ which date
/usr/bin/date
Additional Command Structure
Globbing
- used to match sets of files in a dir.
*
match zero or more of any char.?
match exactly one of any char.[]
match exactly one of a set of char.
$ touch a.txt && touch ab.txt && touch abc.txt
$ ls a*
a.txt ab.txt abc.txt$ ls *txt?
Quoting
- Double quotes
“
— used to disable the meaning of some metachar. like globbing - Single quotes
‘
— used to disable the meaning of all metachar.
can use \ to disable next char. only
$ echo "$SHELL"
$ echo '$SHELL'
Control Statement
- The
;
char.— used to separate commands on a CLI - The
&&
char. — used to execute the second command if the first command succeds - The
||
char. — used to execute the second command if the first command fails
$ sudo apt-get update && sudo apt-get upgrade -y
$ ls > count.txt; wc-l