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

File Permissions and Ownership

Managing file access rights and ownership.

Terminal window
# chmod numeric permissions overview:
# Each digit represents permissions for: [Owner][Group][Others]
# Add values for read(4), write(2), execute(1)
#
# Examples:
# 7 = 4+2+1 = read, write, execute
# 6 = 4+2 = read, write
# 5 = 4+1 = read, execute
# 4 = 4 = read
# 3 = 2+1 = write, execute
# 2 = 2 = write
# 1 = 1 = execute
# 0 = none
#
# Common chmod values:
# 755 = rwx for owner, rx for group, rx for others
# 644 = rw for owner, r for group, r for others
# 700 = rwx for owner, none for group/others

chmod [mode] [file]

Change file permissions (numeric or symbolic).

Terminal window
chmod 644 myfile.txt

chmod +x [file]

Make a file executable.

Terminal window
chmod +x script.sh

chown [owner]:[group] [file]

Change file owner and group.

Terminal window
chown user:staff myfile.txt

ls -l

View file permissions and ownership.

Terminal window
ls -l

stat [file]

Show detailed file status including permissions and ownership.

Terminal window
stat myfile.txt

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

kill [pid]

Terminate a process by its PID.

Terminal window
kill 1234

kill -9 [pid]

Force kill a process by its PID.

Terminal window
kill -9 1234

pkill [name]

Kill processes by name.

Terminal window
pkill firefox

systemctl status [service]

Show status of a systemd service.

Terminal window
systemctl status nginx

systemctl restart [service]

Restart a systemd service.

Terminal window
systemctl restart nginx

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

Archiving and Compression

Creating and extracting tarballs and zip files.

Terminal window
# tar common flags overview:
# c = create new archive
# x = extract archive
# v = verbose (show files being processed)
# f = specify filename of archive
# z = compress with gzip (.tar.gz)
# j = compress with bzip2 (.tar.bz2)
# J = compress with xz (.tar.xz)
#
# Examples:
# tar -cvf archive.tar files/ -> create tar
# tar -xvf archive.tar -> extract tar
# tar -czvf archive.tar.gz dir/ -> create gzipped tar
# tar -xzvf archive.tar.gz -> extract gzipped tar

tar -cvf [archive.tar] [files]

Create a tar archive from files or directories.

Terminal window
tar -cvf archive.tar myfolder

tar -xvf [archive.tar]

Extract a tar archive.

Terminal window
tar -xvf archive.tar

tar -czvf [archive.tar.gz] [files]

Create a compressed tarball (gzip).

Terminal window
tar -czvf archive.tar.gz myfolder

tar -xzvf [archive.tar.gz]

Extract a gzipped tarball.

Terminal window
tar -xzvf archive.tar.gz

zip [archive.zip] [files]

Create a zip archive.

Terminal window
zip archive.zip myfile.txt myfolder/*

unzip [archive.zip]

Extract a zip archive.

Terminal window
unzip archive.zip