Linux Basics commands - Part 1

About Me
As a dedicated tech enthusiast with a passion for continuous learning, I possess a robust background in software development and network engineering. My journey in the tech world is marked by an insatiable curiosity and a drive to solve complex problems through innovative solutions.
I have honed my skills across a diverse array of technologies, including Python, AWS, SQL, and Golang, and have a strong foundation in web development, API testing, and cloud computing. My hands-on experience ranges from creating sophisticated applications to optimizing network performance, underscored by a commitment to excellence and a meticulous attention to detail.
In addition to my technical prowess, I am an avid advocate for knowledge sharing, regularly contributing to the tech community through blogs and open-source projects. My proactive approach to professional development is demonstrated by my ongoing exploration of advanced concepts in programming and networking, ensuring that I stay at the forefront of industry trends.
My professional journey is a testament to my adaptability and eagerness to embrace new challenges, making me a valuable asset in any dynamic, forward-thinking team. Whether working on a collaborative project or independently, I bring a blend of analytical thinking, creative problem-solving, and a deep-seated passion for technology to every endeavor.
Part 1: Introduction to Basic Linux Commands
Setting Up Your Workspace
Create a new directory named "devops":
mkdir devopsNavigate into the "devops" directory:
cd devopsCreate a new file named "demofile.txt":
touch demofile.txtList the contents of the directory to ensure "demofile.txt" is created:
lsOutput:
demofile.txtDisplay the contents of "demofile.txt" (it should be empty):
cat demofile.txt
Adding Text to a File
Print a message to the terminal:
echo "Hello Dosto"Write the message "Hello Dosto" to "demofile.txt":
echo "Hello Dosto" > demofile.txtVerify the content of "demofile.txt":
cat demofile.txtOutput:
Hello Dosto
Creating and Viewing Additional Files
Create another file and add text:
echo "Hello Dosto" > one.txtDisplay the contents of "one.txt":
cat one.txtOutput:
Hello DostoView the beginning of "one.txt":
head one.txtView the end of "one.txt":
tail one.txtContinuously monitor the end of "one.txt":
tail -f one.txt
Using less and more Commands
View "one.txt" with
less:less one.txtView "one.txt" with
more:more one.txt
Current Directory and File Management
Display the current directory path:
pwd
Copying Files and Directories
Copy "one.txt" to the "devops" directory:
cp one.txt devops/Copy "one.txt" within the main directory:
cp devops/one.txt devops/copy/Copy a directory and its contents recursively:
cp -r copy/ devops/
Moving and Renaming Files and Directories
Move "demofile.txt" to the "copy" directory:
mv demofile.txt copy/Rename the "Devops" directory to "linuxfordevops":
mv Devops/ linuxfordevops
Listing and Counting
List files in the current directory:
lsDisplay the content of "one.txt":
cat one.txtOutput:
Hello DostoWord count of "one.txt":
wc one.txt
Creating Soft Links
Create and add text to a new file:
echo "hello this is softlink example." > devops-file.txtDisplay the content of "devops-file.txt":
cat devops-file.txtDisplay the current directory path and copy it:
pwdCreate a soft link to "devops-file.txt":
ln -s /home/dhruv/Devops/linuxfordevops/devops-file.txt softlink-file1List files in long format:
ls -ltrDisplay the content of the soft link:
cat softlink-file1
Creating Hard Links
Create and add text to another file:
echo "this is harlink example" > devopsfile.txtList files to verify the creation:
lsDisplay the content of "devopsfile.txt":
cat devopsfile.txtCreate a hard link to "devopsfile.txt":
ln /home/dhruv/Devops/linuxfordevops/devopsfile.txt hardlink-fileList files again to see the hard link:
lsDisplay the content of the hard link:
cat hardlink-file
Cutting and Sorting Content
Cut and display the first character of "one.txt":
cut -b 1 one.txtOutput:
HCut and display the first four characters of "one.txt":
cut -b 1-4 one.txtOutput:
Hell
Using tee
Echo text and use
teeto display and write to a file:echo "hey" | teeOutput:
heyEcho text and write to "hey.txt" using
tee:echo "hey" | tee hey.txtOutput:
heyDisplay the content of "hey.txt":
cat hey.txtOutput:
hey
Differences and Editing with vi
Compare two files:
diff one.txt hardlink-fileEdit "one.txt" using
vi:vi one.txtPress
ifor insert mode.Press
Escto exit insert mode.Type
:wqto write changes and quit.
Sort the content of "one.txt":
sort one.txt
Connecting to Remote Servers and System Monitoring
Check disk space:
df df -hNavigate to the parent directory and check disk usage:
cd .. du .List all files, including hidden ones:
ls -a
Managing Processes
View active processes:
ps topFind which process is using a file:
fuser filenameKill a process by ID:
kill -9 process_id
Memory and System Performance
Check free memory:
free free -hRun a command in the background and view the output later:
nohup free -h ls cat nohup.outDisplay the first five lines of "nohup.out":
head -n 5 nohup.outCheck system performance with
vmstat:vmstat vmstat -a
This guide covers essential Linux commands for beginners, offering practical examples and outputs to help you get started with basic file operations, linking, system monitoring, and process management.



