Looking for a quick reference to streamline your Unix operations? Explore our blog on Unix Commands Cheat Sheet, a valuable resource to help you master the essential commands, syntax, and tips for efficient terminal navigation. Whether you're a beginner or an experienced user, this cheat sheet is your go-to guide for smoother Unix command execution.
Home Resources IT Infrastructure & Networking Unix Commands Cheat Sheet: Commands You NeedUNIX Fundamentals Top Rated Course
Exclusive 40% OFF
Enquire Now Download curriclumWe ensure quality, budget-alignment, and timely delivery by our expert instructors.
-->
Unix has stood the test of time as a robust and powerful Operating System (OS) for decades now. Despite its complexity and steep learning curve, the multitasking capabilities it offers alongside the UNIX Toolkit make it worth having this Unix Commands Cheat Sheet at all times.
Unix has a market share of around 10 per cent as of 2022, according to 6sense.com. Navigating the Unix environment efficiently requires familiarity with a range of Commands. This Unix Commands Cheat Sheet serves as a comprehensive guide to mastering fundamental Commands, enhancing productivity, and simplifying daily tasks.
Table of Contents
1) Getting started with Unix
2) Unix Commands Cheat Sheet
a) Navigating the file system
b) Text Manipulation
c) System Information
e) User Management
f) Package Management
g) Process management
h) File Compression and Archiving
Before we dive into the Unix Commands Cheat Sheet, let's take a moment to understand the basics of Unix. Unix is an Operating System that originated in the 1960s and has since become the backbone of many modern systems. It features a Command-line Interface that allows users to interact with the system using textual Commands. Whether you're managing files, processes, or users, Unix Commands provide a powerful way to control your system.
Accessing the Terminal is the gateway to the heart of Unix systems, enabling users to engage with its powerful functionalities through the Command-line Interface. By launching the Terminal, users are welcomed into a text-based environment where they can communicate directly with the Operating System.
This initiation empowers users to execute a myriad of Unix Commands, from file management to process control and networking tasks. The Terminal provides a direct and efficient way to harness the system's potential, offering a realm of possibilities to those who seek to navigate, manage, and optimise their Unix experience through the execution of concise and precise textual Commands.
Each Command in Unix follows a specific structure: Command Name > Options > Arguments. The Command Name indicates the action to perform, while Options modify the Command's behaviour. Arguments are the elements the Command operates on, such as file names or parameters.
To execute a Command, open the Terminal and type the Command followed by its Options and Arguments. Press Enter to run it. For instance, to list files in a directory, use the 'ls' Command followed by Options like '-l' for detailed output. With this grasp of basic syntax, you're now well-equipped to explore the world of Unix Commands efficiently.
In this section we will look through the basic Unix Commands under the following categories:
Unix Commands for Navigating the File System: Effortlessly traverse directories and manage files using essential Command-line instructions.
1) pwd: Displays the current working directory's full path.
2) ls: Lists files and directories in the current directory.
3) ls –l: Lists files and directories in a detailed, long format.
4) ls –a: Lists all files and directories, including hidden ones.
5) cd directory: It changes the current directory to the specified directory.
6) cd ~ or cd: Changes the current directory to the user's home directory.
7) cd . Moves up one directory level (to the parent directory).
8) mkdir directory: It creates a new directory with the specified name.
9) rmdir directory: Removes an empty directory.
10) cp source dest: Copies a file or directory from the source to the destination.
11) mv source dest: Moves or renames a file or directory from source to destination.
12) rm file: Deletes a file.
13) rm -r directory: Recursively deletes a directory and its contents (use with caution).
14) touch file: Creates an empty file with the specified name.
15) cat file: Displays the contents of a file.
16) less file: Opens a file for viewing, allowing scrolling and searching.
17) head file: Displays the beginning lines of a file (default: first 10 lines).
18) tail file: Displays the ending lines of a file (default: last 10 lines).
19) tail -f file: Displays the end of a file in real-time, updating as new content is added (e.g., logs).
20) find dir -name pattern: Searches for files and directories matching the specified pattern within the given directory.
21) grep pattern file: Searches for a specified pattern within a file.
Unlock the power of Unix: Register Now for a Comprehensive UNIX Fundamentals Course and Master the Command-line!
Text Manipulation Commands in Unix allow you to efficiently process and modify text content, enhancing your ability to work with textual data.
1) cat: Concatenate and display the contents of one or more files.
2) grep: Search for a specific pattern within files or text streams.
3) sed (Stream Editor): Text processing tool for finding and replacing patterns in text.
4) awk: A versatile text processing language for data extraction and manipulation.
5) cut: Extract specific columns or fields from lines of text.
6) sort: Sort lines of text files alphabetically or numerically.
7) uniq: Filter out duplicate lines from sorted input.
8) wc (Word Count): Count the number of lines, words, and characters in a text file.
9) head: Display the first few lines of a text file.
10) tail: Display the last few lines of a text file.
11) tr (Translate): Translate characters from one set to another in text.
12) paste: Merge lines of text files side by side.
13) join: Join lines from two files based on a common field.
14) diff: Compare and display the differences between two text files.
15) comm: With this, you can compare two sorted files line by line and display common or unique lines.
16) nl (Number Lines): Precede each line of text with its line number.
17) echo: Display a message or value to the Terminal.
Unlock the power of UNIX systems with our comprehensive Administering Unix Systems Course – Join today to become a skilled Administrator!
System Information Commands in Unix provide insights into various aspects of the Operating System and hardware configuration.
1) uname: Displays system information such as kernel name, node name, kernel release, and machine architecture.
2) hostname: Prints the system's hostname.
3) uptime: Shows the system's uptime and load average.
4) free: Displays memory usage information, including total, used, and free memory.
5) df: Lists disk space usage on mounted file systems.
6) lscpu: Prints information about the CPU architecture and its capabilities.
7) lshw: Displays detailed hardware information, including CPU, memory, storage, and more.
8) lsblk: Lists information about block devices (disks and partitions) and their attributes.
Networking Commands in Unix allow you to manage, troubleshoot, and interact with network-related aspects of your system, facilitating communication and connectivity in a digital world.
1) Ifconfig: Displays and configures network interface parameters, including IP addresses and netmasks.
2) ping: Sends ICMP echo requests to a host to check if it's reachable and calculates round-trip time.
3) netstat: Displays network-related information, such as active connections, listening ports, and routing tables.
4) nslookup: Queries DNS servers to retrieve information about domain names, IP addresses, and other DNS records.
5) traceroute: Traces the route taken by packets to a destination, showing each hop's IP address and response time.
6) ssh: Initiates a secure remote shell session for accessing and managing remote systems.
7) scp: Securely copies files between local and remote systems over a network.
8) wget: Downloads files from the internet using HTTP, HTTPS, or FTP protocols, supporting resuming interrupted downloads.
9) curl: A versatile Command-line tool to transfer data to or from a server, supporting various protocols like HTTP, FTP, and more.
10) iptables: Configures and manages firewall rules and Network Address Translation (NAT) on Linux systems.
11) ip: A powerful tool for managing network interfaces, routes, tunnels, and more, replacing the deprecated ‘ifconfig’ and route Commands.
12) route: Displays and manages the IP routing table, showing the network destinations and their associated gateways.
13) host: Performs DNS lookups to translate domain names to IP addresses or vice versa.
14) ifup/ifdown: Brings up or takes down a network interface, allowing you to control network connectivity.
15) ss: Displays detailed information about sockets, including network connections, listening ports, and network statistics.
16) arp: Displays and manages the ARP cache, which maps IP addresses to MAC addresses on a local network.
17) nmap: Scans networks to discover open ports, services, and hosts, helping with network reconnaissance.
18) dhclient: Requests an IP address lease from a DHCP server, useful for configuring network settings dynamically.
19) ifcfg: Manages configuration files for network interfaces, allowing custom settings for various networking options.
User Management involves controlling and administering user accounts on a computer system, governing access, permissions, and security.
1) who: Displays a list of currently logged-in users.
2) w: Provides detailed information about logged-in users.
3) whoami: Prints the username of the current user.
4) id: Displays information about a user's identity.
5) users: Lists the usernames of currently logged-in users.
6) finger: Displays user information including login details.
7) last: Shows the recent login history of users.
8) useradd: It adds a new user account to the system.
9) userdel: Deletes a user account from the system.
10) usermod: Modifies user account properties.
11) passwd: Changes the password for a user.
12) su: Switches to another user's account.
13) sudo: Executes Commands with superuser privileges.
14) chown: Changes the ownership of files and directories.
15) chgrp: It changes the group ownership of files and directories.
16) chmod: Changes file permissions.
17) visudo: Edits the ‘sudoers’ file for configuring ‘sudo’ access.
18) groups: Lists the groups a user belongs to.
19) newgrp: Switches the primary group of the user temporarily.
20) gpasswd: Manages group passwords and membership.
21) sg: Executes a Command as if you were a member of a group.
Package Management involves the systematic installation, updating, and removal of software packages on a computer system to ensure smooth software operations and easy maintenance.
1) apt-get: Advanced Package Tool - Command-line package manager for Debian-based systems.
2) yum: Yellowdog Updater Modified - Package manager for Red Hat-based systems.
3) dnf: Dandified Yum - Next-generation package manager for Fedora and CentOS.
4) pacman: Package Manager Utility - Package manager for Arch Linux.
5) zypper: Package manager for openSUSE Linux distributions.
6) emerge: Package manager for Gentoo Linux.
7) apt: Command-line package manager for Ubuntu and other Debian-based systems.
8) rpm: Red Hat Package Manager - Low-level package manager for Red Hat-based systems.
9) dpkg: Debian Package - Low-level package manager for Debian-based systems.
10) portage: Package management system for Gentoo Linux.
11) pkg: Package manager for FreeBSD.
12) brew: Homebrew - Package manager for macOS and Linux.
13) pkgtool: Package management tool for Slackware Linux.
14) yast: Yet Another Setup Tool - Package manager for openSUSE Linux.
15) flatpak: Software utility for software deployment and package management on various Linux distributions.
16) snap: Package manager for Linux distributions supporting snap packages.
17) conda: Package manager, environment manager, and distribution of software packages for Python.
18) alien: Converts packages from one package format to another (e.g., .deb to .rpm).
19) debootstrap: Bootstrapping tool for creating Debian-based root filesystems.
20) aptitude: Text-based interface to the Advanced Package Tool (APT) for package management.
The Process Management Commands in Unix allow you to monitor, control, and interact with running processes on your system efficiently.
1) ps: Displays a snapshot of currently running processes.
2) ps aux: Lists all running processes in a detailed format.
3) top: Displays real-time information about system processes, resource usage, and system statistics.
4) htop: Interactive version of top, providing an enhanced visual representation of processes.
5) kill PID: Sends a signal to a process, allowing you to terminate it or modify its behaviour.
6) killall process: Terminates all processes with the specified name.
7) pkill pattern: Kills processes based on a specified pattern in their Command names.
8) pgrep pattern: Lists process IDs that match the specified pattern.
9) nice command: Launches a Command with a specified priority level.
10) renice priority PID: Changes the priority of a running process.
11) ps –eLf: Displays a detailed list of threads associated with each process.
12) pstree: Displays a visual representation of running processes in a hierarchical tree structure.
13) jobs: Lists background jobs attached to the current terminal session.
14) fg %job: Brings a background job to the foreground.
15) bg %job: Resumes a suspended background job.
16) nohup command &: It runs a Command in the background, allowing it to continue running even after you log out.
17) disown: Removes background jobs from the shell's job table.
18) cron: Schedules and automates the execution of tasks at specified intervals.
19) at: Executes Commands at a specified time in the future.
20) systemctl: Controls and manages system services and processes on ‘systemd’-based Unix systems.
21) service: Manages system services and daemons on ‘SysVinit’-based Unix systems.
File Compression and Archiving in Unix enables efficient storage and transfer of files by compressing them into smaller sizes and organising them into archives.
1) Tar: It combines multiple files into an Archive and optionally compresses it.
2) gzip: Compresses files using the ‘gzip’ algorithm, replacing the original file.
3) gunzip: Decompresses files compressed with ‘gzip’.
4) zip: Creates and compresses Archives using the zip format.
5) unzip: Extracts files from ‘zip’ Archives.
Mastering Unix Commands is a gateway to harnessing the full potential of this venerable Operating System. This Unix Commands Cheat Sheet provides a solid foundation, enabling users to navigate directories, manipulate files, manage processes, and interact with networks. By incorporating these Commands into daily workflows, users can enhance productivity and wield Unix's power with confidence.
Level up your skills with our comprehensive Linux Training – master the Command line and unlock the full potential of the Linux Operating System.