Learn a new Linux command every day :-)

Did you know?

To debug a bash script you can add set -x directive into the beginning.

#!/bin/bash set -x [your script goes here]
interesting hmm. How do you recall it? How do you debug it after the set -x?

let’s say i have some long command there. Haven’t tried this one yet.

edit: seems more like a shell script to me due to that shabang/shebang thing.
 
Last edited:
interesting hmm. How do you recall it? How do you debug it after the set -x?

let’s say i have some long command there. Haven’t tried this one yet.

edit: seems more like a shell script to me due to that shabang thing.
Thanks to set -x, we can see every action that the script performs. It starts with + character, and then the standard output is visible after this action. This makes it easier to debug the bash script, because all the variables are visible in the commands. And it can help a lot, when your variables are being calculated in real-time mode.
When I didn't know about set -x, I output the variables I needed in different places of the script using echo during debugging to understand what happens there after each command. But this way is much easier.
So, for me, set -x, is just a discovery of this year!
 
Thanks to set -x, we can see every action that the script performs. It starts with + character, and then the standard output is visible after this action. This makes it easier to debug the bash script, because all the variables are visible in the commands. And it can help a lot, when your variables are being calculated in real-time mode.
When I didn't know about set -x, I output the variables I needed in different places of the script using echo during debugging to understand what happens there after each command. But this way is much easier.
So, for me, set -x, is just a discovery of this year!
why the shebang then? Do you directly call that sequence in terminal or do you use a shell script to execute it? Thanks for the tip because i am surely gonna try it tomorrow when I get to my lappy.
 
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
So you work in radioactive weapons departament?
 
I prefer to use *.sh files.
I would advise to launch something like my script below for better understanding. You will see how each line had had worked.

#!/bin/bash

set -x

read -p 'Enter swap size in megabytes: ' size_mb
size_kb=$((1024*${size_mb}))
dd if=/dev/zero of=/swap bs=1024 count=${size_kb}
chmod 0600 /swap
mkswap /swap
swapon /swap
if [ "$(grep '/swap' /etc/fstab)" ]; then
echo "Error: file /etc/fstab already has 'Swap' record"
else
echo "Add Swap record to /etc/fstab"
echo -e '\n/swap swap swap defaults 0 0' >> /etc/fstab
fi
swapon --show
 
@raitoxxxx
where do i see it, as in the log? makes sense except i dunno the debug part.

bhw, cmon guys, make the editor better. Can’t even quote to these basic posts. :/

@Diamond Damien
1709321145728.png



Strap-on?

What is this whole thing doing. I removed my computer. Will paste into chat gpt.

https://pastebin.com/h4iU2Anq

thats just a perpetual ram trick ;)
 
Did you know?

To debug a bash script you can add set -x directive into the beginning.

#!/bin/bash set -x [your script goes here]

Use case

set -x example.png


Look at those + symbols
No need to echo or print name, age, place variables separately, they just auto filled up
 
Last edited:
@raitoxxxx
where do i see it, as in the log? makes sense except i dunno the debug part.

bhw, cmon guys, make the editor better. Can’t even quote to these basic posts. :/



thats just a perpetual ram trick ;)
It doesn't exist in windows. Hehe

It's unix trick.

So this is some other way of thinking.
 
It really depend what you want to achieve or will be working on now can be easily used with the graphic interface, still is good to know a few commands because at some point will be a requirement.
 
Linux on UIs is worse than windows.

I'll learn tomorrow and throw 1000 commands here.
 
It really d still is good to know a few commands because at some point will be a requirement.
Hire someone if you are in this situation, or atleast try to learn. Knowing a few commands won’t get you far. In fact, it can kill the project you are working on in one single command.
 

# system information commands:


1.1) know your file system related information, such as - size, use, available, mount

Code:
df -mh

1.2) know your disk information, like what is the device name of your physical disk, boot disk, etc.

Code:
sudo fdisk -l

1.3) identify whether your hard drive is based on HDD or SDD
Code:
lsblk -d -o name,rota

Note: if output of ROTA( aka Rotation) column is 1, that means, it is HDD

1.4) disk information in shorter format

Code:
lsblk

2.1) Your system RAM (and SWAP) information, like used, free, total, etc.

Code:
free -h

2.2) know your system RAM type(DDR3/DDR4), Speed, Manufacturer, etc.

Code:
sudo dmidecode --type 17

Note: run the below command to install 'dmidecode' package for Ubuntu users
sudo apt install dmidecode --yes

2.3) Detailed RAM information

Code:
cat /proc/meminfo

3.1) your Linux distribution information. E.g., Ubuntu or Centos and their version numbers
Code:
lsb_release -a

3.2) Linux kernel version
Code:
uname -r

4) your system CPU information, like how many cores are present, CPU family name, etc.
Code:
lscpu

5) live system usage information
Code:
top
Code:
htop
 
Last edited:
So far - bad.

These look vague.

What are these shortcuts \ commands meaning? Or is it random letters put together? Like "df" - is this standing for diagrams flicking or dripping filters? Or sone genius put super fckiny hacking code for super crypto 14 year old hackers.
 
So far - bad.

These look vague.

What are these shortcuts \ commands meaning? Or is it random letters put together? Like "df" - is this standing for diagrams flicking or dripping filters? Or sone genius put super fckiny hacking code for super crypto 14 year old hackers.
hmm i guess you have to know the basics first to follow any of these

search for a basic linux course on udemy or something. It is very simple. It is even simpler if you use mac and you know your file system .

df is a perfectly safe command for example.
 
Back
Top