A quick-start guide to Unix commands
Summary

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:

Getting started with Unix commands

Let’s start with opening the terminal:

  • In Linux, use Ctrl + Alt + T or search for “Terminal” in the system menu;
  • In MacOS, press Cmd + Space, type “Terminal”, and hit Enter.

Below, you will find the commands to get started in the Terminal. They work on Linux and MacOS alike. 

Basic navigation commands
pwdPrint current directory
lsList files and folders
cd Change directory to
cd ..Go up one directory
cd ~Go to home directory
cd /Go to the root directory
ls -laList files and folders including hidden files
ls -liList 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 lines of file
tail -n Last lines of file
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
whoamiShows your current user
uname -aOS and kernel version
topShows live processes
ps auxDetail process list
kill PIDKill a process ID
chmod +x Make a script executable
chown Change file ownership
sudorun command as superuser (admin)
Utilities
historyShow previously used commands
clearClear the terminal screen
man Show manual/help for a command
echo “text"Output text
dateShow 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

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. 

Share this post :

PID Perspectives is migrating to European Servers. Please, let us know if you experience a slow response or technical issues.