Command Line Tutorial

The command line, accessed through the terminal, is a powerful tool for software development. It allows you to interact directly with your operating system using text commands, bypassing the graphical user interface (GUI). This provides a more efficient and flexible way to perform many tasks. Developers use the command line for various activities like:

  • Project Management: Navigating directories, organizing files, and automating repetitive tasks become streamlined with commands.
  • Version Control: Tools like Git, essential for code versioning, are primarily accessed and managed through the command line.
  • Building and Testing: Running build scripts to compile code or launching automated tests often involves command-line commands.
  • Package Management: Installing and managing software libraries and dependencies frequently relies on command-line tools.

While modern IDEs (Integrated Development Environments) such as VS Code offer graphical interfaces for some of these tasks, the command line remains a cornerstone of software development due to its efficiency, automation potential, and deep system access.

Among developers and engineers, the top 3 terminal programs for daily use are likely iTerm2 (Mac), oh-my-zsh (customizable shell for various OS), and Terminal.app (built-in on macOS, basic but functional).

Here are some essential terminal commands every software engineer should know, categorized for easy reference:

  • pwd: Print working directory – Show the full path of your current location.
  • cd [directory/folder]: Change directory – Navigate to different folders in your file system.
  • cd ~: Home directory – Navigate to the home directory in your file system.
  • cd /: Root of drive – Navigate to root of drive (instead of user with cd ~).
  • cd -: Previous directory – Navigate to last directory accessed in terminal.
  • cd ..: Parent directory – Navigate to parent directory of current directory.
  • ls: List directory contents – View files and folders within the current directory.
  • ls -l: Long listing – Provides detailed information about files and directories in the current location. This includes file permissions, owner, group, size, date modified, and filename.
  • ls -a: Listing including hidden files – Shows all files and directories in the current location, including hidden ones (files or folders starting with a dot “.”). By default, hidden files are not displayed with the basic ls command.
  • ls -lh: Long listing with human-readable file sizes – Displays a long listing like ls -l, but with file sizes presented in a more user-friendly format (e.g., KB, MB, GB) instead of bytes.
  • ls -R: Entire content of folder recursively – Lists all files and directories within the current folder and all its subfolders, nested directories, and their contents. This provides a comprehensive view of the entire folder structure.
  • touch: Create an empty file – Creates a new file with the specified name. Useful for creating placeholder files or initiating file tracking in version control systems.
  • cp: Copy files – Copy a file from one location to another.
  • mv: Move files – Rename or move a file from one location to another.
  • mkdir [directory name]: Make directory – Create a new directory (folder).
  • rm [file name]: Remove file – Delete a file from directory (use with caution!).
  • rm -r [directory name]: Remove directory (force) – Delete a directory and its contents (use with caution – doesn’t go to trash!).
  • rmdir [directory name]: Remove empty directory – Delete an empty directory.
  • chmod: Change file permissions – Modify access rights for users, groups, and others on a file or directory.
  • chown: Change file ownership – Transfer ownership of a file or directory to a different user.
  • cat: Concatenate files – Display the contents of one or more files on the terminal.
  • grep: Search text – Find specific lines within a file based on a pattern.
  • head: Display head (beginning) of a file – Show the first few lines of a file.
  • tail: Display tail (end) of a file – Show the last few lines of a file.
  • sort: Sort lines of a file – Organize lines of text alphabetically or numerically.

Permissions:

  • sudo: Run a command with superuser privileges – Execute commands requiring administrative access.

Opening Files:

  • open [file]: Opens a file in the default application.

Process Management:

  • top: Display active processes – List currently running processes on your system.

Editors:

  • nano [file]: Open a file for editing in the nano text editor.
  • vim [file]: Open a file for editing in the vim text editor.

Screen:

  • clear: Clear screen – Clear the terminal window.
  • reset: Reset terminal display – Restore the terminal to its default settings.

Clipboard Interaction:

  • pbcopy < [file]: Copy the contents of a file to the clipboard.
  • pbpaste: Paste the contents of the clipboard to the terminal.
  • pbpaste > [file]: Paste the contents of the clipboard into a new file.

System Information:

  • uname: Print system information – Get details about the operating system kernel name, version, and release.
  • free: Show free memory – Display information about available and used memory (RAM) on your system.
  • df: Show disk space usage – View free and used disk space on your system’s partitions.
  • ps: Show process status – List currently running processes on your system.

Package Management:

  • apt-get (Debian/Ubuntu) – Install, remove, and update packages on Debian-based systems.
  • yum (Red Hat/CentOS) – Install, remove, and update packages on Red Hat-based systems.
  • npm (Node.js) – Manage Node.js packages.
  • pip (Python) – Manage Python packages.

Bonus:

  • man <command>: Manual page – Access detailed help documentation for a specific terminal command. Use “q” key to quit.
  • history (then hit enter): Show command history – View a list of previously executed commands in your terminal session. You can use the UP/DOWN arrow keys to navigate through this list and re-run commands by pressing Enter.
  • TAB key: Autocomplete what you’re typing – As you start typing a command or file name, press the TAB key to get suggestions for completion. This can save you time and reduce typos.
  • If a directory you want to access has a space in it, such as the folder name “one two three”, you can access the directory by adding back slashes before the spaces: “one\ two\ three”.
YouTube player
YouTube player

Remember, this is not an exhaustive list, but it provides a solid foundation for navigating the terminal and performing essential tasks. As you progress in your software engineering journey, you’ll encounter more specific commands relevant to your development environment and tools. Check out this Github page for a more extensive command list.

YouTube player

The iTerm 2 customization tutorial above is dependent on Neovim, Curl , and ohmyzsh which can both be installed with Homebrew. The font’s used in the iTerm 2 customizations are from NerdFonts.com. The zsh theme used is Power Level 10k with zsh syntax highlighting and zsh autosuggestions.

YouTube player
YouTube player