Linux provides a rich set of commands for managing the system, files, networking, processes, and much more. Below are some of the commonly used Linux commands and their explanations:
File and
Directory Management
- ls – List directory contents.
ls
ls -l # Long format
ls -a # Show hidden files
ls -lh # Long format with human-readable file
sizes
- cd – Change directory.
cd
/path/to/directory
cd .. # Move to parent directory
cd ~ # Move to home directory
- pwd – Print the current working directory.
pwd
- mkdir – Create a new directory.
mkdir
new_directory
- rmdir – Remove an empty directory.
rmdir
directory_name
- rm – Remove files or directories.
rm file_name
rm -r
directory_name # To remove non-empty
directory
rm -rf
directory_name # Force remove without
confirmation
- cp – Copy files or directories.
cp source_file destination_file
cp -r source_dir
destination_dir # Copy a directory
- mv – Move or rename files and directories.
mv old_name
new_name
mv file_name
/path/to/destination/
- find – Search for files in a directory hierarchy.
find
/path/to/directory -name "filename"
find / -type f
-name "*.txt" # Search for
.txt files
File Permissions
- chmod – Change file permissions.
chmod 755
file_name # Read, write, execute for
owner; read, execute
for group and
others
chmod u+x
file_name # Add execute permission for
user
- chown – Change file ownership.
chown user:group
file_name
chown -R
user:group directory_name # Change
ownership recursively
- chgrp – Change group ownership of a file or
directory.
chgrp group_name
file_name
Process
Management
- ps – Display information about running processes.
ps aux # Show all running processes
ps -ef # Full-format listing
- top – Display dynamic real-time system information
(e.g., CPU, memory usage).
top
- htop – Interactive process viewer (enhanced version
of top).
htop
- kill – Terminate a process.
kill
<PID> # Terminate process by PID
kill -9
<PID> # Force kill a process
- killall – Kill processes by name.
killall
process_name
- bg – Resume a job in the background.
bg %job_number
- fg – Bring a job to the foreground.
fg %job_number
Disk Usage and
Filesystem
- df – Display disk space usage of file systems.
df -h # Human-readable format
- du – Estimate file and directory space usage.
du -sh
/path/to/directory # Total size of a
directory
du -ah
/path/to/directory # Display all files
and directories sizes
- mount – Mount a filesystem.
mount /dev/sdX
/mnt
- umount – Unmount a filesystem.
umount /mnt
- fsck – Check and repair filesystem.
fsck /dev/sdX
Networking
- ifconfig – Display or configure network interfaces
(older tool, replaced by ip).
ifconfig
- ip – Show/manipulate routing, devices, policy
routing, and tunnels.
ip addr show # Show IP addresses
ip link show # Show network interfaces
ip route
show # Show routing table
- ping – Send ICMP ECHO_REQUEST to network hosts.
ping 8.8.8.8 # Ping a public DNS server
- netstat – Network statistics (use ss on newer systems).
netstat
-tuln # Show listening ports
- ss – Utility to investigate sockets.
ss -tuln # Show listening ports and their
status
- wget – Download files from the web.
wget
http://example.com/file.txt
- curl – Transfer data from or to a server.
curl
http://example.com
- scp – Securely copy files between hosts over SSH.
scp file_name
user@remote_host:/path/to/destination
System Monitoring
and Logs
- uptime – Show how long the system has been running.
uptime
- dmesg – Print kernel ring buffer messages (useful
for debugging).
dmesg | less
- journalctl – Query and view logs from systemd journals.
journalctl
-xe # Show system logs
- tail – View the end of a file.
tail -f
/var/log/syslog # Monitor log file in
real time
- less – View the contents of a file one page at a
time.
less
/path/to/file
- grep – Search for patterns within files.
grep "pattern"
file_name
grep -r "pattern"
/path/to/directory # Recursively search
User and Group
Management
- useradd – Add a new user.
useradd username
- usermod – Modify an existing user.
usermod -aG
groupname username # Add user to a group
- passwd – Change user password.
passwd username
- groupadd – Add a new group.
groupadd
groupname
- id – Display user and group IDs.
id username
- whoami – Display the current logged-in user.
whoami
Archive and
Compression
- tar – Archive files.
tar -cvf
archive.tar /path/to/directory # Create
archive
tar -xvf
archive.tar # Extract archive
- gzip – Compress files.
gzip file_name
- gunzip – Decompress .gz files.
gunzip
file_name.gz
- zip – Compress files into a .zip archive.
zip archive.zip
file1 file2
- unzip – Extract .zip files.
unzip archive.zip
Other Useful
Commands
- sudo – Execute a command as another user (usually
root).
sudo command
- history – Show the command history.
history
- alias – Create an alias for a command.
alias ll='ls -l'
- crontab – Schedule tasks (cron jobs).
crontab -e # Edit cron jobs
These are just a few of the many Linux commands.
There are countless others, and each can be customized to suit your specific
needs and environment.
0 Comments