Linux Common Commands
2024-02-20File Commands
- ls # Directory listing
- ls -l # Long listing format
- ls -a # List all files including hidden files
- cd /path/to/directory # Change directory
- pwd # Display the current working directory
- mkdir directory_name # Create a new directory
- rmdir directory_name # Remove an empty directory
- rm file_name # Remove a file
- rm -r directory_name # Remove a directory and its contents recursively
- touch file_name # Create or update a file
- cat file_name # Concatenate and display the file content
- more file_name # View file content page by page
- less file_name # Improved viewing of file content over 'more'
- cp source_file target_file # Copy files from source to target
- mv old_name new_name # Rename or move a file/directory
SSH (Secure Shell)
- ssh user@host # Connect to host as user
- ssh -p port user@host # Connect using a specific port
- ssh-keygen -t rsa # Generate rsa key pair
- ssh-copy-id user@host # Copy your key to the remote server for password-less login
Search
- grep pattern files # Search for pattern in files
- grep -r pattern dir # Recursively search for pattern in dir
- find /dir -name name* # Find files starting with name in dir
- locate file_name # Find files by name (uses a database)
Process Management
- ps # Display your currently active processes
- ps aux | grep process_name # Find process named process_name
- top # Display all running processes
- kill pid # Kill process with given pid
- killall process_name # Kill all processes named process_name
- bg # List stopped or background jobs; resume a stopped job in the background
- fg # Brings the most recent job to foreground
File Permissions
- chmod +x file_name # Make file executable
- chmod 755 file_name # Set read and execute permissions for owner and read for others
- chown user:group file_name # Change file owner and group
Network
- ifconfig # Display all network interfaces and ip address
- ping host # Send ICMP echo request to host
- traceroute host # Display the route packets take to network host
- netstat -tulnp # Display listening ports and their applications
Archive and Compression
- tar cf archive_name.tar files # Create a tar named archive_name.tar containing files
- tar xf archive_name.tar # Extract the files from archive_name.tar
- gzip file_name # Compresses file and renames it to file.gz
- gunzip file.gz # Decompresses file.gz back to original
System Info and Management
- uname -a # Show system and kernel info
- df -h # Display free disk space in human-readable form
- du -sh directory_name # Show disk usage of directory in human-readable form
- free -m # Show free and used memory in MB
Package Management (Debian/Ubuntu)
- sudo apt-get update # Update package list index
- sudo apt-get upgrade # Upgrade all packages
- sudo apt-get install package_name # Install package
Package Management (Rhat/CentOS) and both dnf and yum is available, and dnf is newer and better.
- sudo dnf/yum check-update # Update package list index
- sudo dnf/yum upgrade # Upgrade all packages
- sudo dnf/yum install package_name # Install a package
- sudo dnf/yum remove package_name # Remove a package
- sudo dnf/yum search package_name # Search for a package
- sudo dnf/yum list installed # List installed packages
Text editors
- nano file_name # Open file in nano editor
- vi file_name # Open file in vi editor
MISC Commands
- man command_name # Show manual for command
- echo "text" # Display message on screen
- date # Display current date and time
- uptime # Show how long the system has been running