Linux Parrot 101 - A short guide for new users

Freepoorman

Member
Joined
Mar 8, 2024
Messages
79
Reaction score
68
Credits
735
Hi everyone, I feel really bad that I haven´t been able to contribute to the forum in a while.
So this is a 6 page document I put together as a beginner's guide, a cheat sheet, and revision sheet for Parrot OS users.

Disclaimer: I am a relatively new Linux user, the information in this post was compiled by researching the learning objectives of a course named "Linux 101" offered by TCM Security. This is not their course content, this is independently researched content based on the headings of their learning objectives, and customizing the commands for my preferred distro: Parrot OS.






Linux Parrot 101



Welcome to the world of Linux command-line mastery, tailored for new Parrot OS users. This article will guide you through the essential commands and utilities that are the building blocks of your interaction with the system. Whether you're a novice or looking to refresh your skills, these commands will empower you to navigate and manage your files and directories with confidence.



### Section 1: Essential Linux Commands for Parrot OS Users

These commands not only enhance your ability to navigate and manage your system efficiently but also empower you to leverage the full potential of this versatile and secure operating system.



1.1 Basic Navigation

To begin your journey, you'll need to learn how to move around the filesystem using the command-line interface. These commands are your compass and map, allowing you to determine your current location, explore directories, and reach your desired files.



- pwd (Print Working Directory):

- Description: This command is like a compass that shows you where you are in the filesystem. It displays the full path of your current working directory.

- Example: Typing pwd will give you a result like ~/Documents, indicating that you are in the Documents folder within your home directory.



- ls (List):

- Description: Imagine ls as a flashlight that illuminates the contents of your current directory. It lists all the files and directories present in your current location.

- Example: When you type ls, you'll see a list of files and folders that are in the directory you're currently in.



- cd (Change Directory):

- Description: Think of cd as your feet, allowing you to walk to different directories. It changes your current working directory to the one you specify.

- Example: If you type cd /path/to/directory, you'll move to the directory specified by the path.



- cd .. (Change To Parent Directory):

- Description: This command is like taking a step back. It changes your current directory to the one directly above your current location.

- Example: Typing cd .. will take you up one level in the directory hierarchy.



1.2 File Manipulation

Now that you can navigate, let's learn how to create, move, rename, and delete files and directories. These operations are like organizing your digital desk, ensuring your files are where you need them when you need them.



- touch:

- Description: touch is like a blank canvas. It creates a new, empty file or updates the timestamp of an existing file, which can be useful for tracking when a file was last modified.

- Example: To create a new file named newfile.txt, you would type touch newfile.txt.

- mkdir (Make Directory):

- Description: mkdir is your tool for creating new folders. It's like adding a new drawer to your filing cabinet.

- Example: To create a new directory named newdir, simply type mkdir newdir.



- cp (Copy):

- Description: cp is your photocopier. It duplicates files or directories from one place to another, allowing you to have multiple copies of your data.

- Example: To copy a file named file1.txt to a destination directory, you would use:

cp file1.txt /path/to/destination.



- mv (Move):

- Description: mv is like a moving company. It transports or renames files and directories, helping you to rearrange your filesystem.

- Example: To move a file named file1.txt to a new location, you would type:

mv file1.txt /path/to/destination.



- rm (Remove):

- Description: rm is your delete key. It removes files or directories, so use it with caution as it permanently erases data.

- Example: To delete a file named file1.txt, you would enter rm file1.txt.



1.3 File Viewing and Editing

Sometimes, you'll need to peek at or tweak the contents of your files directly from the command line. These utilities are your magnifying glass and pen, allowing you to inspect and edit text data efficiently.



- cat (Concatenate):

- Description: cat is like a magnifying glass that shows you the entire content of a file at once. It can also concatenate files, which means joining them together.

- Example: To view the content of a file named file1.txt, you would use cat file1.txt.



- more and less:

- Description: These commands are like flipping through a book page by page. They allow you to view the content of a file one screen at a time, which is especially useful for large files.

- Example: To read a file named file1.txt one page at a time, you would type more file1.txt or

less file1.txt.



- nano and vi (Text Editors):

- Description: nano and vi are your digital pens and paper. They are command-line text editors for creating and editing files. nano is simpler for beginners, while vi offers more advanced features.

- Example: To open a file named file1.txt in the nano editor, you would enter nano file1.txt.



1.4 File Permissions and Ownership

Understanding and managing file permissions and ownership is like setting the locks on your digital drawers. It's crucial for maintaining security and controlling who can access your files.



- chmod (Change Mode):

- Description: chmod is like a key that changes the access permissions of a file or directory. It ensures that only authorized users can read, write, or execute the file.

- Example: To set the permissions of a file named file1.txt to allow the owner to read and write, and others to only read, you would use chmod 644 file1.txt.



- chown (Change Owner):

- Description: chown is like changing the name on the deed of a house. It changes the owner and group of a file or directory, which can be important for managing system files.

- Example: To change the owner and group of a file named file1.txt to parrot and users, respectively, you would type chown parrot:users file1.txt.





### Section 2: Seeking Assistance with Linux Commands

As you explore the vast landscape of Linux commands, you'll inevitably encounter new tools and options. This section will teach you how to access detailed documentation, understand command options, and become self-sufficient in learning new commands.



- man (Manual):

- Description: man is like having a detailed instruction manual at your fingertips. It provides a comprehensive manual page for a command, explaining its usage and available options.

- Example: To access the manual for the ls command, you would type man ls.



- info:

- Description: info is like an expanded version of the manual, offering more detailed documentation than man pages. It's particularly useful for understanding complex commands and their intricacies.

- Example: To view the info page for the ls command, you would enter info ls.



- --help:

- Description: The --help option is like a quick-start guide. Most commands have this option to provide a brief summary of their usage and available options.

- Example: To see a summary of the ls command's options, you would use ls --help.





### Section 3: Mastering Advanced Shell Concepts

As you become more comfortable with the basics, it's time to delve into advanced concepts that will supercharge your command-line capabilities. This section covers pipes and command substitution, which are like connecting different tools to create a powerful workflow.



3.1 Pipes (|)



- Description: Pipes are like a conveyor belt that connects the output of one command to the input of another, allowing you to chain commands together for complex data processing.

- Example: To list all files with the .txt extension, you could use ls -l | grep txt.



3.2 Command Substitution



- $(command):

- Description: This is like embedding a mini command within a larger one. It executes the inner command in a subshell and replaces it with its output, allowing you to use the results directly in your command.

- Example: To print the output of the ls command, you could use echo $(ls).



- 'command':

- Description: This old syntax for command substitution treats the enclosed command as a string rather than executing it.

- Example: echo 'ls' will print the string ls instead of listing files.





### Section 4: Navigating the Linux Filesystem Hierarchy Standard

The Linux filesystem is like a well-organized library, with each book (file) and section (directory) having its designated place. Understanding this structure is key to finding your way around and managing your files effectively.



- Example: A typical path to a user's documents directory in Parrot OS looks like ~/Documents, where ~ is the home directory and Documents is the folder where your documents are stored.





### Section 5: Mastering Regular Expressions

Regular expressions are like secret codes that allow you to search for specific patterns within text. They are a powerful tool for tasks such as finding and replacing text, validating input, and parsing log files. In this section, we'll introduce commands that use regular expressions to perform these tasks.



- grep:

- Description: grep is like a detective that searches for specific patterns within files. It's incredibly useful for finding lines of text that match a certain pattern.

- Example: To search for a pattern in a file named file.txt, you would use grep "pattern" file.txt.



- sed:

- Description: sed is a stream editor that can filter and transform text. It's like a text transformer, allowing you to replace, delete, and insert text based on patterns.

- Example: To replace all occurrences of old with new in a file named file.txt, you would use sed 's/old/new/g' file.txt.



- awk:

- Description: awk is a pattern scanning and processing language that can manipulate data and generate reports. It's like a mini programming language for text processing.

- Example: To print the first column of a file named file.txt, you would use:

awk '{print $1}' file.txt.





### Section 6: Performing Basic Administrative Actions

As a Parrot OS user, you'll often need to perform administrative tasks to keep your system up-to-date and running smoothly. This section covers commands that allow you to update the system, install software, and manage services.



- sudo:

- Description: sudo is like a master key that allows you to perform actions with the highest privileges, typically reserved for the system administrator.

- Example: To update the package lists with superuser privileges, you would use sudo apt update.



- apt:

- Description: apt is the package manager for Debian-based systems like Parrot OS. It's your tool for installing, updating, and managing software packages.

- Example: To install a package named package_name, you would use sudo apt install package_name.



- systemctl:

- Description: systemctl is the command for controlling system services. It's like a remote control for your system's services, allowing you to start, stop, and check their status.

- Example: To start a service named service_name, you would use:

sudo systemctl start service_name.





### Section 7: Crafting Short Linux Shell Scripts

Shell scripting is like writing a recipe for your computer to follow. It's a fundamental skill for automating repetitive tasks and creating custom workflows. This section covers the basics of script creation, including how to set up your script, handle variables, make decisions, loop through tasks, and debug your scripts.



7.1 Script Basics



- Shebang (#!/bin/bash):

- Description: The shebang line at the top of your script is like a title page that tells the system what interpreter to use to run your script.

- Example: The first line of your script file should be #!/bin/bash to indicate it's a bash script.



- Comments (# This is a comment):

- Description: Comments are like sticky notes within your script that explain what's happening. They are ignored by the interpreter and are for human readers.

- Example: To add a comment to your script, you would use # This is a comment.



7.2 Variables



- Define variables: variable_name=value.

- Example: To define a variable named myvar with the value "Hello, World!", you would use myvar="Hello, World!".



- Access variables: ${variable_name}.

- Example: To print the value of myvar, you would use echo ${myvar}.



7.3 Conditionals



- if, elif, else:

- Description: Conditionals are like decision points in your script. They allow your script to perform different actions based on whether certain conditions are true or false.

- Example: To check if a file named file.txt exists, you could use:

if [ -f file.txt ]; then echo "File exists"; fi.





- test or []:

- Description: test and [] are used to evaluate conditions within your script. They're like a truth detector for your script's logic.

- Example: To check if a file exists, you could also use if test -f file.txt; then echo "File exists"; fi.



7.4 Loops



- for:

- Description: for loops are like a repeating cycle that allows your script to perform an action for each item in a list.

- Example: To echo each file with a .txt extension in the current directory, you could use:

for file in *.txt; do echo $file; done.



- while:

- Description: while loops are like a continuous loop that keeps executing as long as a condition is true.

- Example: To keep checking if a file exists and echo a message, you could use:

while [ -f file.txt ]; do echo "File exists"; done.



7.5 Functions



- Define functions: function_name() { command1; command2; }.

- Description: Functions are like mini-scripts within your script. They allow you to group commands together and reuse them.

- Example: To define a function that greets a user, you could use greet() { echo "Hello, $1"; }.



- Call functions: function_name.

- Description: To use a function, you simply call its name.

- Example: To greet a user named User, you would use greet "User".



7.6 Exit Status



- $?:

- Description: $? holds the exit status of the last command executed. It's like a report card that tells you if the command was successful or not.

- Example: To check the exit status of a command, you would use echo $? after the command.



7.7 Debugging



- set -x:

- Description: set -x turns on debugging, which is like turning on a spotlight that shows you each step your script takes.

- Example: To start debugging at the beginning of your script, you would use set -x.



- set +x:

- Description: set +x turns off debugging, ending the spotlight on your script's steps.

- Example: To stop debugging in your script, you would use set +x.
 
Last edited:

Members online


Latest posts

Top