It is possible to set an option inside a Bash script such as set -o errexit. But how to do the reverse thing, that is, to unset an option? Change – to + to do the reverse thing of unseting an option in bash. For example, to unset the errexit option set by set -o
Read more
Tag: Linux
How to get the CPU temperatur in command linux on Linux?
Posted onMost modern servers or computers have sensors to detect the temperature of various components. On Linux, how to get the CPU core temperatur in command linux? First, make sure the package “lm-sensors” is installed on your Linux and the command sensors works for you. Then, you can use this piece of script to get the
Read more
How to change a user’s username on Linux?
Posted onI want to rename a user’s username on Linux. For example, rename user u1 to user1. How to change a user’s username on Linux? You can use the usermod command to modify the user’s info. For changing the user name, you can use the -l option: -l, –login NEW_LOGIN The name of the user will
Read more
How to test whether PATH has a specific directory in it in Bash on Linux?
Posted onHow to test whether PATH has a specific directory in it in Bash on Linux? For example, how to test whether /usr/local/mytool/bin is in $PATH? Directories in the $PATH variable are separated by :. So you can use a regular expression to test whether the $PATH contains a directory. The code for your specific example
Read more
How to make the rpcbind.service auto start in systemd on Linux?
Posted onThe command systemctl enable rpcbind.service seems not work. The rpcbind.service does not start after rebooting. How to make/force the rpcbind.service auto start in systemd on Linux? You an force the rpcbind.service to start by making it be “wanted” by the target such as multi-user: # systemctl add-wants multi-user rpcbind.service This will force rpcbind.service to start.
How to make lftp to use key for authentication for sftp on Linux?
Posted onI have successfully enabled password-less ssh login to a remote server, say example.com with username user. But when I use lftp to log on the sftp by lftp sftp://user@example.com it still asks my password. How it make lftp use my private key to logon the remote lftp server? There is a little trick to make
Read more
How to get another user’s PATH in Bash on Linux?
Posted onHow to get the $PATH environment variables of another user in Bash on Linux? The current user running the Bash script is root. If the scripts is run by root, this piece of code will store the PATH from the environment of the user user1: user1path=$(su – $user1 -c env | grep ^PATH= | cut
Read more
How to test a file or directory exists in Python?
Posted onIn Bash, the [ -f ] and [ -d ] tests can test whether a file or a directory exist. What are the corresponding python method for these tests? For -f: **os.path.isfile(path)** Return True if path is an existing regular file. This follows symbolic links. For -d: **os.path.isdir(path)** Return True if path is an existing
Read more
How to scp multiple files from remote to local on Linux?
Posted onWith scp, copying several files such as file1 file2 to remote site can be passed by command line like $ scp file1 file2 user@remote: But how to scp multiple files from remote to local on Linux? You can do similar things by at least 2 method with scp: $ scp user@remote:file{1,2} ./ $ scp user@remote:”file1
Read more
How to get the script’s own path in sourced Bash script?
Posted onIn normal Bash script, $0 is the path to the script. However, when a script is sourced, such as . a.sh a.sh’s $0 does not give a.sh. How to get the a.sh inside a.sh? Short answer: use ${BASH_SOURCE[0]}. You can check this post for details and explanations: How to Get Bash Script’s Own Path.
How to test whether a user already exist on Linux?
Posted onHow to test whether a user account, say linuxuser, already exist on Linux? You may make use of id which tries to get user IDs. The Bash code snippet is as follows. user=hello id -u $user >/dev/null 2>&1 if [ “$?” == “0” ]; then echo “user $user already exist.” else echo “user $user doesn’t
Read more
How to move cursor to a specific byte in Vim?
Posted onIn Vim, ’20G’ moves the cursor to line 20 in command mode. But how to move the cursor to a specific byte in Vim? In normal mode, 20go will move the cursor to byte 20. Or in command line, :goto 20 or :go 20 From vimdoc: :[range]go[to] [count] [count]go Go to {count} byte in the
Read more
How to install MATE on Linux Mint 17 Qiana?
Posted onI am using Linux Ming 17 Qiana. How to install MATE on Linux Mint 17? In Linux Mint, the package that installs MATE is ‘mint-meta-mate’: $ sudo aptitude install mint-meta-mate
How to enable natual scroll of touchpad in MATE on Linux?
Posted onThere are options for Gnome 3 and Cinnamon to make touch pad “natual scroll”. But in MATE, there is no such options in its “Mouse” control options. How to enable natual scroll of touchpad in MATE on Linux? You may manually set the change of your ‘scrolls’ from the touch pad to negative values using
Read more
How to get a user’s home directory from the username in a variables in Bash?
Posted onIn Bash, ~username gives the username user’s home. However, this does not work for situations where username is in a variable such as ~$user How to get the home directory from the user name in a variable in Bash? You can use this Bash script snippet: userhome=$(eval echo ~$user) Here, $user get evaluated to its
Read more
How do I force Linux to unmount a filesystem?
Posted onSome time, Linux fails to unmount a filesystem reporting “device is busy”. I understand that this helps avoid data lost by disallowing unmouting a filesystem when it is being used. But for some situations, I am sure there is something wrong happened or I care not data lost, such as a NFS mounting while the
Read more
How to generate a CSR from a private SSL key?
Posted onI am renewing my SSL key for my websites. The CA requests a CSR. I have my private key. How to generate a CSR (Certificate Signing Request) from a private SSL key? You can generate a CSR from your private key with openssl: openssl req -new -key ssl.key -out req.pem Here, ssl.key is your private
Read more
Linux boots failed with “sulogin: can not open password database” while the /etc/passwd and /etc/shadow files look fine
Posted onLinux boots failed with “sulogin: can not open password database” while the /etc/passwd and /etc/shadow files look fine. How to fix this? The OS is Fedora 22. You may try this trick Step 1: boot Linux with rw init=/bin/bash following this tutorial. Step 2: after Linux booted, disable SELinux following this tutorial. Reboot. If it
Read more
How to manually set Vim’s filetype?
Posted onVim can detects the file types from quite well. But under certain situations, such as creating a new file, Vim does not automatically set the file type. How to manually set it? In side Vim, to set a filetype, set value to the filetype variable. For example, to set the filetype to php: :set filetype=php
How to debug media print view of Web page in Firefox?
Posted onHow to debug the media print view set by @media print {} in CSS of Web pages in Firefox? In firefox, after opening the Web page, First, hit “Shift + F2” to open the “Developer Toolbar” at the bottom. Second, in the “Developer Toobar”, input media emulate print and Firefox will show the print view
Read more