The Most Useful Linux Commands
Linux commands are an integral part of managing a Linux system. Below, I’ve compiled a list of some of the most useful Linux commands along with detailed descriptions and examples for each. This is not an exhaustive list, but it covers the most useful linux commands for system management, file operations, and user interactions.
1. ls – List Files and Directories
List files and directories in the current directory.
Examples:
ls
: Lists files in the current directory.ls -a
: Lists all files, including hidden files.ls -l
: Provides a detailed list with permissions, owner, size, and modification date.
2. cd – Change Directory
Change the current working directory.
Examples:
cd /path/to/directory
: Moves to the specified directory.cd ..
: Moves up one level in the directory hierarchy.cd ~
: Returns to the home directory.
3. cp – Copy Files and Directories
Copy files or directories.
Examples:
cp file.txt /path/to/destination/
: Copies a file to a specified destination.cp -r source_directory /path/to/destination/
: Copies a directory and its contents recursively.cp -a source_file destination/
: Preserves file attributes (timestamps, permissions) during copy.
4. mv – Move or Rename Files and Directories
Move or rename files and directories.
Examples:
mv file.txt /path/to/destination/
: Moves a file to a specified destination.mv old_filename.txt new_filename.txt
: Renames a file.mv source_directory /path/to/destination/new_directory
: Moves and renames a directory.
5. rm – Remove Files or Directories
Remove files or directories.
Examples:
rm file.txt
: Removes a file.rm -r directory_to_remove
: Removes a directory and its contents recursively.rm -i file.txt
: Prompts for confirmation before removing each file.
6. grep – Search Text in Files
Search for text patterns in files.
Examples:
grep "pattern" filename
: Searches for a specific word in a file.grep -r "pattern" /path/to/search
: Searches for a pattern recursively in files.grep -i "pattern" filename
: Performs a case-insensitive search.
7. chmod – Change File Permissions
Change file permissions.
Examples:
chmod +x script.sh
: Adds execute permission to a script.chmod 644 file.txt
: Sets read and write permissions for the owner and read-only permissions for others.
8. chown – Change File Owner and Group
Change file owner and group.
Examples:
chown user:group file.txt
: Changes the owner and group of a file.chown -R user:group directory/
: Recursively changes the owner and group of a directory and its contents.
9. pwd – Print Working Directory
Print the current working directory.
Example:
pwd
: Displays the full path of the current working directory.
10. echo – Display Output
Display a message or value.
Examples:
echo "Hello, World!"
: Prints the message “Hello, World!” to the terminal.echo $HOME
: Prints the value of the HOME environment variable.
11. cat – Concatenate and Display File Contents
Display the contents of a file.
Example:
cat filename.txt
: Outputs the contents of the specified file to the terminal.
12. mkdir – Create Directory
Create a new directory.
Example:
mkdir new_directory
: Creates a new directory named “new_directory.”
13. rmdir – Remove Empty Directory
Remove an empty directory.
Example:
rmdir empty_directory
: Removes an empty directory named “empty_directory.”
14. date – Display Current Date and Time
Display the current date and time.
Example:
date
: Shows the current date and time.
15. whoami – Display Current User
Display the username of the current user.
Example:
whoami
: Outputs the username of the user currently logged in.
16. ps – Display Process Status
Display information about currently running processes.
Examples:
ps
: Shows a snapshot of currently running processes.ps aux | grep process_name
: Lists processes containing the specified name.
17. top – Display System Activity in Real-Time
Display dynamic, real-time information about system processes.
Example:
top
: Shows a live, updating view of system processes.
18. df – Display Disk Space Usage
Display information about disk space usage.
Example:
df -h
: Shows disk space usage in a human-readable format.
19. du – Display File and Directory Space Usage
Display sizes of directories and their contents.
Examples:
du -h
: Shows sizes in a human-readable format.du -sh directory
: Displays the total size of the specified directory.
20. wget – Download Files from the Internet
Download files from the internet using the command line.
Example:
wget https://example.com/file.zip
: Downloads a file from the specified URL.
These commands cover a range of tasks essential for managing and interacting with a Linux system from the command line.
You can learn more about linux here – Linux Documentation
In the last BitsToGigs.com article we had discussed about API development in Spring Boot. You can read that here – The Complete Guide to Spring Boot API Mastery
Happy Learning!
Subscribe to the BitsToGigs Newsletter