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