Linux commands are powerful tools for interacting with and managing a Linux-based system. Here’s a list of 40 most-used Linux commands that are essential for beginners and advanced users alike.
File and Directory Management:
- ls: List the contents of a directory.
bashls -l # Lists files with detailed information
- cd: Change directory.
bashcd /path/to/directory
- pwd: Print the current working directory.
bashpwd
- mkdir: Create a new directory.
bashmkdir new_directory
- rmdir: Remove an empty directory.
bashrmdir empty_directory
- rm: Remove files or directories.
bashrm file.txt # Remove a file rm -r folder # Remove a directory and its contents
- cp: Copy files or directories.
bashcp file1.txt /path/to/destination cp -r directory1 /path/to/destination
- mv: Move or rename files or directories.
bashmv file1.txt /path/to/destination mv oldname.txt newname.txt # Rename a file
- touch: Create an empty file or update the timestamp of an existing file.
bashtouch newfile.txt
- cat: Display the contents of a file.
bashcat file.txt
- more: View file content one screen at a time.
bashmore file.txt
- less: View file content with more control (can scroll up and down).
bashless file.txt
- head: View the first few lines of a file.
bashhead file.txt
- tail: View the last few lines of a file.
bashtail file.txt tail -f file.txt # Follow file updates in real time (useful for logs)
System Information and Monitoring:
- uname: Display system information.
bashuname -a # Show detailed system info
- df: Display disk space usage.
bashdf -h # Human-readable format
- du: Show disk usage of files and directories.
bashdu -sh # Summary for a directory
- top: Display real-time system processes and resource usage.
bashtop
- htop: A more user-friendly alternative to top (needs to be installed).
bashhtop
- free: Show memory usage.
bashfree -h # Human-readable format
- ps: Display currently running processes.
bashps aux # Show detailed process list
- kill: Terminate a process by its PID (Process ID).
bashkill 1234 # Replace 1234 with the process PID
- uptime: Show how long the system has been running.
bashuptime
- whoami: Display the current user.
bashwhoami
- uname: Show system kernel information.
bashuname -r # Show kernel version
File Permissions and Ownership:
- chmod: Change file permissions.
bashchmod 755 file.txt # Set read/write/execute permissions
- chown: Change file or directory ownership.
bashchown user:group file.txt
- chgrp: Change group ownership of a file.
bashchgrp groupname file.txt
Text Manipulation:
- grep: Search for patterns within files.
bashgrep “search_term” file.txt grep -r “search_term” /path/to/directory # Search recursively
- find: Search for files and directories.
bashfind /path/to/search -name “filename”
- awk: Process and analyze text files.
bashawk ‘{print $1}’ file.txt # Print the first column
- sed: Stream editor for modifying files.
bashsed ‘s/old/new/g’ file.txt # Replace all instances of ‘old’ with ‘new’
Networking:
- ping: Test network connectivity.
bashping google.com
- ifconfig: Display or configure network interfaces (older tool, replaced by ip).
bashifconfig
- ip: Show/manipulate routing, devices, and tunnels (modern replacement for ifconfig).
baship addr show
- wget: Download files from the web.
bashwget http://example.com/file.zip
- curl: Transfer data from or to a server (supports more protocols than wget).
bashcurl http://example.com
- netstat: Display network connections, routing tables, and interface statistics.
bashnetstat -tuln # Show listening ports
- ssh: Connect to a remote server via Secure Shell.
bashssh user@remote_server
- scp: Securely copy files between hosts over SSH.
bashscp file.txt user@remote:/path/to/destination
Bonus:
- history: View command history.
bashhistory
- alias: Create shortcuts for long commands.
bashalias ll=’ls -l’
Mastering these commands can significantly improve your efficiency and control over a Linux system. Each command has multiple options and variations that extend their functionality even further!