Apple

macOS Command Line Basics Part 3: Essential Commands

1. Manual and Help Commands man - The Manual Command The Swiss Army knife of Terminal help. Access comprehensive documentation for any command: man ls     # View manual for ls command…

6 min read TexArxs

1. Manual and Help Commands

man – The Manual Command

The Swiss Army knife of Terminal help. Access comprehensive documentation for any command:

man ls     # View manual for ls command

man -k ssh  # Search manuals containing “ssh”

man ditto

man cp


Tips: Use man command to learn more about each command and its attributes.

apropos – Search Command Descriptions

Find commands related to specific keywords:

apropos “copy”  # Find commands related to copying

apropos -s 1 directory  # Search only section 1 manuals


whereis – Locate command source

Get a command location

whereis python  # Find Python locations

whereis ls


2. Navigation Commands

cd – Change Directory

Navigate through your file system:

cd Documents          # Move to Documents folder

cd ..                 # Move up one directory

cd ~                  # Go to home directory

cd /Users/username    # Absolute path navigation

cd –                  # Return to previous directory


pwd – Print Working Directory

Display your current location:

pwd               # Show full path

pwd -P            # Resolve symbolic links


3. File and Directory Operations

ls – List Directory Contents

Reveal files and folders with multiple display options.

ls              # Basic listing

ls -l          # Detailed list view

ls -a         # Show hidden files

ls -lh        # Detailed view with human-readable sizes

ls -R        # Recursive directory listing

ls -lS       #Detailed list view sort by size

ls -lt.       #List the files sorted by time modified (most recent first)


open – Open Files and Applications

Launch files with their default applications:

open file.pdf           # Open PDF in default app

open -a “Chrome”        # Open specific application

open .                  # Open current directory in Finder


cp – Copy Files and Directories

Copy files and directories:

cp file.txt backup.txt      # Simple file copy

cp -R folder/ backup/       # Recursive directory copy

cp -i file1 file2           # Interactive copy with confirmation


ditto – Enhanced Copy

A more powerful copying tool unique to macOS. It can preserve mode, access time, permissions and all other attributes. It can also create and extract archives

ditto source_folder destination_folder  # Preserve attributes

ditto -V source destination             # Verbose copy


mv – Move or Rename

Move files or rename them:

mv old.txt new.txt         # Rename file

mv file.txt ~/Documents/   # Move file

mv -i file1 file2          # Interactive move


touch – Create Empty Files

Create new empty files or update timestamps:

touch newfile.txt          # Create empty file

touch -a file.txt          # Update access time

touch -m file.txt          # Update modification timemkdir – Make Directory


mkdir – Create Directories

Create new directories:

mkdir newfolder                 # Create single directory

mkdir -p path/to/folder     # Create nested directories

mkdir -m 755 folder          # Create with specific permissions


rm – Remove Directory

The rm utility attempts to remove the non-directory type files specified on the command line.

rm.                  #Delete a file (This deletes the file permanently; use it with caution.)

rm -R  <dir>   #Delete a folder and its contents

rm -f <file>     #Force removal without confirmation

rm <file1> <file2> <file3>  #Delete multiple files without any confirmation

Delete empty directories:

rmdir emptyfolder # Remove empty directory


4. Utility Commands

echo – Print to Terminal

Display text or variable values:

echo “Hello, World!”       # Print text

echo $PATH                 # Display environment variable

echo $HOME                 # Show home directory path

exit – Close Terminal

Terminate the current Terminal session:

exit # Close Terminal window


🚀Pro Tips for Terminal Mastery

  1. Use Tab completion to quickly fill file and directory names
  2. !! repeats the last command
  3. Control + R searches command history
  4. Combine commands with && to run sequentially
  5. Use Command + K to clear the Terminal screen

Recommended Learning Path

  1. Practice each command in a safe environment
  2. Create aliases for frequently used commands
  3. Explore advanced options with man command
  4. Integrate commands into your daily workflow
  5. Experiment with command combinations


Conclusion

These fundamental Terminal commands form the backbone of command-line operations on macOS. While graphical interfaces are convenient, mastering these commands will significantly boost your productivity as a developer.

Remember: Practice makes perfect. Try incorporating these commands into your daily workflow, and you’ll be navigating the Terminal like a pro in no time.

#MacOS #Development #Programming #Terminal #TechTips #SoftwareDevelopment #DevTools #Productivity

Follow TexArxs for more development tips and tricks!

Disclaimer: Always review command documentation and understand implications before executing system commands.

Follow TexArxs on LinkedIn
Need Apple IT support for your team?
TexArxs handles MDM deployment, Mac support, and Apple IT management for startups and SMEs across India.
Talk to us →

We use cookies to improve your experience and analyse site usage. By continuing, you agree to our use of cookies. Read our Privacy Policy.