proxmox

How to Use the date Command in Linux: Step-by-Step Tutorial

How to Use the date Command in Linux: Step-by-Step Tutorial

#date #Command #Linux #StepbyStep #Tutorial

“Learn Linux TV”

It’s time to Learn Linux! The Linux Crash Course series on Learn Linux TV takes you through a valuable Linux-related concept, one video at a time. In this episode, Jay covers the date command.

*LEARN LINUX TV – YOUR HOME FOR LINUX-RELATED FUN AND LEARNING!*

*🎓 BRAND NEW UDEMY COURSES…

source

 

To see the full content, share this page by clicking one of the buttons below

Related Articles

23 Comments

  1. I found a way to navigate android phone files and i proceed to copy them (as much as possible because permission denial)
    I want to backup the boot.img at some point and then post it for backup for my specific model
    Anyone wanna help?
    Update
    Found the difference between android base linux files and copied files, can anyone help with rooting to access everything so we make/copy/extract the boot.img? here is the output
    this should be in the oroginal /etc my android
    sending incremental file list
    etc/
    etc/.pwd.lock
    etc/adduser.conf
    etc/bash.bashrc
    etc/bindresvport.blacklist
    etc/debconf.conf
    etc/debian_version
    etc/deluser.conf
    etc/e2scrub.conf
    etc/environment
    etc/fstab
    etc/gai.conf
    etc/group
    etc/gshadow
    etc/host.conf
    etc/hostname
    etc/hosts
    etc/issue
    etc/issue.net
    etc/ld.so.cache
    etc/ld.so.conf
    etc/legal
    etc/libaudit.conf
    etc/login.defs
    etc/lsb-release
    etc/machine-id
    etc/mke2fs.conf
    etc/netconfig
    etc/networks
    etc/nsswitch.conf
    etc/os-release -> ../usr/lib/os-release
    etc/pam.conf
    etc/passwd
    etc/profile
    etc/resolv.conf
    etc/rmt -> /usr/sbin/rmt
    etc/shadow
    etc/shells
    etc/subgid
    etc/subuid
    etc/sudo.conf
    etc/sudo_logsrvd.conf
    etc/sudoers
    etc/sysctl.conf
    etc/xattr.conf
    etc/alternatives/
    etc/alternatives/README
    etc/alternatives/awk -> /usr/bin/mawk
    etc/alternatives/nawk -> /usr/bin/mawk
    etc/alternatives/pager -> /bin/more
    etc/alternatives/rmt -> /usr/sbin/rmt-tar
    etc/alternatives/which -> /usr/bin/which.debianutils
    etc/apt/
    etc/apt/sources.list
    etc/apt/apt.conf.d/
    etc/apt/apt.conf.d/01-vendor-ubuntu
    etc/apt/apt.conf.d/01autoremove
    etc/apt/apt.conf.d/70debconf
    etc/apt/auth.conf.d/
    etc/apt/keyrings/
    etc/apt/preferences.d/
    etc/apt/sources.list.d/
    etc/apt/trusted.gpg.d/
    etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg
    etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg
    etc/cron.d/
    etc/cron.d/e2scrub_all
    etc/cron.daily/
    etc/cron.daily/apt-compat
    etc/cron.daily/dpkg
    etc/default/
    etc/default/rsync
    etc/default/useradd
    etc/dpkg/
    etc/dpkg/dpkg.cfg
    etc/dpkg/dpkg.cfg.d/
    etc/dpkg/dpkg.cfg.d/excludes
    etc/dpkg/origins/
    etc/dpkg/origins/debian
    etc/dpkg/origins/default -> ubuntu
    etc/dpkg/origins/ubuntu
    etc/gss/
    etc/gss/mech.d/
    etc/init.d/
    etc/init.d/hwclock.sh
    etc/init.d/procps
    etc/init.d/rsync
    etc/kernel/
    etc/kernel/postinst.d/
    etc/ld.so.conf.d/
    etc/ld.so.conf.d/aarch64-linux-gnu.conf
    etc/ld.so.conf.d/libc.conf
    etc/logrotate.d/
    etc/logrotate.d/alternatives
    etc/logrotate.d/apt
    etc/logrotate.d/dpkg
    etc/opt/
    etc/pam.d/
    etc/pam.d/chfn
    etc/pam.d/chpasswd
    etc/pam.d/chsh
    etc/pam.d/common-account
    etc/pam.d/common-auth
    etc/pam.d/common-password
    etc/pam.d/common-session
    etc/pam.d/common-session-noninteractive
    etc/pam.d/login
    etc/pam.d/newusers
    etc/pam.d/other
    etc/pam.d/passwd
    etc/pam.d/runuser
    etc/pam.d/runuser-l
    etc/pam.d/su
    etc/pam.d/su-l
    etc/pam.d/sudo
    etc/pam.d/sudo-i
    etc/profile.d/
    etc/profile.d/01-locale-fix.sh
    etc/rc0.d/
    etc/rc1.d/
    etc/rc2.d/
    etc/rc2.d/S01rsync -> ../init.d/rsync
    etc/rc3.d/
    etc/rc3.d/S01rsync -> ../init.d/rsync
    etc/rc4.d/
    etc/rc4.d/S01rsync -> ../init.d/rsync
    etc/rc5.d/
    etc/rc5.d/S01rsync -> ../init.d/rsync
    etc/rc6.d/
    etc/rcS.d/
    etc/rcS.d/S01procps -> ../init.d/procps
    etc/security/
    etc/security/access.conf
    etc/security/faillock.conf
    etc/security/group.conf
    etc/security/limits.conf
    etc/security/namespace.conf
    etc/security/namespace.init
    etc/security/opasswd
    etc/security/pam_env.conf
    etc/security/sepermit.conf
    etc/security/time.conf
    etc/security/limits.d/
    etc/security/namespace.d/
    etc/selinux/
    etc/selinux/semanage.conf
    etc/skel/
    etc/skel/.bash_logout
    etc/skel/.bashrc
    etc/skel/.profile
    etc/sudoers.d/
    etc/sudoers.d/README
    etc/sysctl.d/
    etc/sysctl.d/10-console-messages.conf
    etc/sysctl.d/10-ipv6-privacy.conf
    etc/sysctl.d/10-kernel-hardening.conf
    etc/sysctl.d/10-magic-sysrq.conf
    etc/sysctl.d/10-network-security.conf
    etc/sysctl.d/10-ptrace.conf
    etc/sysctl.d/10-zeropage.conf
    etc/sysctl.d/README.sysctl
    etc/systemd/
    etc/systemd/system/
    etc/systemd/system/sudo.service -> /dev/null
    etc/systemd/system/multi-user.target.wants/
    etc/systemd/system/multi-user.target.wants/e2scrub_reap.service -> /lib/systemd/system/e2scrub_reap.service
    etc/systemd/system/timers.target.wants/
    etc/systemd/system/timers.target.wants/apt-daily-upgrade.timer -> /lib/systemd/system/apt-daily-upgrade.timer
    etc/systemd/system/timers.target.wants/apt-daily.timer -> /lib/systemd/system/apt-daily.timer
    etc/systemd/system/timers.target.wants/dpkg-db-backup.timer -> /lib/systemd/system/dpkg-db-backup.timer
    etc/systemd/system/timers.target.wants/e2scrub_all.timer -> /lib/systemd/system/e2scrub_all.timer
    etc/systemd/system/timers.target.wants/fstrim.timer -> /lib/systemd/system/fstrim.timer
    etc/systemd/system/timers.target.wants/motd-news.timer -> /lib/systemd/system/motd-news.timer
    etc/systemd/user/
    etc/terminfo/
    etc/terminfo/README
    etc/update-motd.d/
    etc/update-motd.d/00-header
    etc/update-motd.d/10-help-text
    etc/update-motd.d/50-motd-news
    etc/update-motd.d/60-unminimize

    sent 5,503 bytes received 606 bytes 12,218.00 bytes/sec
    total size is 135,001 speedup is 22.10 (DRY RUN)

  2. date +%Y%m%d is one of the date commands with formatting I use the most. It prints the ISO formatted date of YEARMonthDay and is incredibly useful in scripting to do things like extensions on file names or dated entries. Throw in %H%M as well at the end and you can include the hour and minute for your entry as well. If you need more granularity, there are of course seconds, but also partial seconds which might be interesting on more busy systems.

  3. Hey, I'll be swapping over from Win10 to Linux sometime in 2025 before Win10 end of support and was wondering what Linux users generally do in regards to antivirus software. Are there popular options for Linux or are antivirus software not usually needed for various reasons?

  4. Format strings can contain more than just strftime-style formatting characters. You can write entire messages, and skip the echo/subshell convention:
    % date +"%Y-%m-%d %H:%M:%S"
    2024-08-27 22:17:25
    % date +"%Y-%m-%d %H:%M:%S – Script has ended."
    2024-08-27 22:17:33 – Script has ended.

    You can also discover the time in a different time zone. This is useful, for example, if your logs must be relevant for a world-wide support team. Any time zone corresponding to a file located in the /usr/share/zoneinfo tree will work.
    % date
    Tue Aug 27 22:17:42 PDT 2024
    % TZ=GMT date
    Wed Aug 28 05:17:47 GMT 2024

    With the Gnu "date" command (which is to say, neither the BSD/MacOS nor Busybox "date" command), you can also compute a date like this, to save yourself from doing non-trivial computations around the end of the month. This is especially true around daylight savings time changes, in leap years, and when leap seconds are significant:
    % date –date="+3 days"

    I often compute file names using like $(TZ=GMT date "+${TMPDIR:-/tmp}/%Y%m%d%H%M%S-filename") so that the files list in order of their creation times, a capability that neither the stat nor ls commands has. These are also human-readable, unlike the Unix epoch time when used for this purpose. Under some circumstances, I can add a sequence number or process ID to ensure that names are unique in case multiple processes try to create a similarly named file concurrently. Or I can create a directory using this convention, and write files with predictable names in there.

  5. Happy belated birthday!
    Thanks for the video. Even though I thought I " knew it all" when it came to the date command, you managed to teach me something new, as always: date -r
    I'm going to write a bash script around that because I wanted an easy way to check if a certain file I reference often was current. Sure, I could use ls -l, but I think date -r meets my needs better.

Leave a Reply