When fatal error happened, we’d like to kill the program. How to exit the program in Node.js? You can use: process.exit() Here, “process” is a global process object. exit method ends the process. process.exit([code]) Ends the process with the specified code. If omitted, exit uses the ‘success’ code 0. To exit with a ‘failure’ code:
Read more
Category: QA
Questions and answers.
How to force ssh client to authenticate using password on Linux?
Posted onssh client can use many authentication methods like password, keys. On a server, I set password-less log in with private/public key. Now, I want to try whether the new password is set correctly by log on using ssh. By default, the key-based authentication method is used again. How to force ssh client to authenticate using
Read more
How to detect whether Linux runs in UEFI or BIOS mode inside the Linux?
Posted onHow to detect whether Linux runs in UEFI or BIOS mode inside the Linux itself without needed to boot the the management console of the mother board? You can detect whether Linux runs in EFI mode by checking whether /sys/firmware/efi exist. In bash, you can test by [ -d /sys/firmware/efi/ ] This technique is used
Read more
How to force a USB 3.0 port to work in USB 2.0 mode in Linux?
Posted onWe know that we can disable USB 3.0 in the BIOS. But is there a way to force a USB 3.0 port to work in USB 2.0 mode inside of a running Linux? On Linux on some platforms booted in BIOS modes, you can use the following command to force USB 2.0 modes for your
Read more
How to make “tree” output consistent on Linux
Posted onI tried tree on different Linux boxes to verify the files by diff. However, I found the format can be a little bit different on different nodes. For examples, the tree result could be . |– test2 | |– test4 | `– test5 `– test3 1 directory, 3 files or . ├── test2 │ ├──
Read more
Common SSD read/write throughput?
Posted onWhat is the common SSD read/write throughput on common SSDs? Following is a very brief test of the speed of a SSD that I have by hand: # time dd conv=fsync if=/dev/zero of=./test bs=8192 count=1048576 1048576+0 records in 1048576+0 records out 8589934592 bytes (8.6 GB) copied, 20.6098 s, 417 MB/s real 0m21.377s user 0m0.089s sys
Read more
How to test whether the git repository is dirty?
Posted onHow to test whether the git repository is dirty? git status can show this. But how to diagrammatically detect this in bash? This piece of bash code works like a charm for me: [[ $(git diff –shortstat 2> /dev/null | tail -n1) != “” ]] You can use it to build your script. For example,
Read more
How to get a FILE pointer from a file descriptor and how to get a file descriptor from a FILE pointer in C on Linux?
Posted onI would like to open files by open() directly. But how to get a FILE pointer from a file descriptor in C on Linux? And how to do the reverse direction: get a file descriptor from a FILE pointer? Get a FILE pointer from a file descriptor (e.g. fd) in C on Linux: FILE *file
Read more
How to open the preferences dialog in Gthumb 3.4 on Linux?
Posted onHow to open the preferences dialog in Gthumb 3.4 on Linux? There seems no options to open the dialog in the menu on the toolbar. It is in the application menu of gthumb under Gnome 3. Click gthumb application icon on the top left side of you desktop and in the menu you can find
Read more
How to get the latest commit’s hash in git?
Posted onI am looking for a better method for getting the latest commit’s hash in git. I know git log -1 can show the info of the latest commit and from the info of the latest commit I can use grep and other tools to get the hash. Is there better method supported from git? Note:
Read more
How to configure Linux to use the scanner in an HP all-in-one printer?
Posted onHow to configure Linux to use the scanner (not only the printer) in an HP all-in-one printer? The OS is Fedora 22 and the connection between the HP all-in-one printer and the PC is through wireless. The printer is working well. You can check this post for configuring the printer and scanner of HP All-In-One
Read more
How to advertise different gateway ip via DHCP in OpenWRT?
Posted onHow to advertise a different router/gateway ip via DHCP in OpenWRT? In general, you need to configure the DHCP option with code 3 (router). (A list of all options can be found in http://www.networksorcery.com/enp/protocol/bootp/options.htm ) For example, to advise the gateway IP 192.168.1.2, you will send this option: “3,192.168.1.2” Now, for OpenWRT, you have 2
Read more
How to export Google Chrome password on Linux?
Posted onHow to export my Google Chrome password on Linux to a human-readable text file? In newer versions of Chrome, the passwords are stored using the encrypted password storage provided by the system, either Gnome Keyring or KWallet. We need to force Chrome to use a temporary profile folder with unencrypted password storage. Step 1. Connect
Read more
Good free images hosting services on the Web?
Posted onSuggestions on some good free images hosting services on the Web? Two good free image hosting websites: Imgur: http://imgur.com/ Postimage.org: http://postimage.org/
How to find out the MX record for a domain on Linux?
Posted onHow to find out a domain’s MX record for Email on Linux? For example, to find which domain/IP the email to gmail.com is delivered to. You may make use of the host command. The -t option is used to select the query type. type can be any recognized query type: CNAME, NS, SOA, SIG, KEY,
Read more
How to host multiple websites on a Apache Linux web server?
Posted onI have a Linux web server with Apache (httpd). How to host multiple websites on Apache? To host websites www.example1.com and www.example2.com on a single node with Apache2 on a single IP, you can use VirtualHost as follows. Edit /etc/httpd/conf/httpd.conf and add the following lines: NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www/example1.com ServerName www.example1.com # Other
Read more
How to allow websites’ .htaccess files in Apache2?
Posted onHow to allow websites to use .htaccess files in Apache2 web servers? The AllowOverride directive controls this: http://httpd.apache.org/docs/current/mod/core.html#allowoverride To allow AllowOverride in a directory, add the following rules to the /etc/httpd/conf/httpd.conf or similar configuration file for your apache installation: <Directory “/var/www/www.example.com”> Options FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files.
Read more
How to force umount a NFS directory on Linux?
Posted onThe NFS server is down. It is reported “Stale NFS file handle”. I tried ‘umount’ and ‘umount -f’. But neither succeeded. # umount /mnt/store umount.nfs: /mnt/store: Stale NFS file handle # umount -f /mnt/store umount.nfs: /mnt/store: Stale NFS file handle How to force umounting the NFS without rebooting the Linux server? I usually have to
Read more
How to redirect anything written on a file to another file in linux?
Posted onSuppose we have two files, a.txt and b.txt . If we write anything in a.txt & b.txt, it should be redirected to c.txt. tee may help for this purpose. tee: duplicate standard input You may try a command like this: echo “hello” | tee -a a.txt >>b.txt Both a.txt and b.txt will contain the “hello”.
Read more
How to Add “nomodeset” to Grub2 in Fedora and Ubuntu
Posted onI need to add nomodeset to make my GPU card work on Linux. Latest Fedora and Ubuntu and their derives use grub2. How to add nomodeset permanently to grub2 on Fedora and Ubuntu? The parameters grub2 will use are stored in its grub.cfg file. The grub.cfg file is generated from grub’s default settings file /etc/default/grub.
Read more