50+ Essential Linux Commands: Your Quick Start Guide
Unlock the power of Linux! This guide provides a collection of frequently used Linux commands that will boost your productivity and efficiency. Whether you're a beginner or an experienced user, mastering these commands will enhance your interaction with the Linux operating system. Let's navigate the command line like a pro!
Why Learn Basic Linux Commands?
- Efficiency: Execute tasks quickly and directly.
- Control: Gain granular control over your system.
- Automation: Create scripts to automate repetitive tasks.
- Server Management: Essential for managing remote servers.
- Troubleshooting: Diagnose and fix system issues effectively.
Essential File and Directory Navigation Linux Commands
1. ls
: List Files and Directories
The ls
command is your window into the file system. It displays the contents of a directory.
ls
(Lists files in the current directory)ls -l
(Lists files with detailed information)ls -a
(Shows all files, including hidden ones)
2. pwd
: Print Working Directory
Ever lost in the terminal? pwd
reveals your current location. This handy command displays the full path of your current working directory. Use it to orient yourself within the file system.
3. cd
: Change Directory
Navigate through directories with ease using the cd
command.
cd directory_name
(Moves to specified directory)cd ..
(Moves up one directory level)cd ~
(Returns to your home directory)
4. mkdir
: Create Directories
Organize your files by creating new directories with mkdir
.
mkdir directory_name
(Creates a new directory)mkdir -p path/to/new/directory
(Creates nested directories)
5 & 6. cp
and mv
: Copy and Move Files
Manage files by copying (cp
) or moving (mv
) them. cp
duplicates files to new locations, while mv
relocates or renames them.
cp source_file destination_file
(Copies a file)mv source_file destination_file
(Moves or renames a file)
7. rm
: Remove Files or Directories
Carefully delete files and directories using the rm
command.
rm file_name
(Deletes a file)rm -r directory_name
(Deletes a directory and its contents recursively)rm -i file_name
(Prompts for confirmation before deleting)
8. touch
: Create Empty Files
Quickly create new, empty files with the touch
command.
touch file_name
(Creates a new empty file)
9. ln
: Create Links (Shortcuts)
Create symbolic links to files using the ln -s
command for easy access. A symbolic link acts as a pointer to the original file.
ln -s original_file link_name
(Creates a symbolic link)
Essential File Content and Information Commands
10. clear
: Clear the Terminal Display
Declutter your terminal screen with the clear
command for better readability. Typing clear
provides a clean slate for your next commands.
11. cat
: Display File Contents
View the content of a file directly in the terminal with cat
. This command is useful for quickly inspecting configuration files or text documents.
cat file_name
(Displays the entire file content)
12. echo
: Print Text
Display text or variables using the echo
command. This simple yet powerful command is often used in scripts.
echo "Hello, world!"
(Prints "Hello, world!")
13. less
: View Paged Outputs
View long files one page at a time using less
. Navigate with the arrow keys, Spacebar (next page), and 'q' to quit.
less file_name
(Opens the file in a paged view)
14. man
: Access Manual Pages
Get detailed information about any command using the man
command. It opens the manual page for the specified command. This is your go-to resource for understanding command options.
man command_name
(Displays the manual page for the command)
15. uname
: Display System Information
Find out basic information about your operating system kernel, host name, Kernel release date and more with the uname
command.
uname -a
(Shows all system information)
16. whoami
: Display Current Username
Quickly identify the currently active user account with the whoami
command. It returns your username.
Archiving, Searching, and Comparing Linux Commands
17. tar
: Archive and Extract Files
Compress and extract files using the tar
command. This is essential for creating backups and sharing files.
tar -czvf archive_name.tar.gz directory_to_archive
(Creates a compressed archive)tar -xzvf archive_name.tar.gz
(Extracts a compressed archive)
18. grep
: Search for Patterns
Find specific text within files using the grep
command.
grep "pattern" file_name
(Searches for "pattern" in the file)grep -r "pattern" directory_name
(Recursively searches for "pattern" in the directory)
19 & 20. head
and tail
: View File Heads and Tails
Display the beginning or end of a file using head
and tail
.
head -n 10 file_name
(Displays the first 10 lines)tail -n 10 file_name
(Displays the last 10 lines)tail -f file_name
(Continuously displays new lines added to the file)
21, 22, 23. diff
, cmp
, and comm
: Compare files
These Linux commands help to point differences among two files.
diff file1 file2
: compares file1 and file2 line by line and presents the differences.cmp file1 file2
: Compares two files byte by byte, it is useful for identifying binary differences.comm file1 file2
: useful for finding common and distinct lines between sorted file1 and sorted file2.
24. sort
: Sort File Content
Sort the lines of a text file.
sort file_name
: displays a file content, organizes in ascending order.
Environment, Networking and Installation Linux Commands
25. export
: Export Environment Variables
Set environment variables for the current session using the export
command. These variables can be used by other programs.
export VARIABLE_NAME=value
(Sets an environment variable)
26 & 27. zip
and unzip
: Compress and Extract .zip Files
Compress and extract zip files using the zip
and unzip
commands.
zip archive_name.zip file1 file2
(Creates a zip archive)unzip archive_name.zip
(Extracts a zip archive)
28. ssh
: Secure Shell Access
Securely connect to remote servers using the ssh
command.
ssh user@host
(Connects to a remote server)
29. service
: Manage Services
Start, stop, and restart system services using the service
command.
service service_name start
(Starts a service)service service_name stop
(Stops a service)service service_name restart
(Restarts a service)
30 & 31. ps
, kill
, and killall
: Manage Processes
View and manage running processes. ps
lists processes, kill
terminates processes by ID, and killall
terminates processes by name.
ps aux
(Lists all running processes)kill process_id
(Kills a process)killall process_name
(Kills all processes with the specified name)
32. df
: Display Disk Space
Check disk space usage with the df
command. This helps you monitor storage capacity.
df -h
(Displays disk space in a human-readable format)
33. mount
: Mount File Systems
Mount file systems to make them accessible.
mount /dev/sdb1 /mnt
(Mounts a file system)
34 & 35. chmod
and chown
: Change Permissions and Ownership
Modify file permissions with chmod
and change file ownership with chown
. These commands are critical for security.
chmod 755 file_name
(Changes file permissions)chown user:group file_name
(Changes file ownership)
36. ifconfig
: Configure Network Interfaces
View and configure network interfaces with the ifconfig
command.
ifconfig
(Displays network interface information)
37. traceroute
: Trace Network Route
Trace the route packets take to reach a destination.
traceroute destination
(Traces the route to the destination)
38. wget
: Download Files
Download files from the internet via the command line using wget
.
wget URL
(Downloads a file from the specified URL)
39 & 40. ufw
and iptables
: Manage Firewalls
Configure firewalls to protect your system. ufw
is a user-friendly front-end for iptables
.
ufw enable
(Enables the firewall)ufw allow 22
(Allows SSH traffic)
41. apt
, pacman
, yum
, rpm
: Package Managers
Install, update, and remove software packages using package managers. The specific command varies by Linux distribution.
apt update && apt upgrade
(Updates packages on Debian/Ubuntu)yum update
(Updates packages on CentOS/RHEL)
Administrator and Utility Linux Commands
42. sudo
: Execute Commands as Superuser
Run commands with administrator privileges using sudo
.
sudo command
(Executes the command as superuser)
43. cal
: Display a Calendar
View a command-line calendar with the 'cal' command.
cal
(Displays the current months calendar)
44. alias
: Create Command Aliases
Create shortcuts for commonly used commands with the alias
command.
alias la='ls -la'
(Creates an alias 'la' for 'ls -la')
45. dd
: Copy and Convert Data
Copy and convert data from one source to another, commonly used for creating bootable USB drives.
dd if=/path/to/image.iso of=/dev/sdb bs=4M status=progress
(Writes an ISO image to a USB drive)
46 & 47. whereis
and whatis
: Locate Commands
Find the location and purpose of commands using whereis
and whatis
.
whereis command_name
(Locates the binary, source, and manual pages)whatis command_name
(Shows what a command does)
48. top
: Monitor System Resources
View active processes and system resource usage in real-time with the top
command.
49 & 50. useradd
, usermod
, and passwd
: Manage Users
Manage user accounts using useradd
(add new users), usermod
(modify user accounts), and passwd
(change passwords).
useradd newuser
(Adds a new user)passwd newuser
(Sets a password for the new user)
Conclusion: Mastering Linux Commands
Congratulations! You've explored over 50 essential basic Linux commands for navigating and utilizing the Linux command line. Continue practicing and experimenting to solidify your knowledge and unlock the full potential of Linux. These beginner Linux commands offer the foundation for more complex operations, scripting and server management. Keep learning, keep exploring!