# Essential CLI Tools and Navigation
- `id user_name` to show user's UID and GIDs ![[images/Pasted image 20250807181401.png]]
- `whoami` shows just current user![[images/Pasted image 20250729193410.png]]
- `who` shows more info than above ![[images/Pasted image 20250729193431.png]]
- `w` shows all recent users with more detail ![[images/Pasted image 20250729193530.png]]
- `hostname` shows name assigned to the machine ![[images/Pasted image 20250729193624.png]]
- `uname -a` shows detailed info about machine's HW, name, kernel ![[images/Pasted image 20250729193656.png]]
- `pwd` shows present working directory
- `cd` changes directory
- `ls` lists content of current directory
- `ls -al` shows all files including hidden ones in long listing format (detailed view)
- -h for human readable view
- -i for inode info
- -Z for security context
- -A to exclude implied directories `.` and `..`
- `mv source dest` moves a file/directory
- `touch` creates a file or updates last modified for existing file
- `cp source dest` copies a file/directory
- `mkdir` creates a directory
- `rm -rf directory` recursively deletes contents of a directory
- -r for recursive
- -f for force
- -v for verbose
- -i for interactive prompting
- `set -o noclobber` to prompt for overwriting files
- this is a temporary change to make permamnent add `set -o noclobber` to `~/.bashrc`
- `which command` to show location for command ![[images/Pasted image 20250802205619.png]]
- `grep` to search specific string
- `egrep` for regex support same as `grep -e`
- `pgrep` for globbing support
- `command | tee file_name` to move output to file and also show on `stdout`
- `file file_path` shows file type ![[images/Pasted image 20250801183744.png]]
- `stat file_path` shows details for file ![[images/Pasted image 20250801183731.png]]
- `cat` shows file contents
- `less` or `more` to page through output
- `head` or `tail` shows first or last 10 lines or a file
- `find search_space_path tests expression` searches path based on expression
- useful `find` test options
| Find Test Options | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `-name` | search for files by name |
| `-iname` | case insensitive version of above |
| `-type` | f for files, d for directories |
| `-user` | find files owned by specified user |
| `-perm` | find files with perms specified based on octal notation (e.g., 4000 for SUID, 2000 for SGID, 555 for rx files, 777 for rwx files) |
| `-size` | find files with specified size (e.g, `-size +50M` for files over 50MB) |
| `-mtime` | find files modified within X days |
| `-exec` | execute command on found files |
- `locate options keywords` to locate file and show path
- faster than `find` command because searches against default db in `var/lib/mlocate/mlocate.db
- `sudo install -y mlocate` to install `locate` functionality
- `sudo updatedb` to update db
- common options
- -i for case insensitive
- `-d new_db` to specify different db to search against
- -b to match against base name
- -w to match against whole name
- -r for regex support
- -n to specific number of results shown
- -c to show count of matching results
- command history
- `history` ![[images/Pasted image 20250822193252.png]]
- `cat ~/.bash_history` ![[images/Pasted image 20250822193238.png]]
- reboot system
- `sudo reboot`
- `sudo init 6`
- shutdown system
- `sudo shutdown`
- `sudo init 0`
# text editors
- `nano`
- `vim`
- start in command mode
- type colon
- `wq!` to force write-quit
- press `i` to enter insert mode
- escape to re-enter command mode