Ga naar inhoud

Het touch commando

Controleren of touch aanwezig is

Het touch-commando is een veelgebruikt Linux-commando en staat bijna altijd standaard op je systeem geΓ―nstalleerd.
Het maakt deel uit van het pakket GNU coreutils, dat basiscommando’s levert zoals cp, ls, mv, rm, en cat.

Wil je controleren of touch aanwezig is, dan kun je de versie opvragen:

touch --version
Voorbeeldoutput
touch (GNU coreutils) 9.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.

βš™οΈ Installeren van touch

Het commando touch maakt deel uit van het pakket GNU coreutils.
Dit pakket bevat de meest gebruikte basiscommando’s in Linux, zoals cp, ls, mv, rm, en cat.

πŸ‘‰ Daarom is touch op vrijwel alle Linux-distributies standaard geΓ―nstalleerd, inclusief Debian en Ubuntu.
Alleen in uitzonderlijke gevallen, zoals zeer minimale systemen of custom builds, moet je het handmatig installeren.

Installatie op Debian/Ubuntu:

sudo apt update
sudo apt install coreutils

Voorbeeldoutput
touch (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Hieronder vind je enkele veelgebruikte combinaties van het touch-commando:

  • touch bestand.txt β†’ Maak een leeg bestand aan of update de timestamp
Voorbeeld gebruik van touch bestand.txt

Commando:

touch bestand.txt
Voorbeeldoutput:
# bestand.txt is aangemaakt of de timestamp is bijgewerkt

  • touch -a bestand.txt β†’ Update alleen de toegangstijd

  • touch -m bestand.txt β†’ Update alleen de wijzigingstijd

  • touch -c bestand.txt β†’ Maak het bestand niet aan als het niet bestaat

  • touch -v bestand.txt β†’ Laat zien wat er gebeurt

  • touch -t 202509081230 bestand.txt β†’ Stel tijd en datum expliciet in (YYYYMMDDhhmm)

  • touch --date="2025-09-08 12:30" bestand.txt β†’ Stel datum en tijd in met een leesbare string

  • touch -r referentie.txt bestand.txt β†’ Stel timestamp gelijk aan een ander bestand

  • touch --no-create bestand.txt β†’ Update timestamp, maar maak bestand niet aan

  • touch --time=atime bestand.txt β†’ Wijzig alleen de toegangstijd

  • touch --time=mtime bestand.txt β†’ Wijzig alleen de wijzigingstijd

Het touch-commando heeft weinig configuratie. Je kunt echter aliases gebruiken voor standaardopties.

1. Per gebruiker instellen

Plaats instellingen in je shell-configuratie:

alias touch='touch -v'

Dit zorgt dat altijd een melding wordt weergegeven bij het aanmaken of bijwerken van bestanden.

2. System-wide instellen

Plaats dezelfde alias in /etc/bash.bashrc of /etc/profile.

Voordelen: - Alle gebruikers krijgen dezelfde standaardopties.

Logging van het touch-commando

Het touch-commando schrijft zelf geen logbestanden weg.
Wil je gebruik van touch monitoren, dan kan dat met auditd.

Voorbeeld auditd regel

sudo auditctl -w /bin/touch -p x -k touch_monitor
  • -w /bin/touch β†’ bewaak het bestand /bin/touch
  • -p x β†’ log bij uitvoeren
  • -k touch_monitor β†’ tag voor herkenning

Logs bekijken:

ausearch -k touch_monitor

Of rechtstreeks in:

less /var/log/audit/audit.log

Coreutils en het touch-commando

Het touch-commando maakt deel uit van coreutils.
Je kunt touch dus niet apart updaten, alleen het hele pakket.

sudo apt update
sudo apt install --only-upgrade coreutils

Verwijderen van touch

Het touch-commando is een fundamenteel onderdeel van Linux.
Het verwijderen kan scripts of systeemfunctionaliteit breken.
Gebruik liever permissies of een alias als je het wilt beperken.

Voorbeeld alias om touch te blokkeren:

alias touch='echo "touch is uitgeschakeld"'

Permissies aanpassen:

sudo chmod 700 /bin/touch
(Alleen root kan het uitvoeren)

πŸ“– Handleiding

De ingebouwde handleiding van Linux-commando’s is altijd beschikbaar via man.
Voor touch:

man touch
Voorbeeld
TOUCH(1)                   User Commands                   TOUCH(1)

NAME
       touch - change file timestamps

SYNOPSIS
       touch [OPTION]... FILE...

DESCRIPTION
       Update the access and modification times of each FILE to the current time.
       A FILE is created if it does not exist.