The 40 Most-Used Linux Commands You Should Know
The Linux terminal, often referred to as the command line, might seem intimidating to new users accustomed to graphical interfaces. But beneath the surface lies a powerful tool that grants precise control over your system. This comprehensive guide explores the 40 most-used Linux commands, empowering you to navigate the terminal with confidence and efficiency.
Essential File and Directory Management:
- pwd: This ubiquitous command simply prints the working directory, indicating your current location within the file system hierarchy.
- cd: Change directory allows you to navigate through the file system. Use
cd ~
to go to your home directory,cd ..
to move to the parent directory, andcd directory_name
to enter a specific directory. - ls: This workhorse command lists the contents of a directory. Use
ls -l
for a long listing with detailed information about each file. - mkdir: Create a new directory with
mkdir directory_name
. Usemkdir -p
to create nested directories if they don’t exist. - rmdir: To remove an empty directory, use
rmdir directory_name
. - rm: This command deletes files. Use with caution! Deleted files are generally unrecoverable. Consider
rm -rf
for forceful deletion (use with extreme care!). - cp: Copy files or directories. Use
cp source_file destination_file
orcp -r source_directory destination_directory
for directories. - mv: Move or rename files and directories.
mv source_file destination_file
moves the file, whilemv old_name new_name
renames it. - touch: Create an empty file with
touch filename
.
Viewing and Manipulating Files:
- cat: Display the contents of a file on the terminal. Use
cat filename
to view the entire file orcat filename | head -n 5
to display the first five lines. - more: Similar to
cat
, but displays the file content one screen at a time, allowing you to navigate through lengthy files with ease. - less: Another alternative to
cat
, offering similar functionality with the ability to move forward and backward within the file content. - head: Display the first lines of a file. Use
head -n 10 filename
to view the first ten lines. - tail: Display the last lines of a file. Use
tail -n 5 filename
to view the last five lines. - grep: Search for a specific pattern within a file. Use
grep "pattern" filename
to find lines containing the pattern.
Permissions and Ownership:
- chmod: Change file or directory permissions. Use
chmod ugo+rwx filename
to grant read, write, and execute permissions to user (u), group (g), and others (o). - chown: Change file ownership. Use
chown user:group filename
to change the owner and group associated with a file.
System Information and Processes:
- uname: Display information about the Linux kernel and system. Use
uname -a
for all details. - whoami: This simple command reveals your current logged-in username.
- ps: Show currently running processes. Use
ps aux
for a more detailed listing. - top: View process information in real-time, allowing you to monitor CPU and memory usage.
- free: Display information about available and used memory (RAM) on the system.
Networking:
- ping: Check network connectivity by sending echo requests to a specific host. Use
ping google.com
to test your internet connection. - ifconfig: Display information about network interfaces and IP addresses.
- ssh: Secure Shell allows you to securely connect to remote Linux servers.
Text Editing and Manipulation:
- nano: A user-friendly text editor suitable for basic editing tasks.
- vim: A powerful and versatile text editor with a steeper learning curve, but offering extensive functionality for power users.
Package Management:
- apt-get (Debian/Ubuntu): This package manager allows you to install, update, and remove software packages. Use
apt-get install package_name
to install a package. - yum (Red Hat/CentOS): Similar to
apt-get
, but used for Red Hat-based distributions. Useyum install package_name
to install a package.
Basic System Administration:
- sudo: Grant temporary superuser (root) privileges to execute a command. Use with caution, as root access grants unrestricted control over the system.
- su: Switch to the root user account. Be extremely careful when using the root account, as mistakes can have serious consequences.
- reboot: Restart the system.
- halt: Power down the system.
Disk Management:
- df: Display information about mounted file systems, including available and used disk space.
- fdisk: Manage disk partitions. (**Advanced users only! Improper use can lead to data loss.)
User Management:
- useradd: Add a new user account to the system.
- passwd: Change a user’s password.
Permissions and Security:
- umask: Set the default file creation mask, which determines the initial permissions assigned to newly created files and directories.
Help and Information:
- man: Access manual pages for Linux commands. Use
man command_name
to view the manual page for a specific command. - help: Display brief help information for a command. Use
help command_name
to get basic usage instructions.
Remember:
- The command line can be a powerful tool, but it’s crucial to use it with caution. Experimenting with unfamiliar commands can have unintended consequences.
- It’s always a good practice to consult the manual pages (
man command_name
) before using a command you’re unfamiliar with. - Many commands have various options and flags that modify their behavior. Explore the manual pages to discover the full potential of each command.
Beyond the Basics:
This list provides a solid foundation for navigating the Linux command line. As you gain experience, explore more advanced commands and techniques to unlock the full potential of this versatile interface. Remember, the Linux terminal offers a powerful and efficient way to interact with your system, and mastering these commands empowers you to manage your Linux environment with precision and control.