Mastering Linux Command Line: A Guide to Essential Commands Part 4
Linux is a powerful operating system known for its versatility and efficiency. To make the most out of Linux, it’s essential to understand and use some fundamental commands. This guide will walk you through several key commands, explaining their uses and providing examples.
Contents
1. chown – Change File Ownership
The chown command changes the ownership of files and directories. This can be useful when you need to transfer file ownership between users.
Example: chown user1:group1 file.txt
This command changes the owner of file.txt
to user1
and the group to group1
.
2. man – Manual Pages
The man command displays the manual pages for other commands. This is a handy tool to learn more about what a command does and its options.
Example: man ls
This displays the manual page for the ls command.
3. ls – List Directory Contents
The ls command lists the contents of a directory. Various options can be used to modify its output.
Examples:
ls -a # Lists all files including hidden files
ls -l # Lists files in long format
ls -la # Combines both options above
4. ps – Display Current Processes
The ps
command provides a snapshot of the current processes.
Example: ps
This shows a list of running processes along with their process IDs (PIDs).
5. top – Task Manager
The top
command displays real-time information about running processes, including CPU and memory usage.
Example: top
Use top
for a more user-friendly and colorful interface, if available.
6. kill – Terminate Processes
The kill
command terminates a process using its PID.
Example: kill -9 1234
This forcefully kills the process with PID 1234
.
7. df – Disk Space Usage
The df
command displays the amount of disk space used and available on filesystems.
Example: df -h
The -h
option displays the information in a human-readable format.
8. du – Disk Usage
The du
command estimates file and directory space usage.
Example: du -sh *
The -s
option summarizes the sizes, and -h
makes the output human-readable.
9. ifconfig – Network Configuration
The ifconfig command configures network interfaces and displays information about them.
Example: ifconfig
This displays all active network interfaces and their IP addresses.
10. grep – Search Text
The grep command searches for patterns within files.
Example: grep ‘pattern’ file.txt
This searches for the string ‘pattern’ in file.txt
.
11. traceroute – Trace Network Path
The traceroute
command traces the path that packets take to reach a network host.
Example: traceroute google.com
This shows the route packets take to reach google.com
.
12. ping – Test Network Connectivity
The ping command checks the network connection to a host.
Example: ping google.com
This sends ICMP ECHO_REQUEST packets to google.com
and displays the response.
13. zip and unzip – Compress and Decompress Files
The zip command compresses files, and the unzip command decompresses them.
Examples: zip archive.zip file.txt
unzip archive.zip
These commands create and extract a zip archive, respectively.
14. nano, vim, vi – Text Editors
These are text editors used to edit files from the command line.
Examples: nano file.txt
vim file.txt
vi file.txt
nano
is user-friendly, while vim
and vi
offer more advanced features.
15. tar – Archive Files
The tar command creates and extracts compressed archive files.
Example: tar -cvf archive.tar file.txt
tar -xvf archive.tar
The first command creates an archive, and the second extracts it.
16. curl – Transfer Data from URLs
The curl command transfers data from or to a server using various protocols.
Example: curl -O http://example.com/file.txt
This downloads file.txt
from example.com
.
17. wget – Download Files
The wget command downloads files from the internet.
Example: wget http://example.com/file.txt
This downloads file.txt
from example.com
.
18. sed – Stream Editor
The sed command is used for text manipulation, such as find and replace operations.
Example: sed -i ‘s/old/new/g’ file.txt
This replaces all occurrences of ‘old’ with ‘new’ in file.txt.
In conclusion, mastering these Linux commands can significantly enhance your productivity and efficiency. Whether you’re a developer, tester, or system administrator, these commands are indispensable tools in your arsenal. Remember, the best way to learn is by doing, so don’t hesitate to experiment and explore the vast capabilities of the Linux command line.
Are you ready to take the first step towards becoming a successful automation tester? Let’s embark on this exciting journey together! Join our new batch at https://sdet.live/become Use Code “PROMODE” for 10% OFF!” We’re starting a new batch soon