100 Useful Basic Linux Commands — A Complete Guide for Beginners
- Get link
- X
- Other Apps
Linux is one of the most powerful operating systems, widely used for servers, development, and even everyday computing. At the heart of Linux lies its command line interface (CLI), which gives you direct control over the system.
Whether you are a beginner or someone brushing up your skills, this guide covers 100 useful basic Linux commands that will make navigating, managing, and troubleshooting your system easier.
Navigating the File System: | |
1 | ls: List files and directories in the current location. |
2 | cd: Change directory. |
3 | pwd: Print the working directory. |
File Manipulation: | |
4 | cat: Display the contents of a file. |
5 | less: View file content page by page. |
6 | more: View file content page by page. |
7 | head: Display the first few lines of a file. |
Example: head -n 5 filename | |
8 | tail: Display the last few lines of a file. |
Example: tail -n 10 filename | |
9 | tail -f: Continuously display the last lines of a file (useful for monitoring log files). |
Example: tail -f /var/log/syslog | |
10 | diff: Compare the content of two files and display the differences. |
Example: diff file1 file2 | |
Viewing and Editing Files: | |
11 | mkdir: Create a new directory. |
12 | touch: Create an empty file. |
13 | nano or vim: Text editors to create or modify files. |
14 | cp: Copy files or directories. |
15 | mv: Move or rename files or directories. |
16 | rm: Remove files or directories. |
17 | rmdir: Remove empty directories. |
18 | wc: Count lines, words, and characters in a file. |
19 | ln: Create hard or symbolic (soft) links to files. |
Example: ln -s target_file link_name | |
20 | stat: Display file or file system status information. |
Example: stat filename | |
Searching and Filtering: | |
21 | grep: Search for patterns in files or output. |
22 | find: Search for files and directories. |
Example: find /path/to/search -name "filename" | |
23 | locate: Find files by name quickly using a pre-built database. |
Example: locate filename (search for a file by its name) | |
Text Manipulation: | |
24 | sed: Stream editor for text manipulation (search and replace, etc.). |
Example: sed 's/old/new/g' filename (replace all occurrences of 'old' with 'new' in the file) | |
Process Management: | |
25 | ps: Display information about running processes. |
Example: ps -ef | |
26 | pstree: Display a tree of processes, showing their parent-child relationships. |
Example: pstree | |
27 | kill: Terminate processes. |
28 | pkill: Send signals to terminate processes based on their names or attributes. |
Example: pkill -SIGKILL process_name (force-kill processes by name) | |
29 | nohup: Run a command immune to hangups, even if the user logs out (disconnects from the session). |
Example: nohup long_running_command & (run a command in the background, immune to logout) | |
Resource Monitoring: | |
30 | date: Display the current date and time. |
31 | Cal : Display the calender |
31 | uptime: Display the system's uptime and load average. |
Example: uptime | |
32 | hostname: Show the system's hostname. |
Example: hostname | |
34 | history: Display the command history for the current shell session. |
Example: history | |
35 | top: Monitor system processes and resource usage. |
36 | df -Th: Show disk space usage. |
37 | du -sh: Display disk usage of files and directories in a human-readable format. |
Example: du -h /path/to/directory | |
38 | free -Th: Display system memory usage in a human-readable format. |
Example: free -h | |
39 | vmstat: Report virtual memory statistics (CPU, memory, and I/O). |
- Example: vmstat 1 (output statistics every 1 second) | |
System Monitoring: | |
40 | sar: Collect and report system activity information (requires installation). |
41 | iostat: Report CPU and I/O statistics (requires installation). |
Example: iostat | |
42 | tee: Read from standard input and write to standard output and files simultaneously. |
Example: command | tee output_file.txt (save command output to a file and display it in the terminal) | |
Memory Usage: | |
43 | pmap: Display memory map of a process. |
Example: pmap PID (show memory usage of a process with the specified PID) | |
User Management: | |
44 | whoami: Display the current user's username. |
45 | id: Show user and group information for the current user. |
46 | Chage -l root : Display user details |
47 | su: Switch user or become a superuser (root) with a different user's credentials. |
Example: su username (switch to the specified user) | |
sudo: Execute a command with administrative privileges. | |
48 | useradd: Create a new user account. |
Example: useradd new_username | |
49 | passwd: Change the password for a user account. |
Example: passwd username | |
50 | usermod: Modify user account settings. |
Example: usermod -aG group_name username | |
51 | userdel: Delete a user account. |
Example: userdel username | |
52 | groupadd: Create a new user group. |
Example: groupadd groupname | |
52 | groupadel: delete a new user group. |
Example: groupdel groupname | |
53 | groups: Display the groups a user belongs to. |
Example: groups username | |
Permissions: | |
54 | chmod: Change file permissions. |
Example: chmod u+x file (add execute permission for the owner) or chmod 755 file (give read, write, and execute permissions to the owner, and read and execute permissions to the group and others) | |
Example: chown user:group file (change the owner and group of a file) | |
55 | chown: Change file ownership. |
umask: Set the default permissions for newly created files and directories. | |
Example: umask 022 (set default permissions to 644 for files and 755 for directories) | |
56 | chgrp: Change the group ownership of a file or directory. |
Example: sudo chgrp new_groupname file (change the group ownership of a file) | |
Network Management : | |
57 | ifconfig (or ip addr show): Display network interface information. |
58 | ip: Show or manipulate routing, devices, and policy routing. |
Example: ip addr (display network interface addresses) or ip route (display routing table) | |
Example: ifconfig or ip addr show | |
59 | ping: Send ICMP echo requests to a host to check network connectivity. |
Example: ping google.com | |
60 | nslookup (or dig): Query DNS servers to retrieve domain name or IP address information. |
Example: nslookup example.com or dig example.com | |
61 | netstat: Show network statistics, including open ports and active connections. |
Example: netstat -tuln | grep 3300 | |
62 | traceroute: Trace the route packets take to reach a destination. |
Example: traceroute google.com | |
Network Diagnostics: | |
63 | nmap: Network exploration tool and security scanner. |
Example: nmap -p 1-1000 target_ip (scan the first 1000 ports of a target IP address) | |
64 | ip route: Display or manipulate the routing table. |
Example: ip route show (display the routing table) | |
65 | tcpdump: Capture and display network traffic. |
66 | telnet: Connect to a remote host using the Telnet protocol (requires installation). |
Package Management: | |
67 | yum list: List installed and available packages (for RPM-based distributions). |
rpm -qa | grep tomcat | |
68 | apt (or apt-get): Package manager for Debian-based distributions (e.g., Ubuntu). |
Example: sudo apt update (update package lists) or sudo apt install package_name (install a package) | |
69 | yum: Package manager for Red Hat-based distributions (e.g., CentOS). |
Example: sudo yum update (update packages) or sudo yum install package_name (install a package) | |
70 | which: Display the location of a command. |
71 | whatis: Display the use of the command |
File Compression and Archiving: | |
72 | tar: Create, extract, or manipulate tar archives. |
tar -zcvf: Create a compressed tar archive (tarball) using gzip compression. | |
Example: tar -zcvf archive.tar.gz files | |
tar -jcvf: Create a compressed tar archive using bzip2 compression. | |
Example: tar -jcvf archive.tar.bz2 files | |
73 | gzip (or gunzip): Compress or decompress files using gzip compression. |
Example: gzip filename or gunzip filename.gz | |
74 | zip (or unzip): Create, list, and extract ZIP archives. |
Example: zip archive.zip files or unzip archive.zip | |
Hardware | |
75 | uname -r: Display the kernel release. |
- Example: uname -r | |
76 | dmesg: Display the kernel ring buffer to view system messages, including boot messages. |
Example: dmesg | tail (display the last few kernel messages) | |
77 | lshw: List hardware information (requires installation). |
Example: sudo lshw (display detailed hardware information) | |
78 | lsmod: List loaded kernel modules. |
Example: lsmod (display the list of loaded kernel modules) | |
Remote Command Execution: Jobs | |
79 | cron: A time-based job scheduler for running commands at specified intervals. |
crontab: Schedule commands to run at specified intervals using cron. | |
80 | at: Schedule a one-time command to run at a specific time. |
Example: echo "command_to_run" | at HH:MM | |
Disk Usage and Space Monitoring: | |
81 | watch: Execute a command repeatedly and display its output in real-time. |
Example: watch df -h (monitor disk space usage in real-time) | |
File system Management | |
82 | mount: Mount a file system to a specific directory. |
Example: sudo mount /dev/sdX1 /mnt (mount a partition to the /mnt directory) | |
83 | umount: Unmount a mounted file system. |
Example: sudo umount /mnt (unmount the file system mounted at /mnt) | |
Files download | |
84 | wget: Download files from the web using HTTP, HTTPS, or FTP protocols. |
Example: wget https://example.com/file | |
Example: sudo command (run the command with root privileges) | |
FTP | |
85 | ftp: Connect to a remote host using the File Transfer Protocol. |
Example: ftp ftp.example.com (connect to the FTP server) | |
86 | sftp: Securely transfer files to and from a remote host over SSH. |
Example: sftp user@remote_host (connect to the remote host using SFTP) | |
File Transfer: | |
87 | scp: Securely copy files between local and remote hosts over SSH. |
Example: scp local_file remote_user@remote_host:/remote/path | |
Firewall Configuration: | |
88 | iptables -L |
System Logs: | |
89 | journalctl: Query the systemd journal for system log messages. |
90 | screen: Terminal multiplexer that allows running multiple sessions in a single terminal (requires installation). |
Managing Services: | |
91 | systemctl: Control and manage systemd services. |
92 | service: Control and manage system services (older systems using SysV init). |
Example: sudo service service_name start (start a service) | |
Managing Environment Variables: | |
93 | set: Set environment variables. |
94 | unset: Unset environment variables. |
Disk Management: | |
95 | fdisk: Create, view, or manipulate disk partitions (requires superuser privileges). |
96 | lsblk: List information about available block devices (disks and partitions). |
Example: lsblk | |
File Permissions and Ownership: | |
97 | sort: Sort lines of text files. |
Example: sort filename (sort lines in ascending order) | |
System Maintenance: | |
98 | shutdown: Schedule a system shutdown or reboot. |
- Example: sudo shutdown -r now (reboot immediately) or sudo shutdown -h +5 (shutdown in 5 minutes) | |
99 | reboot: Reboot the system. |
Example: sudo reboot |
Thanks for visiting the page.
- Get link
- X
- Other Apps
Comments
Post a Comment