
Basic Commands
1. ls
• Usage: Lists directory contents.
• Example: ls (lists files in the current directory).
2. cd
• Usage: Changes the current directory.
• Example: cd /home/user (changes to the /home/user directory).
3. pwd
• Usage: Prints the current working directory.
• Example: pwd (displays the current directory path).
4. mkdir
• Usage: Creates a new directory.
• Example: mkdir new_directory (creates a directory named new_directory).
5. rmdir
• Usage: Removes an empty directory.
• Example: rmdir old_directory (removes the directory old_directory).
6. mv
• Usage: Moves or renames files or directories.
• Example: mv oldname newname (renames oldname to newname).
7. cp
• Usage: Copies files or directories.
• Example: cp source destination (copies source to destination).
8. open
• Usage: Opens files or directories (mostly used in macOS).
• Example: open filename (opens the file named filename).
9. touch
• Usage: Creates an empty file or updates the timestamp of an existing file.
• Example: touch newfile (creates a new empty file named newfile).
10. find
• Usage: Searches for files and directories.
• Example: find /path -name filename (finds filename in the specified path).
11. ln
• Usage: Creates hard and symbolic links.
• Example: ln -s target linkname (creates a symbolic link linkname to target).
Compression and Archiving
gzip- Usage: Compresses files.
- Example:
gzip filename(compressesfilename).
gunzip- Usage: Decompresses files.
- Example:
gunzip filename.gz(decompressesfilename.gz).
tar- Usage: Archives files.
- Example:
tar -cvf archive.tar directory(creates an archivearchive.tarof thedirectory).
Customization and Viewing Files
alias- Usage: Creates shortcuts for commands.
- Example:
alias ll='ls -la'(creates an aliasllforls -la).
cat- Usage: Concatenates and displays file contents.
- Example:
cat filename(displays the contents offilename).
less- Usage: Views file contents one screen at a time.
- Example:
less filename(opensfilenamefor viewing).
tail- Usage: Displays the last part of a file.
- Example:
tail filename(displays the last 10 lines offilename).
wc- Usage: Prints newline, word, and byte counts for files.
- Example:
wc filename(displays the line, word, and byte count offilename).
Searching and Sorting
grep- Usage: Searches text using patterns.
- Example:
grep 'pattern' filename(searches forpatterninfilename).
sort- Usage: Sorts lines of text files.
- Example:
sort filename(sorts the lines infilename).
Manual Pages
man- Usage: Displays the manual page for a command.
- Example:
man ls(shows the manual for thelscommand).
Networking and Connectivity
ping- Usage: Checks the network connection to a server.
- Example:
ping example.com(sends ICMP ECHO_REQUEST to network hosts).
ifconfig- Usage: Configures network interfaces.
- Example:
ifconfig eth0(displays the configuration ofeth0).
wget- Usage: Downloads files from the internet.
- Example:
wget http://example.com/file(downloadsfilefrom the specified URL).
curl- Usage: Transfers data from or to a server.
- Example:
curl http://example.com(retrieves the content from the URL).
System Information
uname- Usage: Prints system information.
- Example:
uname -a(displays all system information).
df- Usage: Reports file system disk space usage.
- Example:
df -h(shows disk space in human-readable format).
du- Usage: Estimates file space usage.
- Example:
du -sh directory(displays the total size of the directory).
top- Usage: Displays tasks and system status.
- Example:
top(shows an ongoing view of system processes).
ps- Usage: Reports a snapshot of current processes.
- Example:
ps aux(displays detailed information about all running processes).
uptime- Usage: Tells how long the system has been running.
- Example:
uptime(displays the current time, uptime, number of users, and load averages).
User and Permission Management
chmod- Usage: Changes file permissions.
- Example:
chmod 755 filename(sets the permissions offilenameto 755).
chown- Usage: Changes file owner and group.
- Example:
chown user:group filename(changes the owner and group offilename).
passwd- Usage: Changes a user’s password.
- Example:
passwd(prompts to change the current user’s password).
useradd- Usage: Creates a new user.
- Example:
useradd newuser(creates a new user namednewuser).
usermod- Usage: Modifies a user account.
- Example:
usermod -aG groupname username(addsusernametogroupname).
userdel- Usage: Deletes a user account.
- Example:
userdel username(deletes the userusername).
Package Management (Debian-based systems)
apt-get- Usage: Handles packages.
- Example:
apt-get update(updates the package lists).
apt-cache- Usage: Searches for packages.
- Example:
apt-cache search package_name(searches forpackage_name).
dpkg- Usage: Handles individual package files.
- Example:
dpkg -i package.deb(installspackage.deb).
Process Management
kill- Usage: Terminates processes.
- Example:
kill PID(sends a signal to terminate the process withPID).
killall- Usage: Kills processes by name.
- Example:
killall processname(terminates all instances ofprocessname).
pkill- Usage: Kills processes by name or attribute.
- Example:
pkill -u username(kills all processes owned byusername).
Text Processing
awk- Usage: Pattern scanning and processing language.
- Example:
awk '{print $1}' filename(prints the first column fromfilename).
sed- Usage: Stream editor for filtering and transforming text.
- Example:
sed 's/old/new/g' filename(replacesoldwithnewinfilename).
tr- Usage: Translates or deletes characters.
- Example:
echo "text" | tr 'a-z' 'A-Z'(converts lowercase to uppercase).
Miscellaneous
echo- Usage: Displays a line of text.
- Example:
echo "Hello, World!"(printsHello, World!to the terminal).
date- Usage: Displays or sets the system date and time.
- Example:
date(shows the current date and time).
history- Usage: Displays the command history.
- Example:
history(shows the list of previously executed commands).
clear- Usage: Clears the terminal screen.
- Example:
clear(clears the screen).
File Manipulation
head- Usage: Displays the beginning of a file.
- Example:
head -n 10 filename(shows the first 10 lines offilename).
diff- Usage: Compares files line by line.
- Example:
diff file1 file2(comparesfile1andfile2).
cmp- Usage: Compares two files byte by byte.
- Example:
cmp file1 file2(checks iffile1andfile2are identical).
Disk Usage and Management
fdisk- Usage: Manipulates disk partition table.
- Example:
fdisk /dev/sda(opensfdiskto manage partitions on/dev/sda).
mount- Usage: Mounts a filesystem.
- Example:
mount /dev/sda1 /mnt(mounts/dev/sda1to/mnt).
umount- Usage: Unmounts a filesystem.
- Example:
umount /mnt(unmounts the filesystem mounted at/mnt).
Archive Manipulation
zip- Usage: Compresses files into a ZIP archive.
- Example:
zip archive.zip file1 file2(createsarchive.zipcontainingfile1andfile2).
unzip- Usage: Extracts files from a ZIP archive.
- Example:
unzip archive.zip(extracts the contents ofarchive.zip).
System Monitoring
htop- Usage: An interactive process viewer (similar to
topbut more user-friendly). - Example:
htop(opens the interactive process viewer).
- Usage: An interactive process viewer (similar to
iostat- Usage: Reports CPU and I/O statistics.
- Example:
iostat(displays I/O statistics).
vmstat- Usage: Reports virtual memory statistics.
- Example:
vmstat(displays virtual memory statistics).
Permissions and Ownership
chgrp- Usage: Changes the group ownership of files.
- Example:
chgrp groupname filename(changes the group offilenametogroupname).
umask- Usage: Sets the default file creation permissions.
- Example:
umask 022(sets the default file creation permissions to755).
Process Control
bg- Usage: Resumes a suspended job in the background.
- Example:
bg %1(resumes job number 1 in the background).
fg- Usage: Brings a background job to the foreground.
- Example:
fg %1(brings job number 1 to the foreground).
SSH and Remote Management
ssh- Usage: Connects to a remote machine securely.
- Example:
ssh user@hostname(connects tohostnameasuser).
scp- Usage: Securely copies files between hosts.
- Example:
scp file user@hostname:/path(copiesfileto/pathonhostname).
rsync- Usage: Synchronizes files and directories between two locations.
- Example:
rsync -avz source destination(synchronizessourcetodestination).
Cron Jobs
crontab- Usage: Schedules periodic background tasks.
- Example:
crontab -e(edits the current user’s cron jobs).
Text Editors
nano- Usage: A simple text editor.
- Example:
nano filename(opensfilenamein the nano editor).
vi/vim- Usage: A powerful text editor.
- Example:
vi filename(opensfilenamein the vi editor).
Other Useful Commands
xargs- Usage: Builds and executes command lines from standard input.
- Example:
echo file1 file2 | xargs rm(removesfile1andfile2).
tee- Usage: Reads from standard input and writes to standard output and files.
- Example:
echo "text" | tee file(writestexttofileand displays it).
nohup- Usage: Runs a command immune to hangups.
- Example:
nohup command &(runscommandin the background and allows it to continue running after logging out).
watch- Usage: Executes a program periodically and displays output.
- Example:
watch -n 1 df -h(runsdf -hevery second).
basename- Usage: Strips directory and suffix from filenames.
- Example:
basename /path/to/file(returnsfile).
dirname- Usage: Strips the last component from file names.
- Example:
dirname /path/to/file(returns/path/to).
file- Usage: Determines the file type.
- Example:
file filename(displays the type offilename).
Advanced File Operations
split- Usage: Splits a file into pieces.
- Example:
split -b 1M largefile(splitslargefileinto 1MB chunks).
shred- Usage: Securely deletes a file by overwriting it.
- Example:
shred -u filename(overwrites and deletesfilename).
Advanced Text Processing
cut- Usage: Removes sections from each line of files.
- Example:
cut -d':' -f1 /etc/passwd(displays the first field of/etc/passwd).
paste- Usage: Merges lines of files.
- Example:
paste file1 file2(merges lines offile1andfile2).
uniq- Usage: Reports or omits repeated lines.
- Example:
uniq filename(removes duplicate lines fromfilename).
join- Usage: Joins lines of two files on a common field.
- Example:
join file1 file2(joins lines offile1andfile2with a common field).
Disk and File System Management
fsck- Usage: Checks and repairs a Linux file system.
- Example:
fsck /dev/sda1(checks and repairs the file system on/dev/sda1).
mkfs- Usage: Builds a Linux file system.
- Example:
mkfs -t ext4 /dev/sda1(creates an ext4 file system on/dev/sda1).
blkid- Usage: Locates and prints block device attributes.
- Example:
blkid(displays attributes of all block devices).
lsblk- Usage: Lists information about block devices.
- Example:
lsblk(displays block devices).
System Performance
nice- Usage: Runs a command with modified scheduling priority.
- Example:
nice -n 10 command(runscommandwith a niceness of 10).
renice- Usage: Alters the priority of running processes.
- Example:
renice 10 -p PID(changes the priority of the process withPIDto 10).
dstat- Usage: Versatile resource statistics.
- Example:
dstat(provides a detailed view of system resource usage).
Networking
netstat- Usage: Prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
- Example:
netstat -tuln(displays listening ports).
traceroute- Usage: Prints the route packets take to the network host.
- Example:
traceroute example.com(shows the route toexample.com).
nslookup- Usage: Queries Internet name servers interactively.
- Example:
nslookup example.com(looks up the IP address forexample.com).
iptables- Usage: Administers IP packet filter rules.
- Example:
iptables -L(lists all current rules).
nmap- Usage: Network exploration tool and security scanner.
- Example:
nmap -sP 192.168.1.0/24(scans the network for active devices).
Backup and Restore
rsnapshot- Usage: Filesystem snapshot utility.
- Example:
rsnapshot hourly(creates an hourly snapshot).
dd- Usage: Converts and copies a file.
- Example:
dd if=/dev/sda of=/path/to/backup.img(creates a disk image of/dev/sda).
File Integrity
md5sum- Usage: Computes and checks MD5 hash.
- Example:
md5sum filename(outputs the MD5 hash offilename).
sha256sum- Usage: Computes and checks SHA-256 hash.
- Example:
sha256sum filename(outputs the SHA-256 hash offilename).
Scripting and Automation
cron- Usage: Daemon to execute scheduled commands.
- Example:
crontab -l(lists the cron jobs).
at- Usage: Schedules commands to run at a particular time.
- Example:
echo "command" | at now + 5 minutes(schedulescommandto run in 5 minutes).
System Logs
dmesg- Usage: Prints the message buffer of the kernel.
- Example:
dmesg(displays kernel messages).
journalctl- Usage: Queries and displays messages from the journal.
- Example:
journalctl -xe(shows the system log with detailed output).
logrotate- Usage: Rotates, compresses, and mails system logs.
- Example:
logrotate /etc/logrotate.conf(runs the logrotate configuration).
Virtualization and Containers
docker- Usage: Manages Docker containers.
- Example:
docker ps(lists running Docker containers).
vagrant- Usage: Builds and manages virtual machine environments.
- Example:
vagrant up(starts the Vagrant environment).
Miscellaneous
screen- Usage: Terminal multiplexer that allows for multiple sessions within a single terminal window.
- Example:
screen(starts a new screen session).
tmux- Usage: Terminal multiplexer that lets you switch between several programs in one terminal.
- Example:
tmux(starts a new tmux session).
bc- Usage: Command-line calculator.
- Example:
echo "scale=2; 3/7" | bc(calculates3/7to two decimal places).
expr- Usage: Evaluates expressions.
- Example:
expr 1 + 2(returns3).
