Linux how to display

Display Date And Time In Linux

H ow do I display date and time in Linux using the command line and GUI options?

To display date and time under Linux operating system using command prompt use the date command. It can also display the current time / date in the given FORMAT. We can set the system date and time as root user too.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux with the terminal application
Est. reading time 3 minutes

Syntax

Open a terminal and type the following command:
date

You can format the date as follows in dd-mm-yy format:
date +»%d-%m-%y»

Simply display the current time:
date «+%T»

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

To print the date of the day before yesterday, run:
date —date=’2 days ago’
Want to see the day of year of Christmas in the current year? Try:
date —date=’25 Dec’ +%j
Display the current full month name and the day of the month:
date ‘+%B %d’

Display date and time in Linux using the timedatectl

Most modern Linux distro with systemd use the timedatectl command. It is used to query and change the system clock and its settings, and enable or disable time synchronization services. All you have to do is type the following command:
$ timedatectl

TZ environment variable

The TZ environment tells Linux what time zone you are in. Many times when you want to change your time zone temporarily. For example, you might want to print the current date and time in “America/Los_Angeles” timezone even though you are in “Europe/London”. So we can set TZ, give a command like as follows when using TCSH/CSH:
setenv TZ timezone
For BASH/KSH/SH (see export command:
TZ=timezone; export TZ
Another option:
TZ=»America/Los_Angeles» date
TZ=»Asia/Tokyo» date
Use the following command to print a list of all timezones:
timedatectl list-timezones
timedatectl list-timezones | more
## filter out data using the grep command/egrep command ##
timedatectl list-timezones | grep -i Hong_kong
timedatectl list-timezones | grep -i paris
timedatectl list-timezones | grep -E -i ‘paris|london|kolkata’

The TZ Environment Variable on Linux

GUI Tool: Time Administration

The Time Administration Tool allows you to set the time, date and timezone of your system, as well as setting any time server to synchronize your local time server. Type the following command to start time admin tool:
sudo time-admin
## OR ##
time-admin

Fig.01: Linux Date and Time Administration Tool

How to change date and time settings with Gnome based Linux desktop

First, you need to Settings in Activities and then click Details in the sidebar. Make sure you click Date & Time in the sidebar to open the panel:

Conclusion

In this quick tutorial, you learned about the date command that you can use to see or change the date/time under Linux operating systems. We further explained how to use the GUI tools too. The date command has many more options. See man page by typing the following man command:
$ man date

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Display or print UNIX / Linux path

I am a new Linux or Unix system user and I am using a Debian Linux VPS. How do I print current path settings under BASH or sh or ksh shell?

In Linux or Unix-like file systems, the human-readable address of a resource is defined by PATH shell variable. On Unix / Linux like operating systems, (as well as on DOS / Windows and its descendants), PATH is an environment variable listing a set of paths to directories where executable may be found. This page explains how to print path variable using various commands under Linux and Unix-like systems.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux, Unix, or macOS terminal app
Est. reading time 2 minutes

Display current PATH in Linux

Use the echo command as follows:
echo «$PATH»
Here is my settings from Debian Linux system:

You can use the printf command as well to show the current PATH settings:
$ printf «%s\n» $PATH
Here is my settings from macOS/macOS X Unix desktop:

What is a PATH in Linux or Unix?

A PATH is nothing but the search path for commands. It is a colon-separated list of directories in which the shell looks for commands.

How to modify current PATH

Use the export command to add /opt/games to PATH, enter:
export PATH=$PATH:/opt/games
To format your PATH variable for easy viewing, add following code to your bash startup file (such as

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Now just run path:
$ path
Here is what I see on CentOS/RHEL/Fedora Linux:

Another option is to run the following command:
echo «$PATH» | tr «:» «\n» | nl

Fig.01: Printing $PATH on Linux or Unix-like system

Summing up

The default shell path ( $PATH variable) is system-dependent, and is set by the administrator who installs bash or ksh or any other shell. However, developers and other Linux and Unix system users can set up their own path using the export command under bash/sh/ksh.

Setting up PATH permanently

Users can edit the

/.profile to set up their path as follows for bash:

Printing PATH in Linux or Unix

Now run:
echo «$PATH»
printf «%s\n», $PATH

How to Checking Path in Unix and Linux

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

accepts an optional argument that is the name of a path-like variable.

Hi,
I did not get either of those path() working. I assume my version of unix does not recognize IFS when applying printf. But this works:

echo $PATH | sed ‘s/\:/\n/g’ | sort

Thanks for that, Pekka. I started using zsh, which has the same problem you described. The original solution works wonderfully in bash, but yours works in zsh.

Ugghh curly quotes. Could not copy and paste.

I am using Zshell, Prezto, OSX. The sed command replaces the : with an n

To get one path per line I used:

Hello Sir;
I am trying to run a program on a cluster and every time I run the program I have this message: mpiexec was unable to launch the specified application as it could not find an executable. ”
so I am suggesting that the program is not recognize the mpixec path. so I need to add the MPI path in my working directory.
my question is how to set this up?

hola necesito decargar un editor ok lo descargo en superusuario y cuando esta descargando me dice q no puede continuar … me aparece esto : dpkg: aviso: `ldconfig’ no se ha encontrado en el PATH o no es ejecutable.
dpkg: aviso: `start-stop-daemon’ no se ha encontrado en el PATH o no es ejecutable.
dpkg: error: 2 expected programs not found in PATH or not executable.
Note: root’s PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.
E: Sub-process /usr/bin/dpkg returned an error code (2)
Un paquete no se pudo instalar. Tratando de recuperarlo:
dpkg: aviso: `ldconfig’ no se ha encontrado en el PATH o no es ejecutable.
dpkg: aviso: `start-stop-daemon’ no se ha encontrado en el PATH o no es ejecutable.
dpkg: error: 2 expected programs not found in PATH or not executable.
Note: root’s PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.
help me..

In below code:
Node=/liferay-portal-5.2.0/jboss-tomcat-4.2.3/server/node_portal
export jboss=$Node/../..
echo $jboss

But I need Output as :

Please help me out in this.

How can I make PATH easily to view when I just execute the script? Thanks

You can search/replace within variables as you expand them.
The following replaces ‘:’ with newlines while expanding $PATH, so it’s done without using external commands:

Источник

How to Display Specific Lines of a File in Linux Command Line

How do I find the nth line in a file in Linux command line? How do I display line number x to line number y?

In Linux, there are several ways to achieve the same result. Printing specific lines from a file is no exception.

To display 13th line, you can use a combination of head and tail:

Or, you can use sed command:

To display line numbers from 20 to 25, you can combine head and tail commands like this:

Or, you can use the sed command like this:

Detailed explanation of each command follows next. I’ll also show the use of awk command for this purpose.

Display specific lines using head and tail commands

This is my favorite way of displaying lines of choice. I find it easier to remember and use.

Use a combination of head and tail command in the following function the line number x:

You can replace x with the line number you want to display. So, let’s say you want to display the 13th line of the file.

Explanation: You probably already know that the head command gets the lines of a file from the start while the tail command gets the lines from the end.

The “head -x” part of the command will get the first x lines of the files. It will then redirect this output to the tail command. The tail command will display all the lines starting from line number x.

Quite obviously, if you take 13 lines from the top, the lines starting from number 13 to the end will be the 13th line. That’s the logic behind this command.

Now let’s take our combination of head and tail commands to display more than one line.

Say you want to display all the lines from x to y. This includes the xth and yth lines also:

Let’s take a practical example. Suppose you want to print all the the lines from line number 20 to 25:

Use SED to display specific lines

The powerful sed command provides several ways of printing specific lines.

For example, to display the 10th line, you can use sed in the following manner:

The -n suppresses the output while the p command prints specific lines. Read this detailed SED guide to learn and understand it in detail.

To display all the lines from line number x to line number y, use this:

Use AWK to print specific lines from a file

The awk command could seem complicated and there is surely a learning curve involved. But like sed, awk is also quite powerful when it comes to editing and manipulating file contents.

NR denotes the ‘current record number’. Please read our detailed AWK command guide for more information.

To display all the lines from x to y, you can use awk command in the following manner:

It follows a syntax that is similar to most programming language.

I hope this quick article helped you in displaying specific lines of a file in Linux command line. If you know some other trick for this purpose, do share it with the rest of us in the comment section.

Источник

Читайте также:  Windows не выводит приветствие
Оцените статью