Ticker

6/recent/ticker-posts

Advertisement

Linux basic commands for managing the system

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

  1. ls – List directory contents.

ls

ls -l     # Long format

ls -a     # Show hidden files

ls -lh    # Long format with human-readable file sizes

  1. cd – Change directory.

cd /path/to/directory

cd ..     # Move to parent directory

cd ~      # Move to home directory

  1. pwd – Print the current working directory.

pwd

  1. mkdir – Create a new directory.

mkdir new_directory

  1. rmdir – Remove an empty directory.

rmdir directory_name

  1. 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

  1. cp – Copy files or directories.

cp source_file destination_file

cp -r source_dir destination_dir  # Copy a directory

  1. mv – Move or rename files and directories.

mv old_name new_name

mv file_name /path/to/destination/

  1. 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

  1. 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

  1. chown – Change file ownership.

chown user:group file_name

 

chown -R user:group directory_name  # Change ownership recursively

  1. chgrp – Change group ownership of a file or directory.

chgrp group_name file_name

Process Management

  1. ps – Display information about running processes.

ps aux  # Show all running processes

ps -ef  # Full-format listing

  1. top – Display dynamic real-time system information (e.g., CPU, memory usage).

top

  1. htop – Interactive process viewer (enhanced version of top).

htop

  1. kill – Terminate a process.

kill <PID>  # Terminate process by PID

kill -9 <PID>  # Force kill a process

  1. killall – Kill processes by name.

killall process_name

  1. bg – Resume a job in the background.

bg %job_number

  1. fg – Bring a job to the foreground.

fg %job_number

Disk Usage and Filesystem

  1. df – Display disk space usage of file systems.

df -h  # Human-readable format

  1. 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

  1. mount – Mount a filesystem.

mount /dev/sdX /mnt

  1. umount – Unmount a filesystem.

umount /mnt

  1. fsck – Check and repair filesystem.

fsck /dev/sdX

Networking

  1. ifconfig – Display or configure network interfaces (older tool, replaced by ip).

ifconfig

  1. 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

  1. ping – Send ICMP ECHO_REQUEST to network hosts.

ping 8.8.8.8       # Ping a public DNS server

  1. netstat – Network statistics (use ss on newer systems).

netstat -tuln      # Show listening ports

  1. ss – Utility to investigate sockets.

ss -tuln           # Show listening ports and their status

  1. wget – Download files from the web.

wget http://example.com/file.txt

  1. curl – Transfer data from or to a server.

curl http://example.com

  1. scp – Securely copy files between hosts over SSH.

scp file_name user@remote_host:/path/to/destination

System Monitoring and Logs

  1. uptime – Show how long the system has been running.

uptime

  1. dmesg – Print kernel ring buffer messages (useful for debugging).

dmesg | less

  1. journalctl – Query and view logs from systemd journals.

journalctl -xe  # Show system logs

  1. tail – View the end of a file.

tail -f /var/log/syslog  # Monitor log file in real time

  1. less – View the contents of a file one page at a time.

less /path/to/file

  1. grep – Search for patterns within files.

grep "pattern" file_name

grep -r "pattern" /path/to/directory  # Recursively search

User and Group Management

  1. useradd – Add a new user.

useradd username

  1. usermod – Modify an existing user.

usermod -aG groupname username  # Add user to a group

  1. passwd – Change user password.

passwd username

  1. groupadd – Add a new group.

groupadd groupname

  1. id – Display user and group IDs.

id username

  1. whoami – Display the current logged-in user.

whoami

Archive and Compression

  1. tar – Archive files.

tar -cvf archive.tar /path/to/directory  # Create archive

tar -xvf archive.tar  # Extract archive

  1. gzip – Compress files.

gzip file_name

  1. gunzip – Decompress .gz files.

gunzip file_name.gz

  1. zip – Compress files into a .zip archive.

zip archive.zip file1 file2

  1. unzip – Extract .zip files.

unzip archive.zip

Other Useful Commands

  1. sudo – Execute a command as another user (usually root).

sudo command

  1. history – Show the command history.

history

  1. alias – Create an alias for a command.

alias ll='ls -l'

  1. 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.

Bottom of Form

Top of Form

Bottom of Form

 

Post a Comment

0 Comments