File Operations
ls: Lists all files and directories in the current directory.
ls -R: Lists files in the current directory and its sub-directories.
ls -a: Shows hidden files (files starting with a dot).
ls -al: Lists files and directories with detailed information such as permissions, size,
and owner.
cd directoryname: Changes the current directory to directoryname.
cd ..: Moves one level up in the directory hierarchy.
pwd: Displays the full path of the current working directory.
cat > filename: Creates a new file named filename.
cat filename: Displays the contents of filename.
cat file1 file2 > file3: Joins file1 and file2, and writes the output to file3.
touch filename: Creates a new empty file named filename, or updates the file's
timestamp if it already exists.
rm filename: Deletes the file named filename.
cp source destination: Copies files or directories from source to destination.
mv source destination: Moves or renames files or directories from source to
destination.
find / -name filename: Searches for a file or directory named filename starting
from the root directory.
file filename: Determines the type of filename.
less filename: Views the contents of filename page by page, allowing for
navigation.
head filename: Displays the first ten lines of filename.
tail filename: Displays the last ten lines of filename.
lsof: Lists open files and the processes that have them open.
du -h --max-depth=1: Shows the size of each directory within the current directory,
limited to immediate children.
fdisk: Manages disk partitions.
Directory Operations
mkdir directoryname: Creates a new directory named directoryname in the
current working directory.
rmdir directoryname: Deletes the directory named directoryname.
cp -r source destination: Recursively copies directories from source to
destination.
mv olddir newdir: Renames the directory olddir to newdir.
find / -type d -name directoryname: Searches for a directory named
directoryname starting from the root directory.
Process Operations
ps: Displays currently active processes for the user.
top: Shows a real-time list of all running processes.
kill pid: Terminates the process with the specified process ID (pid).
pkill name: Terminates processes by their name.
bg: Resumes suspended jobs in the background without bringing them to the
foreground.
fg: Brings the most recent job to the foreground.
fg n: Brings job number n to the foreground.
renice +n [pid]: Adjusts the priority of the running process with the specified pid.
&> filename: Redirects both standard output (stdout) and standard error (stderr)
to the file named filename.
1> filename: Redirects standard output (stdout) to the file named filename.
2> filename: Redirects standard error (stderr) to the file named filename.
File Permissions
chmod octal filename: Changes the permissions of filename to the specified octal
value (0 to 7), where 0 means no permissions and 7 means full permissions.
chown ownername filename: Changes the owner of filename to ownername.
chgrp groupname filename: Changes the group ownership of filename to
groupname.
Networking
ping host: Sends ICMP echo requests to host and displays the results, helping to
check connectivity.
whois domain: Retrieves and displays WHOIS information for the specified domain.
dig domain: Fetches DNS information for the given domain.
netstat -pnltu: Displays various network-related information including network
connections, routing tables, and interface statistics.
ifconfig: Shows IP addresses and other details of all network interfaces.
ssh user@host: Establishes a remote login session to host as the specified user.
scp source destination: Securely transfers files between hosts over SSH.
wget url: Downloads files from the web using the specified url.
curl url: Sends a request to the url and returns the response, useful for interacting
with web services.
traceroute domain: Traces and displays the route that packets take to reach the
specified domain.
mtr domain: Combines the functionality of traceroute and ping to provide a
continuous network diagnostic tool.
ss: Investigates sockets, serving as a modern alternative to netstat.
nmap: A network exploration tool and security scanner for discovering hosts and
services on a network.
Archives and Compression
tar cf file.tar files: Creates a tar archive named file.tar containing the
specified files.
tar xf file.tar: Extracts the contents of the file.tar archive.
gzip file: Compresses file and renames it to file.gz.
gzip -d file.gz: Decompresses file.gz back to file.
zip -r file.zip files: Creates a zip archive named file.zip containing the
specified files.
unzip file.zip: Extracts the contents of the file.zip archive.
Text Processing
grep pattern files: Searches for pattern in the specified files.
grep -r pattern dir: Searches recursively for pattern within the specified dir.
command | grep pattern: Pipes the output of command to grep for searching the
specified pattern.
echo 'text': Prints the specified text to the terminal.
sed 's/string1/string2/g' filename: Replaces occurrences of string1 with
string2 in the filename.
diff file1 file2: Compares file1 and file2, displaying the differences between
them.
wc filename: Counts the number of lines, words, and characters in the specified
filename.
awk: A versatile programming language used for pattern scanning and processing
within files.
sed -i 's/string1/string2/g' filename: Replaces string1 with string2 in
filename, with the -i option editing the file in-place.
cut -d':' -f1 /etc/passwd: Extracts the first field of each line from
/etc/passwd, using colon (:) as the field delimiter.
Disk Usage
df: Displays disk space usage for all mounted filesystems.
du: Shows the disk space usage for directories and their contents.
free: Displays memory and swap usage.
whereis app: Shows possible locations of the app executable.
System Info
date: Displays the current date and time.
cal: Shows the calendar for the current month.
uptime: Displays how long the system has been running.
w: Displays information about users currently logged in and their activities.
whoami: Shows the username of the current user.
uname -a: Displays detailed information about the system's kernel.
df -h: Displays disk usage in a human-readable format (e.g., GB, MB).
du -sh: Shows the disk usage of the current directory in a human-readable format.
free -m: Displays memory and swap usage in megabytes (MB).
Package Installations
sudo apt-get update: Updates the package lists for upgrades and new package
installations.
sudo apt-get upgrade: Upgrades all packages that have available updates.
sudo apt-get install pkgname: Installs the specified package pkgname.
sudo apt-get remove pkgname: Removes the specified package pkgname from the
system.
Environment Variables
env: Displays all environment variables currently set in the session.
echo $VARIABLE: Shows the value of the specified environment variable.
export VARIABLE=value: Sets the value of the specified environment variable.
alias new_command='old_command options': Creates a new command
new_command that executes old_command with the specified options.
echo $PATH: Prints the current value of the PATH environment variable.
export PATH=$PATH:/new/path: Adds /new/path to the existing PATH environment
variable.