Command-Line Interface (CLI)

File and Directory Commands

Command
Description

ls

List files/folders

ls -a

List all files including hidden

pwd

Show current directory

cd <folder>

Change directory

cd /

Go to root directory

cd or cd ~

Go to home directory

cd ..

Go up one directory

cd -

Go to previous directory

mkdir <folder>

Create directory

touch <file>

Create empty file

rm <file>

Delete file

rm -r <folder>

Remove folder and contents

rmdir <folder>

Remove empty folder


File Viewing and Editing

Command
Description

cat <file>

Show file contents

cat -n <file>

Show file with line numbers

cat > <file>

Create/overwrite file (input, Ctrl+D to end)

cat >> <file>

Append to file (Ctrl+D to end)

nano <file>

Simple text editor (Ctrl+O save, Ctrl+X exit)

vim <file>

Powerful editor (i insert, Esc, :wq save & exit)


Permissions and Ownership

Command
Description

ls -l <file>

Show file permissions and details

ls -@l <file>

Show permissions + extended attributes (macOS)

chmod u=rw,g=r,o=r <file>

Change permissions (owner/group/others)

chmod o+rw <file>

Add read/write for others

chown <user> <file>

Change file owner

chgrp <group> <file>

Change file group

sudo chown root <file>

Change owner to root

sudo chgrp root <file>

Change group to root


Process and System Commands

Command
Description

sudo

Run command as administrator

ps / ps aux

Show running processes

kill <pid>

Stop a process by process ID

top / htop

Interactive process viewer

bg

Send process to background

fg

Bring process to foreground


Package Managers

Command
OS/Use

apt-get

Linux package manager

brew

macOS package manager

snap

Universal package manager

pip

Python package installer


Command
Description

pushd

Save current dir on stack + switch dir

popd

Return to previous directory on stack

Last updated