DAY -3Basic Linux Commands for Beginners

TABLE OF CONTENTS
\>> Introduction:
Linux, with its powerful command-line interface, has become the go-to operating system for many DevOps professionals. Its flexibility and extensive toolset make it an ideal choice for managing and automating various tasks in the DevOps workflow. In this blog post, we will explore a range of essential Linux commands that every DevOps practitioner should be familiar with. We will provide detailed explanations of each command along with practical examples to help you grasp their functionalities effectively.
📃List of Basic Linux Commands:
- ls
List Directory Contents: The 'ls' command allows you to view the contents of a directory. You can use it to obtain a list of files and directories within the current directory or a specified location.
Example:
COPY
$ ls
file1.txt file2.txt directory1
$ ls /home/user/Documents
file1.docx file2.pdf directory2
- cd
Change Directory: The 'cd' command is used to navigate through different directories in the file system.
Example:
COPY
$ cd /var/log
- pwd
Print Working Directory: The 'pwd' command displays the current working directory, allowing you to verify your location within the file system.
Example:
COPY
$ pwd
/home/user/Documents
- mkdir
Make Directory: With the 'mkdir' command, you can create a new directory.
Example:
COPY
$ mkdir new_directory
- cp
Copy Files and Directories: The 'cp' command enables you to create copies of files and directories.
Example:
COPY
$ cp file1.txt /home/user/Documents
- mv
Move and Rename Files and Directories: The 'mv' command allows you to move files or directories to a different location or rename them.
Example:
COPY
$ mv file1.txt /home/user/Documents
$ mv file1.txt file_new.txt
- rm
Remove Files and Directories: The 'rm' command is used to delete files and directories.
Example:
COPY
$ rm file1.txt
$ rm -r directory1
- cat
Concatenate and Display File Content: The 'cat' command displays the content of a file or concatenates multiple files into a single output.
Example:
COPY
$ cat file1.txt
$ cat file1.txt file2.txt > merged_file.txt
- grep
Search Text Patterns: The 'grep' command allows you to search for specific text patterns within files.
Example:
COPY
$ grep "error" logfile.txt
- chmod
Change File Permissions: The 'chmod' command enables you to change the permissions of files and directories.
Example:
COPY
$ chmod 644 file.txt
- chown
Change File Ownership: The 'chown' command lets you change the ownership of files and directories.
Example:
COPY
$ chown user:group file.txt
- ps
Process Status: The 'ps' command displays information about active processes running on the system.
Example:
COPY
$ ps -ef
- top
Monitor System Resources: The 'top' command provides real-time information about system resource usage, including CPU, memory, and processes.
Example:
COPY
$ top
- wget
Download Files from the Web: With the 'wget' command, you can download files from the internet via a terminal.
Example:
COPY
$ wget https://hardikpansani./file.zip
- tar
Archive and Extract Files: The 'tar' command allows you to create archives (tarballs) and extract files from them.
Example:
COPY
$ tar -cvf archive.tar hardik1.txt hardik2.txt
$ tar -xvf archive.tar
- ssh
Secure Shell: The 'ssh' command establishes a secure connection to a remote server.
Example:
COPY
$ ssh username@remote_server
- scp
Securely Copy Files Between Hosts: The 'scp' command allows you to securely copy files between local and remote hosts.
Example:
COPY
$ scp file.txt username@remote_server:/path/to/destination
- find
Search for Files and Directories: The 'find' command is used to search for files and directories based on various criteria.
Example:
COPY
$ find /var/log -name "*.log"
- tail
Display the End of a File: The 'tail' command displays the last lines of a file, making it useful for monitoring logs.
Example:
COPY
$ tail -n 10 logfile.txt
- history
View Command History: The 'history' command lists previously executed commands in the terminal.
Example:
COPY
$ history
- df
Disk Free: The 'df' command displays information about disk space usage on file systems.
Example:
COPY
$ df -h
- du
Disk Usage: The 'du' command provides a summary of disk usage for files and directories.
Example:
COPY
$ du -sh /path/to/directory
- ln
Create Links: The 'ln' command creates hard or symbolic links to files and directories.
Example:
COPY
$ ln -s /path/to/file link_name
- systemctl
Systemd Control: The 'systemctl' command allows control of the systemd system and service manager.
Example:
COPY
$ systemctl start service_name
$ systemctl stop service_name
$ systemctl restart service_name
- journalctl
Systemd Journal: The 'journalctl' command queries and displays log data from the systemd journal.
Example:
COPY
$ journalctl -u service_name
- ifconfig
Network Configuration: The 'ifconfig' command displays and configures network interfaces.
Example:
COPY
$ ifconfig
- netstat
Network Statistics: The 'netstat' command displays network connections, routing tables, and network interface statistics.
Example:
COPY
$ netstat -tuln
- ssh-keygen
SSH Key Generation: The 'ssh-keygen' command generates SSH key pairs for secure authentication.
Example:
COPY
$ ssh-keygen -t rsa -b 4096
- sed
Stream Editor: The 'sed' command is a powerful text editor for modifying and transforming text.
Example:
COPY
$ sed 's/old_text/new_text/g' file.txt
- curl
Transfer Data with URLs: The 'curl' command is used to transfer data to or from a server using various protocols.
Example:
COPY
$ curl -O https://example.com/file.txt
- rsync
Remote File Synchronization: The 'rsync' command is used to synchronize files and directories between local and remote systems.
Example:
COPY
$ rsync -avz /local/path/ username@remote:/remote/path/
- awk
Text Processing and Pattern Matching: The 'awk' command is a versatile tool for processing and manipulating text files based on patterns.
Example:
COPY
$ awk '/pattern/ { print $1 }' file.txt
- grep -r
Recursive File Search: The 'grep -r' command searches for a specified pattern recursively in files and directories.
Example:
COPY
$ grep -r "pattern" /path/to/directory/
- tar and gzip
Compress and Extract Files: The 'tar' command, combined with 'gzip', creates compressed tarball archives and extracts files from them.
Example:
COPY
$ tar -czvf archive.tar.gz /path/to/directory/
$ tar -xzvf archive.tar.gz
- sort
Sort Lines in Text Files: The 'sort' command sorts the lines in a text file based on a specified criteria.
Example:
COPY
$ sort file.txt
- find and xargs
Execute Commands on Found Files: Combining the 'find' and 'xargs' commands allows you to perform actions on files found by the 'find' command.
Example:
COPY
$ find /path/to/directory -name "*.txt" -type f -print0 | xargs -0 rm
- cron
Schedule Jobs: The 'cron' command allows you to schedule recurring jobs and tasks on a Linux system.
Example:
COPY
$ crontab -e
- diff
Compare Files: The 'diff' command compares two files and displays the differences between them.
Example:
COPY
$ diff file1.txt file2.txt
- scp with SSH Keys
Securely Copy Files with SSH Key Authentication: The 'scp' command can be used with SSH key authentication for secure file copying between hosts.
Example:
COPY
$ scp -i ~/.ssh/private_key.pem file.txt username@remote:/path/to/destination
- lsof
List Open Files and Processes: The 'lsof' command lists open files and processes running on a system.
Example:
COPY
$ lsof -i :port_number
Conclusion:
In this blog post, we have explored a range of essential Linux commands that are invaluable for DevOps professionals. Understanding and utilizing these commands will empower you to navigate the Linux environment, manage files and directories efficiently, monitor system resources, and perform various automation tasks. By mastering these commands, you'll be equipped with the necessary skills to streamline your DevOps workflow and enhance your productivity as a professional in the field.
Thanks for Reading
#
