Skip to content

Instantly share code, notes, and snippets.

@carlosgrillet
Created August 17, 2025 12:21
Show Gist options
  • Select an option

  • Save carlosgrillet/c6ec9ba3da55c437878fbb1c97d18c3d to your computer and use it in GitHub Desktop.

Select an option

Save carlosgrillet/c6ec9ba3da55c437878fbb1c97d18c3d to your computer and use it in GitHub Desktop.
Coreutils cheat sheet

πŸ“‚ File & Directory Operations

ls: List directory contents

$ ls
Desktop  Documents  Downloads

cp: Copy files or directories

$ cp file1.txt copy.txt

mv: Move or rename files

$ mv copy.txt moved.txt

rm: Remove files

$ 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: Show file details

$ stat notes.txt
  File: notes.txt
  Size: 0   Blocks: 0   IO Block: 4096  regular empty file

πŸ“– File Viewing

cat: Show file contents

$ 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: Show last 10 lines

$ tail file.txt
Hello
World

nl: Number lines

$ 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

βœ‚οΈ Text Processing

sort: Sort lines

$ sort names.txt
Alice
Bob
Charlie

uniq: Remove duplicates

$ uniq items.txt
apple
banana
orange

cut: Extract columns

$ 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: Identify file type

$ file notes.txt
notes.txt: ASCII text

find: Search for files

$ 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

chown: Change file owner

$ sudo chown user:user notes.txt

chgrp: Change group ownership

$ sudo chgrp staff notes.txt

πŸ“¦ Archiving & Linking

ln: Create hard link

$ ln notes.txt link.txt

ln -s: Create symbolic link

$ ln -s notes.txt symlink.txt

⏱️ Date & Time

date: Show or set date/time

$ date
Sun Aug 17 12:00:00 UTC 2025

uptime: Show uptime

$ uptime
12:00:00 up 1 day,  3:45,  2 users,  load average: 0.10, 0.12, 0.09

sleep: Pause execution

$ sleep 2

πŸ“Š Disk & File Size

df: Show disk usage

$ 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: Show system info

$ uname -a
Linux host 5.15.0 x86_64 GNU/Linux

hostname: Show hostname

$ hostname
my-computer

whoami: Show current user

$ whoami
user

id: Show user identity

$ 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: Show login name

$ logname
user

tty: Show terminal name

$ 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: Show differences

$ 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: Print arguments

$ echo "Hello World"
Hello World

printf: Format output

$ printf "Name: %s\n" Alice
Name: Alice

true: Do nothing, succeed

$ true
$ echo $?
0

false: Do nothing, fail

$ false
$ echo $?
1

test: Evaluate expressions

$ test -f notes.txt && echo "exists"
exists

expr: Evaluate expressions

$ expr 5 + 3
8

seq: Generate sequences

$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment