Learn a new Linux command every day :-)

sohom

Supreme Member
Joined
May 26, 2013
Messages
1,361
Reaction score
646
Hey friends,

Most of the people here are directly or indirectly working with websites.
Few of them are managing their sites on their own & the rest of them are out sourcing.

And till today, most websites are being hosted on Linux Server.

So why don't we collect all day to day Linux commands in one place?
That way, we can show our skills, and it will help the community too.
And for non-programmers, this will be a learning opportunity.

----------------------------------------------------------------------------------------------------------------------------------

I hope others will share their daily commands too.
 

# Commands to create, list and view a file:~


1.1) Create a blank file:


Code:
touch BLANK_FILE

1.2) create a file with single line of content:


Code:
echo "This is my comment for Day 1" > FILE_NAME

1.3) append another line to that same file:


Code:
echo "This is my comment for Day 2" >> FILE_NAME

Note: noticed the difference? to append you need to use two greater-than symbols

1.4) create a multi line file:


Code:
cat > MULTI_LINE_FILE << EOF
My file content line number 1.
My file content line number 2.
EOF

Note: here EOF => 'End of File'. It's just a pattern name, which should match the beginning and ending. In place of EOF, you can use any strings, such as EF.

2) View an existing file:


Code:
cat FILE_NAME


3.1) List all files in the present directory:


Code:
ls

3.2) list all files, including hidden files(filename starts with dot symbol) in the current directory:


Code:
la

3.3) list all files, including hidden files in the current directory, with details, such as- file size, total size, owner, permission, creation/modification date, etc. :


Code:
ls -lah
 
Last edited:
firebase init

a command I use from time to time for my work.
 
Now is time for a little of advance command. And these commands fall under the category of networking.
But they are very useful to examine your web server and to cross-check if any unexpected/fishy communication(incoming/outgoing) is on going.

Once examined, the next step is to take a decision about which of them needs to be added to your Firewall rules, so your website is safer.
...

# List all open ports on your web server

1.1) List tcp based open ports


Code:
sudo netstat -an | grep "LISTEN "

Note: port information is prefixed with IP information. Eg, if column output is 0.0.0.0:80, in that case, the port is 80 (for HTTP)

1.2) List tcp based open ports with more details, such as - PID(Process ID), application/command name, user, etc.


Code:
sudo lsof -nP -iTCP -sTCP:LISTEN

1.3) list both tcp & udp based open ports


Code:
sudo netstat -tulpn

Note: with the help of 'grep' command, you can limit the output information for a specific port.

Code:
sudo netstat -tulpn | grep 3306

For the above example, I used 3306 for the MySQL database. You can replace 3306 with a different port number; say 443 (for HTTPS)
 
Last edited:
Why learn Linux commands, if modern AI writes complex bash scripts in no time?

Because some of us are old school and could write a bash script without going to stackoverflow before ChatGPT happened too. Also because these basic Linux commands are a gateway to a more tech savvy self.
 
Why learn Linux commands, if modern AI writes complex bash scripts in no time?
chatGPT can easily give you a bash script that contains sudo rm -rf / somewhere at the bottom and when you run it, that will delete your whole server.

If you don't understand what the code does and simply copy paste it into your shell, you can very easily nuke your computer.

Don't trust AI blindly.
 
Code:
sudo rm -rf /*

apparently, it generates the launch code for the American nuclear bomb warhead a.k.a the "Minuteman III", and it also gives you the private number of Obama.
 
Why learn Linux commands, if modern AI writes complex bash scripts in no time?
coz what it writes does not matter. What you know matters. Learn it. Or you will be a newbie forever. Chatgpt is a crutch. Don’t get used to it. Use it to generate what you need.

ps, I really want to see you as an engineer in a radioactive weapons department.

btw Sohom, great job buddy. Please keep this thread going. Love it already. <3
 
Good thread for those that don´t have their own Gogol.
1709316001333.png


Good thread for those who are making the transition from AskJeeves to Netscape.
 
View attachment 325955


yeah gogol still not loading properly on my Erwise web browser yet... hopefully they will update soon.
Oh shite. Atleast this page will load in 10ms on a good nix server. I don’t see any image/other resources here.

Design is a perception. Fast loading pages are skillful devs being on their job.
 
Back
Top