[Linux] Miscellaneous Commands (cont.)

1. to check current linux version and etc.

cat /etc/os-release
--------->>>>>-----------
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

 

2. to check current linux kernel info and etc.

uname -a
--------->>>>>-----------
Linux raspberrypi 5.10.90-v7l+ #1 SMP Sun Jan 16 03:12:50 KST 2022 armv7l GNU/Linux

(+ "uname" stands for "unix name")

 

3. to get current working directory

pwd -P
--------->>>>>-----------
/home/pi

(+ "pwd" stands for "print working directory")
(+ [-P] options is for 'physical directory', which returns without symbolic links)

 

4. (shell) "$0" with "dirname" command

"dirname" - Display directory portion of pathname
"$0" - the first parameter of the command

So when it comes to "dirname $0", it will returns the extact dirpath of the first parameter (especially the file)
To get exact full file path, you need to use it with "pwd" command (also with "-P" option would be better)

# test.sh
#!/bin/bash

dirPath="$(dirname "$0")"
echo $dirPath

sh test.sh
-------->>>--------
.

sh /home/pi/test.sh
-------->>>--------
/home/pi
# test.sh
#!/bin/bash

dirPath="$(dirname "$0")"
echo $dirPath

t="$( cd "$(dirname "$0")" ; pwd -P )"
echo $t


sh test.sh
-------->>>--------
.
/home/pi

sh /home/pi/test.sh
-------->>>--------
/home/pi
/home/pi

 

5. (make) "-j4" option

it will splits the work between all four cores, speeding up compilation significantly.
(for the machine which has multi-core, like RP2,3,4)

 

6. "cat" command

"cat" command stands for "concatenate"

And it will reads the input (the file or standard input) and gives their content writing to standard output.

So, when it comes to the command without any following parameter, just prints the keyboard input

 

7. 2>&1

n>&m : redirect [n] into [m]

0: standard input
1: standard output
2: standard error

2>&1 : redirect [standard error] into [standard output]