Linux Shell Introduction
Command Anatomy
command | [option] | arguement |
---|---|---|
binary | how to run | what to run against |
ls |
||
ls |
-l |
|
ls |
-lah |
/etc |
- Command - program being run
- Option - how to operate ( dash and letter, stacking, --longer-options )
- Argument - what to operate on (like a filepath)
Key Differences
There are some important differences to note when coming from a Windows environment:
-
Everything is a file
- Ordinary Files
- Directories
- Special Files - hard / soft links etc.
-
CaSe sEnSiTiVe!
- "logfile.txt" is not the same as "Logfile.txt"
-
/// FORWARD /// slashes
- backslashes are used, but a more advanced topic
-
File extensions don't matter
- not required, but best practice to use
File System
/bin binaries (points to /usr/bin)
/sbin admin binaries programs
/dev external devices are mounted (optical / hdd / ssd )
/etc system and application configuration files
elasticsearch/
kibana/
logstash/
/home place for all user profile ~
/lib libraries of code
/tmp temporary "permissions free" working space
/var various files system uses
/var/log logged events
/usr/ user apps / tools / libraries
/opt optional binaries
Absolute and Relative Paths
There are two types of filepaths when working in the terminal:
-
Absolute
- full path starting at root ( / )
- path that always begins at / (root) i.e. very “top” of filesystem
- bottom line: if it starts with a “ / “ it’s an absolute file path
- example:
/home/user/Documents/my-project
-
Relative
- relative to your current location in file system
- example:
./Documents/my-project
Getting Help
Let's talk about how to help yourself. Here are some basic commands to get your bearings and help answer the basic questions of terminal life:
Surroundings
whoami
- print the current user id and namehostname
- print or change system hostnamedate
- display or change date and timeuname
- print general system informationcat /etc/*-release
- print out OS informationwhich
- Search user $PATH for program
Man Pages (RTFM)
The man
pages are built-in documentation and user manual. Your box is packed full of them, so the trick
is that it just takes patience and being able to search for what your looking for.
Let's look at an example workflow to get more information on how to use your current bash
shell session:
man bash
- opens the paginated manual<spacebar>
- jump to next pagef / b
- forward / backu / d
- up / down/<search_string>
- search for a keywordn
(ext) /shift + n
- forward and backq
- quit