Essential Linux Command Overview: Your Ultimate Cheat Sheet
Written on
Introduction to Linux Commands
Linux is an operating system comparable to Windows, iOS, and macOS. It is one of the most widely used platforms globally; for instance, Android runs on the Linux OS. Whether you are a developer, a cybersecurity expert, or involved in any tech-related field, grasping the Linux shell commands is invaluable. This guide serves as a comprehensive cheat sheet for the most crucial Linux commands you should familiarize yourself with for effective navigation within the Linux operating system.
Basic Linux Shell Commands
- ls: Lists all files in your current directory.
- Commands and Flags:
- ls: Displays all regular files in the directory.
- ls -a: Lists all files, including hidden ones (which start with a dot).
- Commands and Flags:
- cat: Outputs the contents of a file.
- Commands and Flags:
- cat [file.txt]: Shows the contents of the specified file.
- Commands and Flags:
- pwd: Reveals the full path of your current working directory.
- Commands and Flags:
- pwd: Displays the complete path of the current directory.
- Commands and Flags:
- cd: Changes your current directory.
- Commands and Flags:
- cd [directoryname/]: Navigates to a specified subdirectory.
- cd: Without arguments, it takes you to the home directory.
- Commands and Flags:
- mkdir: Creates a new directory.
- Commands and Flags:
- mkdir [directoryname]: Generates a new directory within the current directory.
- Commands and Flags:
- whoami: Displays your username.
- Commands and Flags:
- whoami: Shows the current user's name.
- Commands and Flags:
- id: Provides user ID and group information.
- Commands and Flags:
- id: Displays your user ID and group details.
- Commands and Flags:
- rm: Deletes specified files.
- Commands and Flags:
- rm [filename.txt]: Removes the indicated file.
- Commands and Flags:
- mv: Moves or renames files.
- Commands and Flags:
- mv file.txt [desireddirectory/]: Moves the file to the desired directory.
- mv file.txt renamedfile.txt: Renames the specified file.
- Commands and Flags:
- cp: Copies files from one location to another.
- Commands and Flags:
- cp [filename/filepath] [desired filename/filepath]: Copies the file to the specified location.
- Commands and Flags:
File System Commands
- find: Searches for specific files in a directory.
- Commands and Flags:
- find /home -name "*.txt": Locates all files with a .txt extension (case-sensitive).
- find -iname "*.TXT": Searches case-insensitively.
- Commands and Flags:
- ls -l: Identifies the owner and permissions of a file.
- Commands and Flags:
- ls -l [filename]: Displays file permissions and ownership details.
- Commands and Flags:
- chmod: Alters file permissions for users, groups, and others.
- Examples:
- chmod 400 filename: Grants read access to the owner only.
- chmod 600 filename: Allows read and write access to the owner only.
- Examples:
- chown: Changes the ownership of a file.
- Commands and Flags:
- chown username filename: Modifies the ownership of the file.
- Commands and Flags:
- sudo: Executes commands as a privileged user.
- Commands and Flags:
- sudo chown [username] [filename]: Runs the chown command with elevated privileges.
- Commands and Flags:
- chgrp: Modifies the group assignment of a file.
- Commands and Flags:
- chgrp [groupname] [filename]: Changes the group owner of the file.
- Commands and Flags:
System Process Commands
- ps: Lists running process information.
- Commands and Flags:
- ps: Displays process information.
- ps -f: Provides additional details, including command line arguments.
- Commands and Flags:
- kill: Terminates a process.
- Commands and Flags:
- kill [PID]: Attempts to terminate the process.
- kill -9 [PID]: Forces the process to close.
- Commands and Flags:
- jobs: Displays the status of processes in the current terminal.
- Commands and Flags:
- jobs: Lists jobs running in the terminal.
- Commands and Flags:
- bg: Resumes a process in the background.
- Commands and Flags:
- bg: Sends a job to the background.
- Commands and Flags:
- fg: Brings a background process to the foreground.
- Commands and Flags:
- fg: Restores a background job to the foreground.
- Commands and Flags:
- &: Runs a process in the background.
- Commands and Flags:
- [Processname] &: Executes the specified process in the background.
- Commands and Flags:
Network Commands in Linux
- ip: Manages network interfaces.
- Commands and Flags:
- ip addr show: Displays network interface information.
- Commands and Flags:
- ifconfig: Shows IP address and network interface details.
- Commands and Flags:
- ifconfig: Displays all network interface configurations.
- Commands and Flags:
- ping: Tests connectivity between machines.
- Commands and Flags:
- ping [IP address]: Sends data packets to a specified IP and waits for a response.
- Commands and Flags:
- netstat: Displays network connections.
- Commands and Flags:
- netstat -na: Shows all inbound and outbound network connections.
- Commands and Flags:
File Processing Commands
- nano: The default text editor in Linux.
- Commands and Flags:
- nano [filename.txt]: Opens the specified file in the Nano editor.
- Commands and Flags:
- echo: Redirects messages to a file.
- Commands and Flags:
- echo "This is my message" > filename: Writes a message to the specified file.
- Commands and Flags:
- head: Retrieves the first few lines of a file.
- Commands and Flags:
- head [filename/path]: Displays the first 10 lines of the specified file.
- Commands and Flags:
- tail: Retrieves the last few lines of a file.
- Commands and Flags:
- tail [filename/path]: Shows the last 10 lines of the specified file.
- Commands and Flags:
- grep: Searches for specific lines in a file.
- Commands and Flags:
- grep [string] [filename]: Searches for a specified string within the file.
- Commands and Flags:
- wc: Counts lines, words, and characters in a file.
- Commands and Flags:
- wc filename.txt: Displays the count of lines, words, and characters.
- Commands and Flags:
- sort: Sorts the contents of a file.
- Commands and Flags:
- sort filename.txt: Sorts the file's contents alphabetically.
- Commands and Flags:
- cut: Separates specific parts of a text file.
- Commands and Flags:
- cut -d , -f 1 filename: Separates the text by commas and returns the first section.
- Commands and Flags:
- Pipe Command |: Connects the output of one command to another.
- Commands and Flags:
- cat filename.txt | sort -u: Takes the output from cat and sorts it for unique values.
- Commands and Flags:
Conclusion
If you're looking for further assistance in writing content like this, feel free to reach out! I'm available for freelance writing opportunities. For more engaging content, don’t hesitate to follow me, and I welcome any comments, questions, or suggestions for future articles!