advertisement

2019年8月9日

Linux 學習

Other users' home directories
Bash will expand a lone ~ to point to your home directory, but you can also use it to point to
other users' home directories. For example, if we wanted to refer to a file called fredsfile.txt in
Fred's home directory, we could type:
$ ./myprog ~fred/fredsfile.txt

my home directories
example: $ ./myprog ~/myfile.txt

Looking at directories
Sometimes, you'll want to look at a directory, rather than inside it. For these situations, you
can specify the -d option, which will tell ls to look at any directories that it would normally
look inside:
$ ls -dl /usr /usr/bin /usr/X11R6/bin ../share
drwxr-xr-x 4 root root 96 Dec 18 18:17 ../share
drwxr-xr-x 17 root root 576 Dec 24 09:03 /usr
drwxr-xr-x 2 root root 3192 Dec 26 12:52 /usr/X11R6/bin
drwxr-xr-x 2 root root 14576 Dec 27 08:56 /usr/bin

$ ls -dl /usr/local
drwxr-xr-x 8 root root 240 Dec 22 20:57 /usr/local
If we take a look at the second column from the left, we see that the directory /usr/local
(inode 5120) is referenced eight times. On my system, here are the various paths that
reference this inode:
/usr/local
/usr/local/.
/usr/local/bin/..
/usr/local/games/..
/usr/local/lib/..
/usr/local/sbin/..
/usr/local/share/..
/usr/local/src/..

mkdir -p
However, mkdir has a handy -p option that tells mkdir to create any missing parent
directories, as you can see here:
$ mkdir -p easy/as/pie

After typing this command, myfile.txt will be moved to /home/drobbins/myfile.txt. And if
/home/drobbins is on a different filesystem than /var/tmp, the mv command will handle the
copying of myfile.txt to the new filesystem and erasing it from the old filesystem. As you might guess, when myfile.txt is moved between filesystems, the myfile.txt at the new location
will have a new inode number. This is because every filesystem has its own independent set
of inode numbers.



A given inode can have any number of hard links, and
the inode will persist on the filesystem until the all the hard links disappear. When the last
hard link disappears and no program is holding the file open, Linux will delete the file
automatically.
you can only make hard links to files,not directories.

The second limitation
of hard links is that they can't span filesystems. This means that you can't create a link from
/usr/bin/bash to /bin/bash if your / and /usr directories exist on separate filesystems.


Note that double quotes will work similarly to single quotes, but will still allow bash to do
some limited expansion. Therefore, single quotes are your best bet when you are truly
interested in passing literal text to a command.


wildcards=globbing

https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
https://www.linuxjournal.com/content/bash-extended-globbing.
http://www.globtester.com/ globbing debuger

If the first character following the ‘[’ is a ‘!’ or a ‘^’ then any character not enclosed is matched.
wayne.su@rd1-4:~/configdec$ ls
myfile1  myfile2  myfile3  myfile4
wayne.su@rd1-4:~/configdec$ ls myfile[!2]
myfile1  myfile3  myfile4
wayne.su@rd1-4:~/configdec$ ls myfile[^2]

myfile1  myfile3  myfile4

regular expression


grep regex operatorMeaningExample
.Matches any single character.grep '.' file
grep 'foo.' input
?The preceding item(k) is optional and will be matched zero or at most, once.grep 'vivek?' /etc/passwd
*The preceding item(k) will be matched zero or more times.grep 'vivek*' /etc/passwd
+The preceding item will be matched one or more times.ls /var/log/ | grep -E "^[a-z]+\.log."
{N}The preceding item is matched exactly N times.egrep '[0-9]{2} input
{N,}The preceding item is matched N or more times.egrep '[0-9]{2,} input
{N,M}The preceding item is matched at least N times, but not more than M times.egrep '[0-9]{2,4} input
Represents the range if it’s not first or last in a list or the ending point of a range in a list.grep ':/bin/[a-z]*' /etc/passwd
^Matches the empty string at the beginning of a line; also represents the characters not in the range of a list.grep '^vivek' /etc/passwd
grep '[^0-9]*' /etc/passwd
$Matches the empty string at the end of a line.grep '^$' /etc/passwd
\bMatches the empty string at the edge of a word.vivek '\bvivek' /etc/passwd
\BMatches the empty string provided it’s not at the edge of a word.grep '\B/bin/bash /etc/passwd
\<Match the empty string at the beginning of word.grep '\<="" kbd="" style="box-sizing: inherit;">
\>Match the empty string at the end of word.grep 'bash\>' /etc/passwd
grep '\' /etc/passwd



You can reverse the meaning of the square brackets by putting a ^ immediately after the [.
In this case, the brackets will match any character that is not listed inside the brackets.

Again, note that we use [^] with regular expressions
$ grep dev.hda[^12] /etc/fstab

/dev/hda3 / reiserfs noatime,ro 1 1

#/dev/hda4 /mnt/extra reiserfs noatime,rw 1 1

^ and $ can be combined to match an entire line. For example, the following regex will match
a line that starts with the # character and ends with the . character, with any number of other
characters in between:
$ grep '^#.*\.$' /etc/fstab
# /etc/fstab: static file system information



When bash starts it opens the three standard file descriptors: stdin (file descriptor 0), stdout (file descriptor 1), and stderr (file descriptor 2). You can open more file descriptors (such as 3, 4, 5, ...), and you can close them






~ # ls -l a
ls: a: No such file or directory
~ # ls -l a 2>abc
~ # cat abc
ls: a: No such file or directory
~ # ls -l a 1>abc
ls: a: No such file or directory
~ # cat abc
~ # ls -l a &>abc
~ # cat abc

ls: a: No such file or directory

https://catonmat.net/bash-one-liners-explained-part-three

bash exit code
http://www.tldp.org/LDP/abs/html/exitcodes.html


makefile .PHONY的作用

讓cc變成一個偽目標,即使沒有cc這個檔案也可以執行。





fakeroot vs sudo
Why not just use sudo?
First of all, you don't need root privileges to build software and you don't need root privileges to compress them. So if you don't need it, you'd have to really be a Windows user to even think of getting that permission. But sarcasm aside, you may not even have root password.

Besides, let's say you do have root permissions. And let's say you want to pretend that a file should have read access only to the root. So you sudo, actually change the file owner and permissions to root, you get out of root shell and try to package everything. You fail because now you cannot read the file anymore since you don't have root access. So you have to sudo and compress and build the package as root. Effectively, you have to do everything as root.

This is BadTM.

As a packager, you don't need root permissions and you shouldn't get it. When you install a package, you may need to install some file (A) as root and that's where you need root permissions. All fakeroot does is to make this possible. It lets the packager list A as owned by root for the archiver, so that when the package is decompressed by the user, the archiver demands root permission and creates A as owned by root.


2019年6月12日

安裝 Nvidia 顯示卡驅動

下載驅動
https://www.nvidia.com/object/unix.html

# bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
# /sbin/shutdown -r now
# service lightdm stop
# chmod +x NVIDIA-Linux-x86_64-390.116.run
# ./NVIDIA-Linux-x86_64-390.116.run

-----Testing-----
$ nvidia-settings

2019年6月3日

Linux 方便簡單的截圖軟體 Imagemagick

安裝
# apt-get install imagemagick

執行
$ import sc1.png
$ import -window root image1.png

若出現
import: unable to open X server `' @ error/import.c/ImportImageCommand/366.
錯誤訊息

請重新開機即可

2019年6月2日

No common CD-ROM drive was detected 解決方式

安裝debian netinst  時出現 "No common CD-ROM drive was detected"

請使用https://rufus.ie/ rufus燒入軟體,將ISO燒製USB,並且選擇 DD Image mode


DD Image mode VS ISO Image mode

https://askubuntu.com/questions/896911/is-dd-image-disk-writing-permanent

2018年7月11日

真誠的讚美 帶給雙方美好的感受

如何真誠讚美一個人?

真誠讚美一個人要先有顆真誠的心,願意花時間仔細努力的觀察一個人的優點,找出優點甚至是跟別人不一樣突出的優點,給予讚美真誠的欣賞他


什麼叫不一樣突出的點

簡單舉
在禮堂台上演講者發問問題,讓台下的聽眾來舉手回答,等了一會兒有位人舉了手回答這沒人回答的問題,並且答案完全正確!!在休息時間裝水的時候,我剛好遇到他,我就說:嗨~你怎麼知道剛剛那題的答案呀OAO!! 他跟你說明之後原來他很熱愛看戰爭片所以他很熟這問題,我就覺得:哇賽! 現場那麼多人只有你答得出來耶 好猛喔OAO! 


任何人都一定有優點!!

當你學會觀察別人的優點後,其實會發現任何人都有優點~
簡單舉
身邊的同學有什麼優點? 成績好、很會聊、很會打球、願意無私分享知識。
在更小的事情~
我發現你不但不會隨手丟垃圾,只要你路過看到地上有垃圾都會主動撿起來。
玩遊戲的時候~我仔細觀察發現他玩遊戲滑鼠移動看起來好可愛哦O口O!! 看起來像撲撲車的感覺!!

那那如果是剛出生的小寶寶有什麼優點?  
.
.
.
.
.

2018年7月7日

嫉妒 可以誹謗一個人 也可以讓自己成長

嫉妒?

人類有多達27種情緒,簡單分喜、怒、哀、樂,細分還有渴望、嫉妒、同情等,嫉妒是怎麼樣的一種情緒~

只要是正常人都會有嫉妒之心,嫉妒主要對象是人,我們會嫉妒一個人的好,一個人的優點或快樂,卻不會嫉妒一個人的缺點或不快樂,嫉妒屬於七宗罪對人類惡行的之一,在嫉妒心的作用之下,人可能會透過謠言、搬弄是非、誹謗和其他間接的行為以貶損被嫉妒的人,而無意之間造口業。



不好的行為

口業不論是在道教、佛教、一貫道或基督教各宗教都共同指出一個方向(Google很多),不能口出惡言、散布謠言或搬弄是非詆毀他人,應該說好話,如果是無神論者,我可以跟你說有因就會有果,做了惡劣行為會不會有報應我沒見證過我不知道,也許有些人所說的報應只是人給予加害人的另一種回報,但我可以確定的是有因就會有果,有原因才會有結果,這也是在自然界科學都很常見的。

簡單舉如果一個人一天到晚都在想要怎麼陷害那個人要怎麼到處詆毀那個人,可能你會花很多心思在策劃如何陷害他,而當你一開口到處散佈不實謠言詆毀他人,別人對你的第一印象就是你很愛說說別人的壞話或毀謗他人,而這樣的結果不僅浪費時間在思考怎麼陷害一個人,一個經常到處口出惡言,會有多少人喜歡他呢?
相反的一個人仔細觀察一個人看出一個人的好,用真誠的心來讚美他,到處讚美別人說好話,別人想到你的第一瞬間不會是惡事,而是你的好話!
真誠的讚美

被害人的影響

這些惡事會帶給受害者很深的影響,一個被嫉妒的人常常會因為擔心「嫉妒」給自己帶來的人際關係的負面影響而感到不安,也因為害怕自己成為眾矢而感到惶恐,這種擔憂和顧慮造成他們巨大的心理折磨。


好的行為

嫉妒是複雜的情緒,我們要如何利用嫉妒的心來讓自己成長、讓自己進步~
仔細觀察他人找出他的優點向他學習或模仿來提升自我,讓自己成長、讓自己進步,嘗試讓自己接近或達到被嫉妒的人的成就,或者在其他方面能夠更勝於他,來緩和嫉妒的情緒。 簡單舉例如果有個英文很好的同學每次段考英文總是拿第一,而你是位很努力很拼命的人,不管再怎麼努力英文還是無法贏過他,仔細觀察為什麼他的英文總是這麼好,他的優點是什麼,向他學習他的優點或請教他,或許他從小在國外受教育所以英文對他來說易如反掌,那先天的優勢我們可以反過來思考我們自身的優勢,加強自身的強項來戰勝他人,達到自我成長也是可以的。




正向思考

當別人嫉妒你表示你實力很強,當別人抹黑搬弄是非表示他們不願意承認你的好,他們不願意承認他們自己錯了,他們是在幫你消業障,即使全世界沒人相信你,只要有個好朋友願意相信你就足夠,不管有多少人想要惡意扭曲抹黑一個人,問心無愧永遠堅持做一個正直的人不去傷害人堅持到底!


自我的影響

好的嫉妒會讓人有一種被他人的優勢或成功所激勵的感覺,可以讓自己成長許多,邁向成功的一步。

兩舌

兩舌則是利用機會在兩人之間道長話短並搬弄是非,最終目的在於挑撥離間,破壞當事人的處事和諧。

在日常生活中,犯了這四項口業,其惡口傷害了對方感情,妄言破壞了當事人人格,而搬弄是非及綺語亦使彼此相處無法真誠對待。 ref: https://zh.wikipedia.org/wiki/%E5%8F%A3%E6%A5%AD

2017年4月10日

How to choose right PWM frequency

The PWM switching frequency has to be much higher than what would affect the load (the device that uses the power), which is to say that the resultant waveform perceived by the load must be as smooth as possible. The rate (or frequency) at which the power supply must switch can vary greatly depending on load and application, for example
Switching has to be done several times a minute in an electric stove; 120 Hz in a lamp dimmer; between a few kilohertz (kHz), to tens of kHz for a motor drive; and well into the tens or hundreds of kHz in audio amplifiers and computer power supplies.


For a question like this, you will probably get as many answers as there are people interested in answering. Here is my answer: It depends.
Here are some of the limiting factors, first the lower limits:
  • Persistence of vision:
    • Different people are differently sensitive to flicker in a light source. Some would notice flicker even at 100 Hertz, others perhaps not even at as low as 10 Hz.
    • Motion of light source relative to the eye makes flicker more discernible, scaling up with speed of the motion.
    • Human vision sensitivity at low intensity of light - both ambient and source intensity. At very low intensity, the eye is much more sensitive to any change in intensity. So an LED operated at low duty cycle / low current and in a dark environment would require a higher minimum PWM frequency.
Now the upper limits:
  • LED turn-on characteristics: An LED cannot be toggled at arbitrarily high frequency, once the pulse duration approaches the turn-on time, the LED never really turns on fully, hence linearity of PWM control is lost to begin with, and at higher frequency / shorter pulses, eventually the LED just stays dim or off.
  • PWM provider capabilities: Your microcontroller would have its own maximum PWM rate, which sets a hard limit.
  • Switching losses: Any switching system, MOSFET based, BJT based, or other, suffers switching losses of power as switching rate increases. At one point this become significant both in terms of heating of switching device, and efficiency of illumination.
Thus, depending on these parameters, and any others affecting your specific requirement, the correct answer could be anywhere in the 50 Hz to few dozen KHz range.

motor frequency 可以測試不同頻率下輸出電流來決定

Ref:

2016年12月21日

Docker 安裝在 Windows 快速建置Linux Debian 環境

Host(PC)端安裝先前條件:

  1. Windows 7 64-bit OS 或 Windows 8 / Windows8.1
  2. Virtualization (虛擬化)已開啟
*如果你的作業系統是 Windows 10 請不要參照底下步驟
請參考這裡


OS作業系統請自行確認。

Virtualization 確認方式如下

Windows 8 / Windows8.1:
開啟工作管理員點選 CPU 如下圖

2016年12月11日

Compiler Wpasupplicant Source Code

# apt-get install openssl-dev libssl-dev libnl-3-dev libnl-genl-3-dev pkg-config

Then open the .config file:
vi .config
and uncomment the line:
CONFIG_LIBNL32=y
# make

https://w1.fi/wpa_supplicant/