Skip to content

terminal

Frequently used shell commands for file navigation, permissions, networking and more.

Navigation

Moving around the file system.

pwd

Print working directory (shows your current location).

Terminal window
pwd

cd [directory]

Change directory.

Terminal window
cd Documents

ls

List files and directories.

Terminal window
ls

ls -l

List files and directories with details.

Terminal window
ls -l

ls -a

List all files and directories (including hidden ones).

Terminal window
ls -a

cd ..

Go up one directory.

Terminal window
cd ..

cd ~

Go to your home directory.

Terminal window
cd ~

File Manipulation

Creating, moving, and deleting files and directories.

touch [file]

Create an empty file.

Terminal window
touch myfile.txt

mkdir [directory]

Create a new directory.

Terminal window
mkdir mydirectory

cp [source] [destination]

Copy a file or directory.

Terminal window
cp myfile.txt mycopy.txt

mv [source] [destination]

Move or rename a file or directory.

Terminal window
mv myfile.txt newlocation/myfile.txt

rm [file]

Remove a file.

Terminal window
rm myfile.txt

rm -r [directory]

Remove a directory and its contents (recursive).

Terminal window
rm -r mydirectory

rm -f [file]

Force remove a file (use with caution!).

Terminal window
rm -f myfile.txt

rm -rf [directory]

Force remove a directory and its contents (use with extreme caution!).

Terminal window
rm -rf mydirectory

Viewing Files

Displaying the contents of files.

cat [file]

Display the contents of a file.

Terminal window
cat myfile.txt

less [file]

View a file one page at a time (use space to scroll, q to quit).

Terminal window
less myfile.txt

head [file]

Display the first few lines of a file.

Terminal window
head myfile.txt

tail [file]

Display the last few lines of a file.

Terminal window
tail myfile.txt

nano [file]

Open a file in the nano text editor.

Terminal window
nano myfile.txt

vi/vim [file]

Open a file in the vi/vim text editor.

Terminal window
vi myfile.txt

Searching

Finding files and content.

find [directory] [options] [expression]

Find files and directories.

Terminal window
find . -name "myfile.txt"

grep [pattern] [file]

Search for a pattern in a file.

Terminal window
grep "hello" myfile.txt

which [command]

Show the location of a command.

Terminal window
which ls

System Information

Getting information about the system.

uname -a

Display system information.

Terminal window
uname -a

df -h

Display disk space usage.

Terminal window
df -h

du -sh [directory]

Display directory size.

Terminal window
du -sh Documents

top

Display running processes.

Terminal window
top

ps aux

List all running processes.

Terminal window
ps aux

Networking

Commands related to network operations.

ping [host]

Check network connectivity to a host.

Terminal window
ping google.com

ifconfig

Display network interface information (macOS/Linux).

Terminal window
ifconfig

ipconfig

Display network interface information (Windows).

Terminal window
ipconfig

netstat

Display network connections.

Terminal window
netstat

curl [url]

Transfer data from or to a server.

Terminal window
curl https://www.example.com

wget [url]

Download a file from a URL.

Terminal window
wget https://www.example.com/file.zip

Package Management (macOS - Homebrew)

Managing software packages with Homebrew.

brew install [package]

Install a package.

Terminal window
brew install wget

brew uninstall [package]

Uninstall a package.

Terminal window
brew uninstall wget

brew update

Update Homebrew and its packages.

Terminal window
brew update

brew search [package]

Search for a package.

Terminal window
brew search wget

brew list

List installed packages.

Terminal window
brew list