Skip to content

SysTutorials

  • Tutorials
  • Linux
  • Linux Manuals
  • Systems
  • Programming
  • Software
  • Subscribe
  • Search
SysTutorials

  • QA

    How to get file size in Python?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How to get a file’s size in Python from the full path of a file? You can use this piece of Python code: os.path.getsize(file_path) It returns the size in bytes. It raises os.error if the file does not exist or is inaccessible. Manual of os.path.getsize(): https://docs.python.org/2/library/os.path.html#os.path.getsize

    Read More How to get file size in Python?Continue

  • QA

    How to open a URL in a new window in JavaScript?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How to open a URL in a new window in JavaScript? For example, to open a new window to browse “http://www.systutorials.com“. Open the URL in a new window: url = “http://www.systutorials.com”; window.open(url); Some browser will open the window in a new tab depending on the configuration. If you want to force the browser to open…

    Read More How to open a URL in a new window in JavaScript?Continue

  • QA

    How to send POST request in JavaScript?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How to send POST request in JavaScript from the users’ browsers? One easy method I find is to use the jQuery library’s post() method. Here is one example that send POST request with data “file: filename” to the “/fileview” URL on the server and show the replied data: $.post(“/fileview”, {file: filename}, function (data) { //…

    Read More How to send POST request in JavaScript?Continue

  • QA

    How to get the file extension from a filename in Python?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How to get the file extension from a filename in Python? For example, I would like to get “.txt” from “file.txt”. The Python code: >>> name, ext = os.path.splitext(‘file.txt’) >>> name ‘file’ >>> ext ‘.txt’ Manual of os.path.splitext: https://docs.python.org/2/library/os.path.html#os.path.splitext

    Read More How to get the file extension from a filename in Python?Continue

  • QA

    How to iterate all files and directories under a directory in Python?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How to iterate all files and directories under a directory in Python? For example, I would like to iterate each file and directory under /mnt/data/ /mnt/data/ |– file.txt `– great That is: /mnt/data/files.txt /mnt/data/great You can use the os.walk to do this: root, dirs, files = os.walk(path).next() root will be the path.dirs will contain the…

    Read More How to iterate all files and directories under a directory in Python?Continue

  • QA

    How to set the replication factor for one file when it is uploaded by `hdfs dfs -put` command line in HDFS?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    When uploading a file by the hdfs dfs -put command line in HDFS, how to set a replication factor instead of the global one for that file? For example, HDFS’s global replication factor is 3. For some temporary files, I would like to save just one copy for faster uploading and saving disk space. The…

    Read More How to set the replication factor for one file when it is uploaded by `hdfs dfs -put` command line in HDFS?Continue

  • QA

    How to exit the program in Node.js?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    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 How to exit the program in Node.js?Continue

  • QA

    How to detect the #hash and get the hash in JavaScript?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How to detect the #hash and get the hash in JavaScript? It’s better if no additional library is needed. That said, jquery is fine if it is needed. You can use this piece of JavaScript code: if (window.location.hash) { // hash found var hash = window.location.hash.substring(1); } else { // No hash }

    Read More How to detect the #hash and get the hash in JavaScript?Continue

  • QA

    How to parse POST data in node.js?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    Some JavaScript libraries send data by POST instead of JSON. In node.js, how to parse the POST data? You can use the “querystring” module: var qs = require(‘querystring’) The following piece of code works well for me. The comments should help you read the code well. var post_handle = function(request, response) { if (request.method ==…

    Read More How to parse POST data in node.js?Continue

  • QA

    How to force a USB 3.0 port to work in USB 2.0 mode in Linux?

    ByEric Ma Mar 24, 2018Apr 12, 2020

    We 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 force a USB 3.0 port to work in USB 2.0 mode in Linux?Continue

  • QA

    How to detect whether Linux runs in UEFI or BIOS mode inside the Linux?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How 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 detect whether Linux runs in UEFI or BIOS mode inside the Linux?Continue

  • QA

    How to force ssh client to authenticate using password on Linux?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    ssh 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 force ssh client to authenticate using password on Linux?Continue

  • QA

    Common SSD read/write throughput?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    What 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 Common SSD read/write throughput?Continue

  • QA

    How to make “tree” output consistent on Linux

    ByEric Ma Mar 24, 2018Mar 24, 2018

    I 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 How to make “tree” output consistent on LinuxContinue

  • QA

    How to test whether the git repository is dirty?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How 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 test whether the git repository is dirty?Continue

  • QA

    How to get the latest commit’s hash in git?

    ByEric Ma Mar 24, 2018Oct 7, 2019

    I 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 get the latest commit’s hash in git?Continue

  • QA

    How to open the preferences dialog in Gthumb 3.4 on Linux?

    ByEric Ma Mar 24, 2018Oct 7, 2019

    How 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 open the preferences dialog in Gthumb 3.4 on Linux?Continue

  • QA

    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?

    ByEric Ma Mar 24, 2018Jun 22, 2018

    I 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 get a FILE pointer from a file descriptor and how to get a file descriptor from a FILE pointer in C on Linux?Continue

  • QA

    How to export Google Chrome password on Linux?

    ByQ A Mar 24, 2018

    How 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 How to export Google Chrome password on Linux?Continue

  • QA

    How to advertise different gateway ip via DHCP in OpenWRT?

    ByEric Ma Mar 24, 2018Mar 24, 2018

    How 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 advertise different gateway ip via DHCP in OpenWRT?Continue

Page navigation

Previous PagePrevious 1 … 22 23 24 25 26 … 70 Next PageNext

© 2026 SysTutorials

  • Tutorials
  • Linux
  • Linux Manuals
  • Systems
  • Programming
  • Software
  • Subscribe
  • Search