Linux Commands Reference Guide
Last updated: December 24, 2024
What is a Command?
A command is a binary file kept under a specific directory that performs a particular function when executed.
Command Categories
File and File System Management
cat | cd | chmod | chown | chgrp | cp | du | df | file | fsck | ln | ls | lsof | mkdir | mount | mv | pwd | rm | rmdir | split | touch
Process Management
at | chroot | crontab | kill | killall | nice | pgrep | pidof | pkill | ps | sleep | time | top | wait | watch
User Management/Environment
env | finger | id | mesg | passwd | su | sudo | uname | uptime | w | wall | who | whoami | write
Text Processing
awk | cut | diff | ex | head | iconv | join | less | more | paste | sed | sort | tail | tr | uniq | wc | xargs
Communications & Networking
inetd | netstat | ping | rlogin | traceroute
Searching
find | grep | strings
Printing
lp
Miscellaneous
banner | bc | cal | man | size | yes
Filesystem Utilities
- cd - Change to another directory location
- ls - List directory contents
- cp - Copy a file or directory to another location
- pwd - Print the current working directory
- mkdir - Make a directory
- mv - Move or rename a file or directory
- rmdir - Delete an empty directory
- rm - Delete a file or directory tree
- touch - Create a new file or update its modification time
- which - Locate a command
- locate - Find files by name
- ln - Link one file/directory to another
- df - Report disk space
- du - Calculate used disk space
- find - Search for files through a directory hierarchy
- chmod - Change the permissions of a file or directory
- chown - Change the owner of a file or directory
- chgrp - Change the group of a file or directory
- quota - Display disk usage and limits
- strings - Print the strings of printable characters in files
- info - The GNU alternative to man
- man - The standard Unix documentation system
- less - Opposite of more ;)
- wc - Print newline, word, and byte counts for each file
Hands-On Examples
# Find files larger than 10MB in /usr
find /usr -size +10M
# Find files modified more than X days ago
find /home -mtime +7
# Find files accessed within the last X days
find /var -atime -7
# Find and remove core files
find / -name core -exec rm {} \;
Text Processing Commands
- echo - Display line of text
- cat - Concatenate files to standard output
- less - Improved more-like text pager
- more - Text pager
- head - Output the first parts of a file
- tail - Output the last parts of a file
- cut - Remove sections from each line of a file or standard input
- paste - Merge lines of files
- diff - Compare two text files line by line
- cmp - Compare two files byte for byte
- sort - Sort lines of text files
- join - Join lines of two files on a common field
- awk - A pattern scanning and processing language
- grep - Print lines matching a pattern
- egrep - Extended pattern matching (synonym for "grep -E")
- fgrep - Simplified pattern matching (synonym for "grep -F")
- sed - Stream editor for filtering and transforming text
- split - Split a file into pieces
- tee - Read from standard input, write to standard output and files
- tr - Translate or delete characters
- uniq - Report or omit repeated lines
- wc - Word/line/byte count
- fold - Wrap each input line to fit within the given width
- iconv - Convert the encoding of the specified files
- uuencode - Encode a binary file for transmission using electronic mail
- uudecode - Decode a binary file that was used for transmission
- cksum - Print the CRC checksum and bytecount of a file
- banner - Create ASCII art version of an input string
Grep Commands - Hands-On
Basic Pattern Searching
# Search for pattern "july" (case-insensitive) in all files
grep -i july *
# Print file names that do NOT contain "july"
grep -L july *
# Select lines containing "july" as a whole word
grep -w july filename
# Search recursively in all files under a directory
grep -r july .
Context and Line Control
# Print 10 lines after the match
grep -A 10 july filename
# Print 1 line before the match
grep -B 1 july filename
# Print 4 lines before and after the match (context)
grep -C 4 july filename
# Print line numbers of matches
grep -n "july" filename
# Print lines excluding the pattern
grep -v july filename
General User Commands
- exit - Cause normal process termination
- logout - Terminate login shell
- dd - Convert and copy a file (Disk Dump)
- dirname - Strip non-directory suffixes from a path
- echo - Print to standard output
- env - Show environment variables; run a program with altered environment
- file / stat - Determine the type of a file
- nohup - Run a command with immunity to hangups outputting to non-tty
- sh - The Bourne shell, the standard Unix shell
- uptime - Print how long the system has been running
- history - GNU History Library
- source - Execute commands from filename in current shell environment
- seq - Print a sequence of numbers
Archives and Compression
- tar - Tape ARchiver, concatenates files
- gzip - The gzip file compressor
- bzip2 - Block-sorting file compressor
- ar - Maintain, modify, and extract from archives (largely obsoleted by tar)
- cpio - A traditional archiving tool/format
- zcat - Print files to stdout from gzip archives without unpacking
- afio - Compatible superset of cpio with added functionality
- p7zip - 7zip for Unix/Linux
- pax - POSIX archive tool that handles multiple formats
- pack / pcat / unpack - Old ATT Unix tools using Huffman coding (obsoleted by compress)
Process and Task Management
- top - Display Linux processes
- htop - Interactive ncurses-based process viewer with scrolling
- ps - Report process status
- kill - Send a signal to process, or terminate a process (by PID)
- killall - Terminate all processes (in GNU/Linux, kill by name)
- pkill - Look up or signal processes based on name and other attributes
- pgrep - Find PIDs of processes by name
- pidof - GNU/Linux equivalent of pgrep
- watch - Execute a program periodically, showing output fullscreen
- nohup - Run a command immune to hangups, with output to a non-tty
- nice - Alter priorities for processes
- renice - Alter the priorities of an already running process
- sleep - Delay for specified time
- time - Time a command
- wait - Wait for the specified process's exit status
Background Processing
- & - Run process in background
- fg - Send job to foreground (interactive)
- bg - Send job to background, as if started with &
- | - Pipe standard output of first program to standard input of second
User Management and Support
- chsh - Change user shell
- finger - Get details about user
- id - Print real/effective UIDs/GIDs
- last - Show listing of last logged in users
- lastlog - Show last log in information for users
- locale - Get locale specific information
- localedef - Compile locale definitions
- logname - Print user's login name
- man - Manual browser
- mesg - Control write access to your terminal
- passwd - Change user password
- su - Start a new process as a different user (defaults to root)
- sudo - Execute a command as a different user
- users - Show who is logged on (only user names)
- w - Show logged-in users and their current tasks
- whatis - Command description from whatis database
- whereis - Locate the command's binary and manual pages
- which - Locate where a command is executed from
- who - Show who is logged on (with some details)
- write - Send a message to another user
Development and Compilation Tools
- as - GNU assembler tool
- c99 - C programming language compiler
- cc - C compiler
- gcc - GNU Compiler Collection C frontend
- f77 - Fortran 77 compiler
- dbx - (System V and BSD) Symbolic debugger
- gdb - GNU symbolic debugger
- ld - Program linker
- lex - Lexical scanner generator
- m4 - Macro language
- make - Automate builds
- nm - List symbols from object files
- size - Return the size of the sections of an ELF file
- ltrace - (Linux) Trace dynamic library calls
- strace - (Linux) or
truss(Solaris) Trace system calls with arguments and signals
This reference guide will be continuously updated as new commands and examples are discovered.