π File & Directory Operations
ls: List directory contents
$ ls
Desktop Documents Downloads
cp: Copy files or directories
$ cp file1.txt copy.txt
$ mv copy.txt moved.txt
$ rm moved.txt
mkdir: Create a directory
$ mkdir projects
rmdir: Remove an empty directory
$ rmdir projects
install: Copy files and set attributes
$ install file1.txt /tmp/file2.txt
touch: Create an empty file or update timestamp
$ touch notes.txt
$ stat notes.txt
File: notes.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
$ cat file.txt
Hello
World
tac: Show file in reverse order
$ tac file.txt
World
Hello
less: View file page by page
$ less file.txt
Hello
World
more: View file page by page
$ more file.txt
Hello
World
head: Show first 10 lines
$ head file.txt
Hello
World
$ tail file.txt
Hello
World
$ nl file.txt
1 Hello
2 World
od: Show file in octal/hex/etc
$ od -c file.txt
0000000 H e l l o \n W o r l d \n
strings: Extract printable text
$ strings /bin/ls | head -3
/lib64/ld-linux-x86-64.so.2
__libc_start_main
GLIBC_2.2.5
$ sort names.txt
Alice
Bob
Charlie
$ uniq items.txt
apple
banana
orange
$ cut -d, -f1 data.csv
Name
Alice
Bob
wc: Count lines, words, chars
$ wc file.txt
2 2 12 file.txt
tr: Translate or delete characters
$ echo "hello" | tr a-z A-Z
HELLO
expand: Convert tabs to spaces
$ echo -e "a\tb" | expand
a b
unexpand: Convert spaces to tabs
$ echo "a b" | unexpand
a b
π File Information & Searching
$ file notes.txt
notes.txt: ASCII text
$ find . -name "*.txt"
./notes.txt
dirname: Get directory path
$ dirname /home/user/file.txt
/home/user
basename: Get filename only
$ basename /home/user/file.txt
file.txt
π Permissions & Ownership
chmod: Change file permissions
$ chmod 644 notes.txt
$ sudo chown user:user notes.txt
chgrp: Change group ownership
$ sudo chgrp staff notes.txt
$ ln notes.txt link.txt
ln -s: Create symbolic link
$ ln -s notes.txt symlink.txt
date: Show or set date/time
$ date
Sun Aug 17 12:00:00 UTC 2025
$ uptime
12:00:00 up 1 day, 3:45, 2 users, load average: 0.10, 0.12, 0.09
$ sleep 2
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 30G 70G 30% /
du: Show file/directory sizes
$ du -sh Documents
120M Documents
truncate: Shrink or expand file
$ truncate -s 1K notes.txt
π₯οΈ System Information
$ uname -a
Linux host 5.15.0 x86_64 GNU/Linux
$ hostname
my-computer
whoami: Show current user
$ whoami
user
$ id
uid=1000(user) gid=1000(user) groups=1000(user),27(sudo)
groups: Show group memberships
$ groups
user sudo
who: Show logged in users
$ who
user tty1 2025-08-17 10:00
users: Show logged in users (short)
$ users
user
$ logname
user
$ tty
/dev/pts/0
π Text/File Comparison
cmp: Compare files byte by byte
$ cmp file1.txt file2.txt
file1.txt file2.txt differ: byte 1, line 1
$ diff file1.txt file2.txt
1c1
< Hello
---
> Hi
comm: Compare sorted files line by line
$ comm file1.txt file2.txt
Hello
Hi
π οΈ Miscellaneous Utilities
yes: Repeatedly print string
$ yes "hello" | head -3
hello
hello
hello
$ echo "Hello World"
Hello World
$ printf "Name: %s\n" Alice
Name: Alice
true: Do nothing, succeed
$ true
$ echo $?
0
$ false
$ echo $?
1
test: Evaluate expressions
$ test -f notes.txt && echo "exists"
exists
expr: Evaluate expressions
$ expr 5 + 3
8
$ seq 3
1
2
3
basename: Get filename only
$ basename /path/to/file.txt
file.txt
dirname: Get directory path
$ dirname /path/to/file.txt
/path/to