Comprehensive list of the top 100 Linux commands with detailed descriptions and usage examples is quite extensive. Below is a subset of this list, showcasing some of the most useful commands for both developers and regular users. Each command includes a description and examples of its usage.
SSH (Secure Shell) is used to securely connect to a remote machine.
- is program for logging into a remote machine and for executing commands on a remote machine. It is intended to provide secure encrypted communi‐ cations between two untrusted hosts over an insecure network. X11 connections, ar‐ bitrary TCP ports and UNIX-domain sockets can also be forwarded over the secure channel.
# Connect to a remote server
ssh username@hostname
# Connect using a specific port
ssh -p 2222 username@hostnameChanges the current directory.
# Change to the home directory
cd ~
# Change to the /etc directory
cd /etc
# Go up one directory level
cd ..Lists directory contents.
- list information about the FILEs (the current directory by default). Sort en‐ tries alphabetically if none of -cftuvSUX nor --sort is specified.
# List files in the current directory
ls
# List all files, including hidden files
ls -a
# List files with detailed information
ls -lPrint the full filename of the current working directory.
pwdNano is a simple, easy-to-use text editor.
- is a small and friendly editor. It copies the look and feel of Pico, but is free software, and implements several features that Pico lacks, such as: opening multiple files, scrolling per line, undo/redo, syntax coloring, line numbering, and soft-wrapping overlong lines.
# Open a file in nano
nano filename.txt
# Save changes and exit
Ctrl + O, Enter, Ctrl + XVim is a powerful text editor.
- is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.
There are a lot of enhancements above Vi: multi level undo, multi windows and buffers, syntax highlighting, command line editing, filename completion, on-line help, visual selection, etc.. See ":help vi_diff.txt" for a summary of the dif‐ ferences between Vim and Vi
# Open a file in vim
vim filename.txt
# Enter insert mode
i
# Save changes and exit
:wqCopies files and directories. Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
# Copy a file
cp source.txt destination.txt
# Copy a directory recursively
cp -r source_dir destination_dirMoves or renames files and directories. Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
# Move a file
mv source.txt destination.txt
# Rename a file
mv oldname.txt newname.txtRemoves files or directories.
# Remove a file
rm filename.txt
# Remove a directory and its contents
rm -r directory_nameChanges file permissions. Change the mode of each FILE to MODE. With --reference, change the mode of each FILE to that of RFILE.
# Make a file executable
chmod +x script.sh
# Set specific permissions
chmod 755 filename.txtChanges file owner and group.
- changes the user and/or group ownership of each given file.
# Change the owner of a file
chown username filename.txt
# Change the owner and group of a directory recursively
chown -R username:group directory_nameDisplays information about running processes.
- displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top instead
# Display all running processes
ps aux
# Display processes for a specific user
ps -u username
# To see every process running as root
ps -U root -u root uSends a signal to terminate a process.
- The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in three ways: -9, -SIGKILL or -KILL.
# Kill a process by PID
kill 1234
# Force kill a process
kill -9 1234Displays real-time system information including processes.
- program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts
topAn interactive process viewer.
- is a cross-platform ncurses-based process viewer. It is similar to top, but allows you to scroll vertically and horizontally, and interact using a pointing device (mouse). You can observe all processes running on the system, along with their command line arguments, as well as view them in a tree for‐ mat, select multiple processes and acting on them all at once.
htopReports disk space usage.
- displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
# Display disk usage in human-readable format
df -hEstimates file space usage.
- Summarize disk usage of the set of FILEs, recursively for directories
# Display the size of the current directory and subdirectories
du -h
# Display the size of a specific directory
du -sh directory_nameArchives files.
- is an archiving program designed to store multiple files in a single file (anarchive), and to manipulate such archives. The archive can be either a regular file or a device (e.g. a tape drive, hence the name of the program, which stands for tapearchiver), which can be located either on the local or on a remote machine
# Create a tar archive
tar -cvf archive.tar file1 file2
# Extract a tar archive
tar -xvf archive.tar
# Create a gzipped tar archive
tar -czvf archive.tar.gz file1 file2
# Extract a gzipped tar archive
tar -xzvf archive.tar.gzCompresses files.
- reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. (The default extension is z for MS‐ DOS, OS/2 FAT, Windows NT FAT and Atari.) If no files are specified, or if a file name is "-", the standard input is compressed to the standard output. Gzip will only attempt to compress regular files. In particular, it will ignore symbolic links.
# Compress a file
gzip filename.txt
# Decompress a file
gunzip filename.txt.gzSearches for files in a directory hierarchy.
- searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the out‐ come is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name. If no starting-point is specified, `.' is assumed
# Find a file by name
find /path/to/search -name filename.txt
# Find files modified in the last 7 days
find /path/to/search -mtime -7Searches for patterns in files.
- searches for PATTERNS in each FILE. PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern. Typically PATTERNS should be quoted when grep is used in a shell command.
# Search for a pattern in a file
grep 'pattern' filename.txt
# Search recursively in all files in a directory
grep -r 'pattern' /path/to/searchConcatenates and displays file content.
# Display file content
cat filename.txt
# Concatenate multiple files and display the output
cat file1.txt file2.txtViews file content one page at a time.
- is a program similar to more(1), but it has many more features. Less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi(1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.)
# View a file
less filename.txt
# Scroll forward and backward
# Forward: Space or f
# Backward: bDisplays the last part of a file.
- Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name
# Display the last 10 lines of a file
tail filename.txt
# Display the last 50 lines of a file
tail -n 50 filename.txt
# Follow a file (useful for logs)
tail -f filename.txtDisplays the first part of a file.
# Display the first 10 lines of a file
head filename.txt
# Display the first 20 lines of a file
head -n 20 filename.txtA powerful text processing language.
# Print the first column of a file
awk '{print $1}' filename.txt
# Print lines where the second column is greater than 100
awk '$2 > 100' filename.txtA stream editor for filtering and transforming text.
# Replace 'old' with 'new' in a file
sed 's/old/new/g' filename.txt
# Delete lines containing a pattern
sed '/pattern/d' filename.txtSecurely copies files between hosts.
# Copy a file to a remote host
scp localfile.txt username@remotehost:/path/to/remote/directory
# Copy a file from a remote host
scp username@remotehost:/path/to/remotefile.txt localfile.txtA fast and versatile file copying tool.
# Synchronize a local directory with a remote directory
rsync -avz /path/to/local/directory username@remotehost:/path/to/remote/directory
# Synchronize a remote directory with a local directory
rsync -avz username@remotehost:/path/to/remote/directory /path/to/local/directoryA non-interactive network downloader.
# Download a file from a URL
wget http://example.com/file.zip
# Download a file and save it with a different name
wget -O newfile.zip http://example.com/file.zipA tool for transferring data from or to a server.
# Download a file from a URL
curl -O http://example.com/file.zip
# Download a file and save it with a different name
curl -o newfile.zip http://example.com/file.zipA package handling utility for Debian-based systems.
# Update the package index
sudo apt-get update
# Install a package
sudo apt-get install package_name
# Remove a package
sudo apt-get remove package_nameA package manager for RPM-based distributions.
# Install a package
sudo yum install package_name
# Remove a package
sudo yum remove package_name
# Update all packages
sudo yum updateA package manager for Python packages.
# Install a package
pip install package_name
# Uninstall a package
pip uninstall package_name
# List installed packages
pip listA platform for developing,
shipping, and running applications in containers.
# Pull an image from the Docker repository
docker pull image_name
# Run a container from an image
docker run image_name
# List running containers
docker ps
# Stop a running container
docker stop container_idControls the systemd system and service manager.
# Start a service
sudo systemctl start service_name
# Stop a service
sudo systemctl stop service_name
# Enable a service to start at boot
sudo systemctl enable service_name
# Disable a service from starting at boot
sudo systemctl disable service_name
# Check the status of a service
sudo systemctl status service_nameQueries and displays logs from journald.
# View all logs
sudo journalctl
# View logs for a specific service
sudo journalctl -u service_name
# Follow new log entries
sudo journalctl -fPrints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
# Display all network connections
netstat -a
# Display listening ports
netstat -l
# Display network statistics
netstat -sUtility to investigate sockets.
# Display all open TCP connections
ss -t
# Display all open UDP connections
ss -u
# Display listening sockets
ss -lConfigures network interfaces.
# Display network interface information
ifconfig
# Assign an IP address to an interface
sudo ifconfig eth0 192.168.1.100Shows/manipulates routing, devices, policy routing, and tunnels.
# Display network interfaces
ip a
# Assign an IP address to an interface
sudo ip addr add 192.168.1.100/24 dev eth0
# Display routing table
ip routeSends ICMP ECHO_REQUEST packets to network hosts.
# Ping a host
ping hostname
# Ping a host with a specified number of packets
ping -c 4 hostnamePrints the route packets take to the network host.
# Trace the route to a host
traceroute hostnameQueries the Domain Name System (DNS) to obtain domain name or IP address mapping.
# Look up the IP address of a domain
nslookup domain.comDNS lookup utility.
# Perform a DNS lookup
dig domain.com
# Perform a reverse DNS lookup
dig -x ip_addressShows or sets the system's hostname.
# Display the hostname
hostname
# Set a new hostname
sudo hostname new_hostnameDisplays the current username.
whoamiExecutes a command as another user, typically the superuser.
# Run a command as the superuser
sudo command
# Edit a file with superuser privileges using nano
sudo nano filename.txtChanges a user's password.
# Change your own password
passwd
# Change another user's password (superuser only)
sudo passwd usernameAdds a user to the system.
# Add a new user
sudo adduser usernameModifies a user account.
# Add a user to a group
sudo usermod -aG groupname usernameRemoves a user from the system.
# Remove a user
sudo deluser usernameAdds a new group.
# Add a new group
sudo groupadd groupnameDeletes a group.
# Delete a group
sudo groupdel groupnameSchedules periodic jobs.
# Edit the current user's crontab
crontab -e
# List the current user's scheduled jobs
crontab -lSchedules a command to run at a specific time.
# Schedule a command to run at a specific time
echo "command" | at 10:00Shows how long the system has been running.
uptimeDisplays memory usage.
# Display memory usage in human-readable format
free -hReports virtual memory statistics.
# Display virtual memory statistics
vmstatReports CPU and I/O statistics.
# Display CPU and I/O statistics
iostatPrints kernel ring buffer messages.
# Display all messages
dmesg
# Display messages and follow new ones
dmesg -wLists information about block devices.
# Display block devices
lsblkLocates and prints block device attributes.
# Display block device attributes
blkidMounts a filesystem.
# Mount a filesystem
sudo mount /dev/sdX1 /mntUnmounts a filesystem.
# Unmount a filesystem
sudo umount /mntManipulates disk partition table.
# View and edit disk partitions
sudo fdisk /dev/sdXBuilds a Linux filesystem.
# Create an ext4 filesystem
sudo mkfs.ext4 /dev/sdX1Checks and repairs a Linux filesystem.
# Check and repair a filesystem
sudo fsck /dev/sdX1Converts and copies a file.
# Create a bootable USB drive
sudo dd if=path/to/image.iso of=/dev/sdX bs=4M status=progressA partition manipulation program.
# Start parted on a disk
sudo parted /dev/sdXProvides fast, secure, and scalable system logging.
# Restart rsyslog service
sudo systemctl restart rsyslogRotates, compresses, and mails system logs.
# Manually rotate logs
sudo logrotate /etc/logrotate.confControls the system hostname.
# Set the system hostname
sudo hostnamectl set-hostname new_hostnameControls system time and date.
# Display current time settings
timedatectl
# Set the system timezone
sudo timedatectl set-timezone America/New_YorkAccesses the hardware clock.
# Display the current hardware clock time
sudo hwclock
# Set the hardware clock to the current system time
sudo hwclock --systohcDisplays or sets the system date and time.
# Display the current date and time
date
# Set the date and time
sudo date MMDDhhmmYYYYAn arbitrary precision calculator language.
# Start bc interactive calculator
bcEvaluates expressions.
# Perform arithmetic operations
expr 2 + 2Builds and executes command lines from standard input.
# Use with find to delete files
find /path/to/search -name "*.tmp" | xargs rmCreates an alias for a command.
# Create an alias
alias ll='ls -la'
# Remove an alias
unalias llDisplays a line of text.
# Print a string
echo "Hello, World!"
# Print the value of a variable
echo $HOMEDisplays or modifies the environment.
# Display all environment variables
env
# Run a command with modified environment variables
env VAR=value commandSets environment variables.
# Set an environment variable
export VAR=value
# Export a variable to the environment
export PATH=$PATH:/new/pathExecutes commands from a file in the current shell.
# Source a script
source script.shDisplays the command history.
# Display command history
history
# Clear command history
history -cCreates an alias for a command.
# Create an alias
alias ll='ls -la'
# Remove an alias
unalias llDisplays the manual for a command.
# Display the manual for ls
man lsDisplays the information about commands.
# Display the info for ls
info lsDisplays a one-line description of a command.
# Display a one-line description of ls
whatis lsSearches the manual pages for a keyword.
# Search for a keyword in the manual pages
apropos keywordLocates the binary, source, and manual page files for a command.
# Locate the files for ls
whereis lsLocates the executable file associated with a command.
# Locate the executable for ls
which lsDescribes a command.
# Describe the ls command
type lsExecutes commands in the Bourne shell.
# Run a shell script
sh script.shExecutes commands in the Bourne-again shell.
# Run a shell script
bash script.shExecutes commands in the Z shell.
# Run a shell script
zsh script.shExecutes commands in the Korn shell.
# Run a shell script
ksh script.shExecutes commands in the Debian Almquist shell.
# Run a shell script
dash script.shA terminal multiplexer.
# Start a new screen session
screen
# Reattach to a detached screen session
screen -rA terminal multiplexer.
# Start a new tmux session
tmux
# Reattach to a detached tmux session
tmux attach