Basic Commands
pwd
– Print the current working directory.- Example:
pwd
- Example:
cd
– Change the current directory.- Example:
cd /home/user
- Example:
ls
– List directory contents.- Example:
ls -l
- Example:
cp
– Copy files or directories.- Example:
cp file.txt /home/user/backup/
- Example:
mv
– Move/rename files or directories.- Example:
mv oldname.txt newname.txt
- Example:
rm
– Remove files or directories.- Example:
rm file.txt
- Example:
mkdir
– Create a new directory.- Example:
mkdir newdir
- Example:
rmdir
– Remove an empty directory.- Example:
rmdir olddir
- Example:
touch
– Create a new empty file or update the timestamp of an existing file.- Example:
touch newfile.txt
- Example:
cat
– Concatenate and display file contents.- Example:
cat file.txt
- Example:
File Viewing
less
– View file contents one screen at a time.- Example:
less file.txt
- Example:
more
– View file contents one screen at a time (less advanced thanless
).- Example:
more file.txt
- Example:
head
– Display the first lines of a file.- Example:
head -n 10 file.txt
- Example:
tail
– Display the last lines of a file.- Example:
tail -n 10 file.txt
- Example:
nano
– Simple text editor in the terminal.- Example:
nano file.txt
- Example:
vim
– Advanced text editor in the terminal.- Example:
vim file.txt
- Example:
grep
– Search text using patterns.- Example:
grep "pattern" file.txt
- Example:
find
– Search for files in a directory hierarchy.- Example:
find /home/user -name "*.txt"
- Example:
diff
– Compare files line by line.- Example:
diff file1.txt file2.txt
- Example:
wc
– Word, line, character, and byte count.- Example:
wc file.txt
- Example:
File Permissions
chmod
– Change file modes or Access Control Lists.- Example:
chmod 755 script.sh
- Example:
chown
– Change file owner and group.- Example:
chown user:group file.txt
- Example:
chgrp
– Change group ownership.- Example:
chgrp group file.txt
- Example:
File Compression
tar
– Archive files.- Example:
tar -czvf archive.tar.gz /path/to/dir
- Example:
zip
– Compress files into a zip archive.- Example:
zip archive.zip file1 file2
- Example:
unzip
– Extract files from a zip archive.- Example:
unzip archive.zip
- Example:
gzip
– Compress files with gzip.- Example:
gzip file.txt
- Example:
gunzip
– Decompress gzip files.- Example:
gunzip file.txt.gz
- Example:
bzip2
– Compress files with bzip2.- Example:
bzip2 file.txt
- Example:
bunzip2
– Decompress bzip2 files.- Example:
bunzip2 file.txt.bz2
- Example:
System Monitoring
top
– Display system tasks.- Example:
top
- Example:
htop
– Interactive process viewer.- Example:
htop
- Example:
ps
– Report a snapshot of current processes.- Example:
ps aux
- Example:
df
– Report file system disk space usage.- Example:
df -h
- Example:
du
– Estimate file space usage.- Example:
du -sh /home/user
- Example:
free
– Display memory usage.- Example:
free -h
- Example:
uptime
– Tell how long the system has been running.- Example:
uptime
- Example:
who
– Show who is logged on.- Example:
who
- Example:
uname
– Print system information.- Example:
uname -a
- Example:
iostat
– Report CPU and I/O statistics.- Example:
iostat
- Example:
Networking
ping
– Send ICMP ECHO_REQUEST to network hosts.- Example:
ping google.com
- Example:
ifconfig
– Configure a network interface.- Example:
ifconfig eth0
- Example:
ip
– Show/manipulate routing, devices, policy routing, and tunnels.- Example:
ip addr show
- Example:
netstat
– Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.- Example:
netstat -tuln
- Example:
ss
– Another utility to investigate sockets.- Example:
ss -tuln
- Example:
wget
– Non-interactive network downloader.- Example:
wget http://example.com/file.zip
- Example:
curl
– Transfer data from or to a server.- Example:
curl -O http://example.com/file.zip
- Example:
scp
– Secure copy (remote file copy program).- Example:
scp file.txt user@remote:/path/to/dest/
- Example:
ssh
– OpenSSH SSH client (remote login program).- Example:
ssh user@remote
- Example:
ftp
– File Transfer Protocol client.- Example:
ftp ftp.example.com
- Example:
Disk Management
fdisk
– Partition table manipulator for Linux.- Example:
fdisk /dev/sda
- Example:
mkfs
– Build a Linux file system.- Example:
mkfs.ext4 /dev/sda1
- Example:
mount
– Mount a file system.- Example:
mount /dev/sda1 /mnt
- Example:
umount
– Unmount a file system.- Example:
umount /mnt
- Example:
fsck
– File system consistency check and repair.- Example:
fsck /dev/sda1
- Example:
User Management
useradd
– Create a new user.- Example:
useradd newuser
- Example:
userdel
– Delete a user account and related files.- Example:
userdel newuser
- Example:
usermod
– Modify a user account.- Example:
usermod -aG sudo newuser
- Example:
passwd
– Update a user’s authentication tokens.- Example:
passwd newuser
- Example:
groupadd
– Create a new group.- Example:
groupadd newgroup
- Example:
Package Management (Debian/Ubuntu)
apt-get
– APT package handling utility.- Example:
apt-get update
- Example:
apt-cache
– Query the APT cache.- Example:
apt-cache search package
- Example:
dpkg
– Debian package manager.- Example:
dpkg -i package.deb
- Example:
aptitude
– High-level interface to the package manager.- Example:
aptitude install package
- Example:
Package Management (Red Hat/CentOS)
yum
– Package manager for RPM-based distributions.- Example:
yum install package
- Example:
rpm
– RPM package manager.- Example:
rpm -ivh package.rpm
- Example:
dnf
– Modernized package manager for RPM-based distributions.- Example:
dnf install package
- Example:
System Control
systemctl
– Control the systemd system and service manager.- Example:
systemctl start service
- Example:
service
– Run a System V init script.- Example:
service service start
- Example:
shutdown
– Halt, power-off or reboot the machine.- Example:
shutdown -h now
- Example:
reboot
– Reboot the system.- Example:
reboot
- Example:
halt
– Halt the system.- Example:
halt
- Example:
init
– Change runlevel.- Example:
init 0
- Example:
Archive and Backup
rsync
– Remote file and directory synchronization.- Example:
rsync -av /source /destination
- Example:
dd
– Convert and copy a file.- Example:
dd if=/dev/sda of=/dev/sdb
- Example:
Text Processing
awk
– Pattern scanning and processing language.- Example:
awk '{print $1}' file.txt
- Example:
sed
– Stream editor for filtering and transforming text.- Example:
sed 's/old/new/g' file.txt
- Example:
cut
– Remove sections from each line of files.- Example:
cut -d' ' -f1 file.txt
- Example:
sort
– Sort lines of text files.- Example:
sort file.txt
- Example:
uniq
– Report or omit repeated lines.- Example:
uniq file.txt
- Example:
tr
– Translate or delete characters.- Example:
tr 'a-z' 'A-Z' < file.txt
- Example:
paste
– Merge lines of files.- Example:
paste file1.txt file2.txt
- Example:
join
– Join lines of two files on a common field.- Example:
join file1.txt file2.txt
- Example:
tee
– Read from standard input and write to standard output and files.- Example:
echo "Hello" | tee file.txt
- Example:
Disk Usage
lsblk
– List information about block devices.- Example:
lsblk
- Example:
blkid
– Locate/print block device attributes.- Example:
blkid
- Example:
df
– Report file system disk space usage.- Example:
df -h
- Example:
System Logs
dmesg
– Print or control the kernel ring buffer.- Example:
dmesg
- Example:
journalctl
– Query and display messages from the journal.- Example:
journalctl -xe
- Example:
Miscellaneous
alias
– Create an alias for a command.- Example:
alias ll='ls -l'
- Example:
unalias
– Remove an alias.- Example:
unalias ll
- Example:
env
– Run a program in a modified environment.- Example:
env VAR=value command
- Example:
printenv
– Print all or part of environment.- Example:
printenv PATH
- Example:
export
– Set an environment variable.- Example:
export PATH=/usr/local/bin:$PATH
- Example:
date
– Display or set the system date and time.- Example:
date "+%Y-%m-%d %H:%M:%S"
- Example:
cal
– Display a calendar.- Example:
cal
- Example:
whoami
– Print effective user ID.- Example:
whoami
- Example:
hostname
– Show or set the system’s hostname.- Example:
hostname
- Example:
clear
– Clear the terminal screen.- Example:
clear
- Example:
history
– Show the command history. – Example:history