Linux commands are the backbone of system management, file handling, and process automation. This guide categorizes and summarizes essential Linux commands to help you master the terminal. Whether you’re a beginner or an advanced user, these commands will boost your productivity.
User and Permission Management
sudo adduser
[username]
: Adds a new user to the system.sudo passwd
[username]
: Sets or changes the password for a user.sudo visudo
: Safely edits the sudoers file to manage administrative privileges.who
: Displays logged-in users.id
[username]
: Shows user ID and group information.chmod
[permissions] [file]
: Changes file permissions.chown
[owner] [file]
: Changes the owner of a file.
File and Directory Management
ls
: Lists the contents of a directory.ls -l
: Detailed listing.ls -a
: Includes hidden files.ls -lt
: Sorts by modification time.touch [filename]
: Creates an empty file.mkdir [dirname]
: Creates a new directory.mkdir -p [dir1/dir2/dir3]
: Creates nested directories.cp [source] [destination]
: Copies files or directories.cp -r
: Copies directories recursively.mv [source] [destination]
: Moves or renames files and directories.rm [filename]
: Deletes a file.rm -r [dirname]
: Deletes a directory recursively.find / -name [filename]
: Searches for a file or directory.
Text Editing
nano [filename]
: Opens the file in Nano text editor.
- Save:
Ctrl + X
, Confirm:Y
, Exit:Enter
.
vi [filename]
: Opens the file in Vi text editor.
- Enter Insert Mode:
i
, Save::w
, Exit::q
.
cat [filename]
: Displays the contents of a file.
System Information and Monitoring
df -h
: Displays disk space usage in human-readable format.du -sh [directory]
: Shows the size of a file or directory.top
: Monitors real-time system processes.uptime
: Displays system uptime and load averages.free -h
: Displays memory usage.ps aux
: Lists all running processes.
Package Management
sudo apt-get update
: Updates the system’s package list.sudo apt-get install [package_name]
: Installs a specified package.wget [URL]
: Downloads files from the internet.sudo tar -xvf [filename.tar.gz]
: Extracts.tar.gz
files.
SSH Configuration
sudo vi /etc/ssh/sshd_config
: Opens the SSH configuration file for editing.
- Enable password login:
PasswordAuthentication yes
.
- Restart SSH service:
sudo service ssh restart
sudo service ssh start
sudo service ssh stop
Disk and Filesystem Operations
mount [device] [directory]
: Mounts a filesystem.umount [directory]
: Unmounts a filesystem.lsblk
: Lists information about block devices.blkid
: Displays UUIDs of filesystems.df -h
: Checks available disk space.
Networking
ping [host]
: Sends ICMP packets to test connectivity.ifconfig
/ip addr
: Displays or configures network interfaces.netstat -tuln
: Displays active network connections.curl [URL]
: Fetches content from a URL.
Miscellaneous Commands
history
: Displays a list of previously executed commands.clear
: Clears the terminal screen.pwd
: Displays the current working directory.echo [text]
: Prints text to the terminal.alias [name]='[command]'
: Creates a shortcut for a command.
Advanced Tips
- Shortcuts:
Ctrl + C
: Stops a running process.Ctrl + Z
: Pauses a process.Ctrl + D
: Logs out of the terminal.
- Wildcards:
*
: Matches multiple characters.?
: Matches a single character.
- Chaining Commands:
command1 && command2
: Runs the second command only if the first succeeds.command1 || command2
: Runs the second command if the first fails.
Conclusion
Mastering Linux commands is crucial for anyone working with servers, development, or system administration. This categorized list will serve as a solid reference. Whether you’re managing users, files, or processes, these commands provide the tools to accomplish your tasks efficiently. Bookmark this guide and keep practicing to enhance your Linux expertise!