How to choose a key used rather than the default ~/.ssh/id_rsa when ssh to a remote server for a specific host? You have at least 2 choices for choosing the key used by ssh. Taking ~/.ssh/key1 and user@example.com as the example here. Method one, specify the key in command line with the -i option of
Read more
Tag: Tutorial
How to check whether a function has been defined in Bash?
Posted onI would like to know whether a function, say f1(), has already been defined in Bash. How should I do it? You can use the type -t to get a string of the type of the name: If the -t option is used, type prints a string which is one of alias, keyword, function, builtin,
Read more
How to disable an option with a bash script?
Posted onIt 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
How to get the metadata of an AWS S3 object?
Posted onI upload files using the aws cli http://www.systutorials.com/239665/uploading-large-files-amazon-s3-aws-cli/ . But how to get the metadata of an object in AWS S3? You can use the s3api‘s head-object command to get the metadata of an object. Taking one example: $ aws s3api head-object –bucket test-hkust –key dir2/fileupload/fb0c6353-a90c-4522-9355-7cd16cf756ff.file.txt It will print results like { “AcceptRanges”: “bytes”, “ContentType”:
Read more
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 change my policy of scheduling in hadoop?
Posted onI want to change policy of scheduling in Hadoop, how to I can change job order in map reduce automatically. Assume you are using Hadoop 2 / YARN. The configuration parameter named yarn.resourcemanager.scheduler.class controls the class to be used as the resource scheduler for YARN/Hadoop. The default value for the scheduler class (check more at
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 get file extension in JavaScript?
Posted onHow to get file extension from a file name in JavaScript? For examples, For “file.txt”, I want to get “txt”. For “file2.multi.ext.fileext”, I want to get “fileext”. This JavaScript function works well for me. function getExt(filename) { var idx = filename.lastIndexOf(‘.’); // handle cases like, .htaccess, filename return (idx < 1) ? “” : filename.substr(idx
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 config Git remote server on Bitbucket or Github
Posted onFor your first push with git, you may get following errors when you use github or bitbucket. $ git push No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as ‘master’. fatal: The remote end hung up unexpectedly Everything up-to-date Just run following command to set your remote
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