Unix is a powerful, multiuser operating system that serves as the foundation for Linux and MacOS. The Unix command-line interface (CLI) allows you to control your system efficiently by typing commands instead of clicking through graphical menus. Here is a practical guide to both operating systems’ most commonly used Unix commands.
Why learn UNIX commands?
Linux users are known to be advocates for the CLI. Why? This is because Unix commands:
- Perform tasks faster (especially the repetitive ones)
- Manage files and directories with precision
- Run powerful scripts and automate processes
- Are essential for programming, system admin, cybersecurity, and more
Getting started with Unix commands
Let’s start with opening the terminal:
- In Linux, use
Ctrl + Alt + Tor search for “Terminal” in the system menu; - In MacOS, press
Cmd + Space, type “Terminal”, and hit Enter.
- Unlike WIndows commands, UNIX commands are case sensitive. File and folders name are case sensitive as well, so File.txt is different than file.txt or file.TXT.
Below, you will find the commands to get started in the Terminal. They work on Linux and MacOS alike.
| Basic navigation commands | |
|---|---|
| pwd | Print current directory |
| ls | List files and folders |
| cd | Change directory to |
| cd .. | Go up one directory |
| cd ~ | Go to home directory |
| cd / | Go to the root directory |
| ls -la | List files and folders including hidden files |
| ls -li | List files and folders with their permissions |
| File and directory operations | |
| touch | Create a new empty file |
| mkdir | Make a new folder |
| cp | Copy a file |
| mv | Move a file |
| rm | Remove a file |
| rm -r | Remove a folder and its contents |
| Viewing and editing files | |
| cat | View file content |
| less | View file with scrolling (q to quit) |
| head -n | First |
| tail -n | Last |
| nano | Open nano text editor |
| vim | Open vim text editor |
| Searching and finding | |
| find . -name “*.txt" | Find all the .txt files in current directory |
| grep “keyword” | Search for a keyword in a file |
| grep -r “password” /etc/ | Recursively search in a directory |
| System info and processes | |
| whoami | Shows your current user |
| uname -a | OS and kernel version |
| top | Shows live processes |
| ps aux | Detail process list |
| kill PID | Kill a process ID |
| chmod +x | Make a script executable |
| chown | Change file ownership |
| sudo | run command as superuser (admin) |
| Utilities | |
| history | Show previously used commands |
| clear | Clear the terminal screen |
| man | Show manual/help for a command |
| echo “text" | Output text |
| date | Show system date and time |
Scripting with bash
Once familiar with Unix commands, you can combine them into Bash scripts to automate tasks. For example:
#!/bin/bash
echo "Hello, $USER!"
echo "Today is $(date)"
Save this as hello.sh, then make the file executable and launch it with:
chmod +x hello.sh
./hello.sh
Tips for learning
- Practice using the Terminal daily
- Use man or —help to learn what commands do and how to use them
- Don’t be afraid to experiment in a test directory
- For MacOS users: many Linux tutorials still apply
Once you learn the basics, working with the Terminal on Linux and MacOS can be fun and rewarding. Depending on the specific OS you use, applications and their commands will vary, but these basic commands will enable you to navigate any UNIX-based system.