AGENDA¶
- Installing programs
- Streams, Pipes & Redirects
- Essential tools:
grep,find,sed tmuxbasicsneovimintroduction- Mini exercises
- New kids on the block:
rg,fd
Installing programs¶
- Requires super-user permissions
- Either use
suorsudo - Password for super-user:
root66
sudo su ... get super-user shell (student password)
apt-get update ... updates the package list
apt-get install <name> ... installs a package
Streams in Linux¶
Everything is a file/stream under Linux.
- stdin (0) → input (keyboard)
- stdout (1) → normal output (terminal)
- stderr (2) → error output (terminal)
- Redirection:
command > file # stdout to file (overwrite)
command >> file # append stdout to file
command < file # use file as input
Default: ls prints the directory listing to stdout by default!
Pipes¶
Streams can be forwarded to other programs. stdout gets stdin for the other
- Combine commands using
|
ls -l | grep ".cpp"
ps aux | grep firefox
Mini-Exercises¶
cat ... without arguments (what happens?)
cat > test.txt ... use Control-D
ls /notfound > out.txt 2> err.txt
Tool: grep¶
- Search for text patterns in files
grep main "*.cpp"
grep -i "error" /var/log/syslog
Tool: find¶
- Search for files by name, type, size
find . -name "*.cpp"
find /etc -type f -size +1M
Tool: sed¶
- Stream editor for search/replace
sed 's/foo/bar/g' file.txt
Mini-Exercises¶
Exercise 1¶
- Redirect the output of
ls -linto a file calledlisting.txt - Append a second listing to the same file
- Use
grepto search for.txtentries
Mini-Exercise 2¶
- Use
findto locate all.logfiles in/var/log - Replace the word "TODO" with "DONE" in a test file using
sed
tmux Basics¶
- Terminal multiplexer
- Keep sessions running in background
tmux detach- Key bindings (default prefix:
Ctrl-b): %split vertically"split horizontallyoswitch paneddetach session- Reattach:
tmux attach
neovim Introduction¶
- Modal editor (Normal, Insert, Command modes)
- Basic commands:
i→ insert modeEsc→ back to normal mode:wq→ save and quit/pattern→ searchdddelete lineyyyank (copy),ppasteuundo
Mini-Exercises¶
Exercise 3¶
- Open a tmux session
- Split the screen into two panes
- In the left pane, open a file with
nvim - In the right pane, run
ls -landgrep
Other Shell Commands¶
export # sets an environment variable
echo $PATH # print an environment variable
./<cmd> # executes an application in the current dir
chmod # change file attributes
New kids on the block¶
ripgrep¶
ripgrep recursively searches directories for a regex pattern while respecting your gitignore. A fast replacement for grep.
apt-get install ripgrep
fdfind¶
A simple, fast and user-friendly alternative to find
apt-get install fd-find
Survival Package (Tools & Workflow)¶
- Pipes and redirection:
|,>,>> greporripgrep,findorfdfind,sedtmux: sessions, splits, detach/attachneovim: insert, save, quit, navigation, search, undo
Wrap-Up¶
- Learned how to combine commands with pipes
- Practiced essential search & replace tools
- Worked with tmux splits
- Got comfortable editing in neovim
Resources¶
Next Session¶
- Configuration management
- Git basics