Skip to main content

Command Palette

Search for a command to run...

Essential Linux Commands: whoami, sudo apt, id, pwd, ls, cd ~ (20-Min Cheat Sheet)

Updated
3 min readView as Markdown
Essential Linux Commands: whoami, sudo apt, id, pwd, ls, cd ~ (20-Min Cheat Sheet)

Meta Description: Master Linux basics—whoami, sudo apt update/install, id, pwd, ls ~, echo ~, cd ~ home shortcut—with examples. 20-min guide for devs navigating terminals fast.phoenixnap+1

Linux File System Basics

Linux uses a tree-like hierarchy from root / with user files in /home.cherryservers
Commands below help identify users, update software, and navigate directories efficiently.

whoami: Check Current User

whoami prints your effective username.
Example: whoamilabex.phoenixnap
Use in scripts: if [[ $(whoami) != root ]]; then echo "Run as root"; fi.ioflood

sudo: Run as Superuser

sudo executes commands with root privileges (needs password).
Example: sudo ls /root accesses protected files.phoenixnap
Essential for system changes.

apt update: Refresh Package Lists

sudo apt update fetches latest software indexes from repositories.
Example: sudo apt update → "Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease".packagecloud+1
Run before installs for fresh data.

apt install: Add Software

sudo apt install <package> downloads and installs programs.
Example: sudo apt install vim → installs Vim editor.geeksforgeeks
Note: "hojo" isn't standard—likely typo, no package found.

id: User & Group Info

id shows UID, GID, and groups.
Example: iduid=1000(labex) gid=1000(labex) groups=1000(labex),27(sudo).phoenixnap

pwd: Current Directory Path

pwd prints full working directory.
Example: pwd/home/labex/project.cherryservers

ls: List Directory Contents

ls shows files/folders in current dir.
Example: lsfile1.txt project.cherryservers

ls ~ vs echo ~: Key Difference

ls ~ lists home dir contents (e.g., Documents Downloads).cherryservers
echo ~ prints home path (e.g., /home/labex)—no listing.earthly
~ expands to $HOME; ls scans it, echo just outputs.

cd ~: Home Directory Shortcut

cd ~ jumps to home dir (tilde = shortcut for /home/<user>).
Example: Anywhere → cd ~pwd shows /home/labex.cherryservers
Also: plain cd does the same.

Command Purpose Example Output
whoami Current user labex phoenixnap
sudo apt update Refresh packages Package lists updated phoenixnap
sudo apt install vim Install software Vim installed geeksforgeeks
id User IDs uid=1000(labex) phoenixnap
pwd Current path /home/labex cherryservers
ls List files Documents project cherryservers
ls ~ Home contents Downloads Music cherryservers
echo ~ Home path /home/labex earthly
cd ~ Go home Changes to /home/labex cherryservers

Practice Tip: Terminal open? Run sequentially—master in 20 minssecond-pocket-shoot-73.hashnode

  1. https://phoenixnap.com/kb/whoami-linux

  2. https://cyberpanel.net/blog/whoami-linux-command

  3. https://operavps.com/docs/whoami-command-linux/

  4. https://ioflood.com/blog/whoami-linux-command/

  5. https://congdonglinux.com/whoami-linux-command-with-examples/

  6. https://linuxize.com/post/whoami-command-in-linux/

  7. https://www.geeksforgeeks.org/linux-unix/whoami-command-linux-example/

  8. https://labex.io/tutorials/linux-linux-whoami-command-with-practical-examples-423009

  9. https://www.howtoforge.com/linux-which-whoami-command/

  10. https://blog.robertelder.org/intro-to-whoami-command/

  11. https://second-pocket-shoot-73.hashnode.dev/seo-handbook

  12. https://www.cherryservers.com/blog/a-complete-guide-to-understanding-linux-file-system-tree

  13. https://phoenixnap.com/kb/sudo-apt-update

  14. https://blog.packagecloud.io/you-need-apt-get-update-and-apt-get-upgrade/

  15. https://www.geeksforgeeks.org/linux-unix/apt-command-in-linux-with-examples/

  16. https://earthly.dev/blog/practical-guide-to-linux-echo-cmd/

More from this blog

A

Aakib'z Studio

127 posts

I share practical insights on powerful development frameworks, focusing on Next.js for modern web apps and Flutter for efficient cross-platform mobile app development.