Skip to content

SysTutorials

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

  • QA

    How to get the hostname of the node in Go?

    ByQ A Mar 24, 2018

    In Go lang, how to get the hostname of the node? In Go, you can use the os.Hostname() function to get the hostname of the node. func Hostname() (name string, err error) Hostname returns the host name reported by the kernel. One example is as follows. The main.go source code: package main import ( “fmt”…

    Read More How to get the hostname of the node in Go?Continue

  • QA

    How to get the hostname of the node in C++?

    ByQ A Mar 24, 2018

    In C++, how to get the hostname of the node? In C++, the C way works too. However, with Boost, you can use the boost::asio::ip::host_name() function to get the hostname as a std::string: namespace boost { namespace asio { namespace ip { /// Get the current host name. BOOST_ASIO_DECL std::string host_name(); … More at http://www.boost.org/doc/libs/1_63_0/boost/asio/ip/host_name.hpp…

    Read More How to get the hostname of the node in C++?Continue

  • QA

    Getting Hostname in C Programs in Linux

    ByQ A Mar 24, 2018Oct 29, 2022

    In C, how to get the hostname of the node? In C, you may use the gethostname function. #include <unistd.h> int gethostname(char *name, size_t namelen); The gethostname() function shall return the standard host name for the current machine. The namelen argument shall specify the size of the array pointed to by the name argument. The…

    Read More Getting Hostname in C Programs in LinuxContinue

  • QA

    How to get the hostname of the node in Python?

    ByQ A Mar 24, 2018

    In Python, how to get the hostname of the node? In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import socket hostname = socket.gethostname() Example: $ python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type “help”, “copyright”, “credits” or “license”…

    Read More How to get the hostname of the node in Python?Continue

  • Linux | Tutorial

    Getting Hostname in Bash in Linux in 3 Ways

    ByEric Ma Mar 24, 2018Mar 25, 2023

    Getting the hostname of the node running a program can be useful in various scenarios, such as creating logs with the hostname, identifying which node a script is running on, or configuring a distributed system with different nodes. In Bash, there are several ways to retrieve the hostname of the machine, as mentioned in the…

    Read More Getting Hostname in Bash in Linux in 3 WaysContinue

  • QA

    How to convert epoch timestamp to human readable date format in Bash?

    ByQ A Mar 24, 2018

    In Bash, how to convert an epoch timestamp to a human readable date format? In Bash, you can use the date command’s -d option: date -d @<your epoch> Here @ specifies the epoch timestamp. One example: $ date -d @1490157520.05 Wed Mar 22 12:38:40 HKT 2017

    Read More How to convert epoch timestamp to human readable date format in Bash?Continue

  • QA

    How to convert epoch timestamp to human readable date format in Python?

    ByQ A Mar 24, 2018

    How to convert an epoch timestamp to a human readable date format? In Python: import time time.strftime(“%a, %d %b %Y %H:%M:%S %Z”, time.localtime(epoch)) One example: $ python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> import time >>>…

    Read More How to convert epoch timestamp to human readable date format in Python?Continue

  • QA

    Getting Epoch Timestamp in C

    ByQ A Mar 24, 2018Nov 10, 2020

    In C, how to get the epoch timestamp, the number of seconds passed since the epoch? In C, from man 7 time: UNIX systems represent time in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). A program can determine the calendar time using gettimeofday(2), which returns time (in seconds and microseconds) that have elapsed since…

    Read More Getting Epoch Timestamp in CContinue

  • QA

    How to get the epoch timestamp in Java?

    ByQ A Mar 24, 2018

    In Java, how to get the epoch timestamp, the number of seconds passed since the epoch? In Java, you can get the current time in milliseconds and then calculate the epoch time: long ts = System.currentTimeMillis()/1000; Example: $ wget –quiet https://github.com/albertlatacz/java-repl/releases/download/428/javarepl-428.jar -O /tmp/javarepo-428.jar && java -jar /tmp/javarepo-428.jar Welcome to JavaREPL version 428 (Java HotSpot(TM) 64-Bit…

    Read More How to get the epoch timestamp in Java?Continue

  • QA

    How to get the epoch timestamp in Perl?

    ByQ A Mar 24, 2018

    In Perl, how to get the epoch timestamp, the number of seconds passed since the epoch? In Perl, to get the epoch time, call the time function: my $ts = time Example: $ perl -e ‘print time . “n”‘ 1491473202

    Read More How to get the epoch timestamp in Perl?Continue

  • QA

    How to get the epoch timestamp in PHP?

    ByQ A Mar 24, 2018

    In PHP, how to get the epoch timestamp, the number of seconds passed since the epoch? In PHP, you can use the time() function. ts = time(); To get the microsecond together too as a float number, use the microtime(true) function. ts2 = microtime(true); Example: $ php -a Interactive shell php > echo time() ….

    Read More How to get the epoch timestamp in PHP?Continue

  • Programming | Tutorial

    How to get the epoch timestamp in Go lang?

    ByEric Ma Mar 24, 2018Feb 20, 2020

    In Go lang, how to get the epoch timestamp, the number of seconds passed since the epoch? In Go, you can use the time.Now() func to get current time and its Unix() func to convert it into an epoch timestamp: import(“time”) func getEpochTime() int64 { return time.Now().Unix() } If you would convert a time string…

    Read More How to get the epoch timestamp in Go lang?Continue

  • Programming | QA | Tutorial

    How to get the epoch timestamp in Python?

    ByQ A Mar 24, 2018Oct 24, 2020

    In Python, how to get the epoch time (the number of seconds since epoch)? In Python, you can get the epoch time by calling time.time() which return a floating number: import time print time.time() If you would like to get only the number of seconds, you may convert it to an integer. One example is…

    Read More How to get the epoch timestamp in Python?Continue

  • QA

    How to get the epoch timestamp in Bash?

    ByQ A Mar 24, 2018

    In Bash, how to get the epoch timestamp, the number of seconds passed since the epoch? In Bash, you can call the date command with format option “+%s”: date +%s Here, “%s” means: %s seconds since 1970-01-01 00:00:00 UTC

    Read More How to get the epoch timestamp in Bash?Continue

  • QA

    How to get an environment variable in Java?

    ByQ A Mar 24, 2018Mar 11, 2019

    In Java, how to get the value (string) of an environment variable? You may call the System.getenv(name) library function in Java to get the environment variable value. public static String getenv(String name) Parameters: name – the name of the environment variable Returns: the string value of the variable, or null if the variable is not…

    Read More How to get an environment variable in Java?Continue

  • QA

    How to get an environment variable in Python?

    ByQ A Mar 24, 2018

    In Python, how to get the value (string) of an environment variable? In Python, all environment variables can be accessed directly through os.environ import os print os.environ[‘HOME’] If the environment variable is not present, it will raise a KeyError. You can use get to return None if the environment variable is not present: print os.environ.get(‘ENV_MIGHT_EXIST’)…

    Read More How to get an environment variable in Python?Continue

  • QA

    How to get an environment variable in Bash?

    ByQ A Mar 24, 2018

    In Bash, how to get the value (string) of an environment variable? In Bash, just directly use: $VAR Note that if you assigned a value to the “local” variable $VAR in your program before reading the “environmental” $VAR, the $VAR will actually contain the value you assigned.

    Read More How to get an environment variable in Bash?Continue

  • QA

    How to process a file line by line in Bash?

    ByQ A Mar 24, 2018

    In Bash, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out. In Bash to process a file ./input.txt line by line: while read line ; do echo $line done < ./input.txt Reference: https://www.systutorials.com/qa/2166/how-to-process-a-file-line-by-line-in-go

    Read More How to process a file line by line in Bash?Continue

  • QA

    Reading and Processing a File Line by Line in C++

    ByQ A Mar 24, 2018Sep 26, 2021

    In C++, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out. In C++, you may open a input stream on the file and use the std::getline() function from the <string> to read content line by…

    Read More Reading and Processing a File Line by Line in C++Continue

  • QA

    How to process a file line by line in PHP?

    ByQ A Mar 24, 2018

    In PHP, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out. In PHP, you can use this code snippet to process a file line by line: if ( ($fhandle = fopen(“./input.txt”, “r”) !== FALSE )…

    Read More How to process a file line by line in PHP?Continue

Page navigation

Previous PagePrevious 1 … 14 15 16 17 18 … 70 Next PageNext

© 2026 SysTutorials

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