DEV Community

Mohammed Ali
Mohammed Ali

Posted on • Updated on

Ultimate CLI Cheatsheet [Live Doc]

cd ../.. // Usecase: Move up two levels
Ctrl + L // Clear screen by scrolling down

touch

Ex. touch [OPTION]... File...
[OPTION] = optional
File... = required filenames
creating a new file using CLI provided it doesn't exist. In case file exists, it will update the access & modification time to the current time. A File argument that does not exist is created empty.
touch : extension is mandatory, else generic file will be created.
touch ../dog.txt : create a file one level above in parent directory
touch ~/cat.txt : create a file in home directory.
Ex. touch file{1..100}.txt
Ex. touch app.{html,css,js}
Ex. ls -l : long format
Ex. mkdir {images,css,src,templates,scripts}
NOTE = Only one caveat here: just ensure that there are no spaces between the words inside the braces.

pwd:

print working directory
Output: Full path of the current directory you are in. Helps in determining current location within the file system hierarchy.
pwd : shows the full path of the current working directory
pwd -L : (Default), prints the logical path, meaning it shows the path as it appears in the file system
pwd -P : prints the physical path, which resolves all symbolic links to show the actual path on the disk.

dirname:

to strip the last component from a given file path, effectively providing the directory path that contains the file or directory specified.
Usage: Useful for extracting the directory name from a full file path, which can be helpful in scripts and file manipulation tasks.
Ex: dirname /home/user/documents/file.txt
Output: /home/user/documents
Strips file.txt from the path, leaving /home/user/documents

rm & rmdir:

rm -r //will delete mydirectory and everything inside it.
rmdir // will delete mydirectory only if it is empty.

netstat

"netstat -an | grep ESTABLISHED" = Shows all established connections.
"netstat -antp (Linux) or netstat -an -o" (Win) provides additional details, including the process ID (PID) associated with the connection.

Ctrl + R = for reverse search
Ctrl + L = clear the screen
Ctrl + D = exit terminal
curl ifconfig.me = See your public IP

who: (show who is logged on)
who -a: All available information.
who -q: Number of logged-on users.

Flags: [Case-sensitive]

-a OR --all
-i OR --interactive
-l OR long format
-m OR --message
-q OR --quiet
-v OR --version
-w OR --watch
-y OR --yes

-D OR --save-dev
-L OR --logical
-P OR --physical

File and Directory Management

find || locate || ln || rsync || scp || rclone || tree || fdupes || file || basename || split || paste || md5sum || comm || sha256sum || iconv || dos2unix || unix2dos || tac || nl || pr || yes || rev || watch || env || export || alias || unalias || which || whereis || apropos

Text Processing

awk || sed || sort || uniq || cut || tr || wc || diff || cmp
Enter fullscreen mode Exit fullscreen mode

Process Management

bg/fg || jobs || nohup || htop || nice/renice
Enter fullscreen mode Exit fullscreen mode

File content

cat || less || head || tail || grep || nano/vim || tee || 
Enter fullscreen mode Exit fullscreen mode

Permissions

chmod || chown
Enter fullscreen mode Exit fullscreen mode

System Information, Monitoring & Performance

whoami || uname || df || du || top || ps || kill || killall || uptime || iotop || vmstat || iostat || sar || mpstat || lsof || lsb_release || dstat || ps || pgrep || time || 
Enter fullscreen mode Exit fullscreen mode

System & User Management

useradd / userdel || usermod || passwd || sudo || cron || dmesg || journalctl || systemctl
Enter fullscreen mode Exit fullscreen mode

Networking & Security

ping || ifconfig / ip addr || wget || curl || ss || iptables || scp || ssh || telnet || dig || nc [netstat] || fail2ban || ufw || openssl || gpg || nslookup ||
Enter fullscreen mode Exit fullscreen mode

Archiving & Compression

tar || zip / unzip
Enter fullscreen mode Exit fullscreen mode

Package Management

apt-get [debian based] || yum / dnf [red-hat or cent-os based] || snap  || brew [Mac-OS & Linux]
Enter fullscreen mode Exit fullscreen mode

Development Tools

gcc || make || git || docker || virtualenv || npm || pip || python || node || javac || docker || kubernetes / kubectl || vagrant || terraform
Enter fullscreen mode Exit fullscreen mode

Disk & File Management

mount / unmount || fsck || dd || fdisk / parted || mkfs || resize2fs || cryptsetup || btrfs
Enter fullscreen mode Exit fullscreen mode

Scripting & Automation

alias || xargs || exec || cron
Enter fullscreen mode Exit fullscreen mode

Debugging, Tshooting, Diagnostics & Logs

strace || ltrace || tcpdump || gdb || nmap || traceroute || who || last || lshw || lsblk || blkid || fdisk || hdparm || ethtool || iwconfig || nmcli || host || ipcalc || mtr || firewalld || route || whois || free || nmon
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
ashish_taunk profile image
Ashish Taunk

This is great collection. Thanks 👍