Inhoud
Linux Terminal : Commandoos
Zie vooral ook : De Linux Terminal gebruiken
https://www.debian.org/doc/manuals/refcard/refcard
using the ls command with the -l (long) and -h (human readable sizes) options to list the files
Nog verwerken :
- tldr
- plus de rest …
Over 'single quotes' en “double quotes” en `backticks` enzovoort :
bestanden en directories verwijderen
Eerst lezen ! Niet gokken !
https://linuxize.com/post/remove-directory-linux/
https://phoenixnap.com/kb/remove-directory-linux
https://askubuntu.com/questions/802996/how-to-remove-directory-with-all-of-its-contents
https://www.howtogeek.com/409115/how-to-delete-files-and-directories-in-the-linux-terminal/nl
Bekijk eerst de directorie met
tree
ls -lR
ls -LR
rm -d
rm -r
rmdir
Zoeken met find
Zoeken met find - op naam
. = de huidige directorie
~ = de huidige home directorie : /home/jijzelf (waarschijnlijk)
~ = $HOME
-type d = directory
-type f = bestand
-name = naam
find . -type d
find ~ -type d
find $HOME -type d
find . -type d -name fotoos
find . -type d -name *foto*
find $HOME -type d -name '*foto*'
linux gnome terminal find empty folder
https://askubuntu.com/questions/719912/how-to-find-all-empty-files-and-folders-in-a-specific-directory-including-files
find . -empty -exec ls -Fd {} \;
# Lege mappen zoeken en verwijderen
find . -empty -type d
find . -empty -type d -name 'naam*' | sort
find . -empty -type d -name 'naam*' | sort -r
find . -empty -type d -name 'naam*' -exec rm {}\;
# Zoek met specifieke namen
# Het gebruik van woorden en * zelf uitproberen. niet alles werkt. Mogelijk moet het met '*woord*'… Begin zonder de . Eventueel proberen met
# Zoek bestanden met specifieke namen find . -type f -name fotoos find . -type f -name Scherm* find . -type f -name *jpg find $HOME -type f -name *jpg find $HOME -type f -name *png # zoeken op png en ook op PNG ! Hier lijken de '' nodig... find $HOME -type f -name *[PpNnGg] find $HOME -type f -name '*[PpNnGg]'
Zoeken met find - rechten
Bestandsrechten wijzigen
Om de bestandsrechten van files en directories op de commandline te wijzigen :
# Alle files -rw-r--r-- geven :
find /mijnpad -type f -exec chmod 644 {} \;
find /mijnpad -type f -name *jpg -exec chmod 644 {} \;
# Alle directories -rwx-r-xr-x geven :
find /mijnpad -type d -exec chmod 755 {} \;
# Eigenaar en group wijzigen
# Ook hier geen * gebruiken !!!
chown -R user.group fileofdirectorynaam
# Bijvoorbeeld
chown -R jijzelf.users [a-z1-9]*
# Rechten aanpassen met find en -exec
find . -type f -name '[a-zA-Z0-9]*' -exec chmod 644 {} \;
find . -type d -name '[a-zA-Z0-9]*' -exec chmod 755 {} \;
# Eigenaarschap aanpassen met find en -exec
find . -type f -name '[a-zA-Z0-9]*' -exec chown jijzelf.users {} \;
find . -type d -name '[a-zA-Z0-9]*' -exec chown jijzelf.users {} \;
Zie het script spatiesuitpng.sh :
Zoeken met find - leeftijd
atime=accessed
ctime=created
mtime=modified
speel met ctime en mtime. bestudeer het verschil in resultaat.
# ctime=created
-ctime -20 => minder dan 20 dagen oud
-ctime 20 => exact 20 dagen oud
-ctime +20 => meer dan 20 dagen oud
# mtime=modified
-mtime -20 => minder dan 20 dagen oud
-mtime 20 => exact 20 dagen oud
-mtime +20 => meer dan 20 dagen oud
-type d : mappen
-type f : bestanden
-print : geef het zoek resultaat weer, per bestand/map in 1 regel info.
-exec : voor het hieropvolgend commmando uit op het gevonden bestand (of map).
# zoek bestanden ouder dan 15 dagen
find /mijnpad -type f -mtime +15
# zoek bestanden 15 dagen oud
find /mijnpad -type f -mtime 15
# zoek bestanden jonger dan 15 dagen
find /mijnpad -type f -mtime -15
# zoek bestanden met extensie abc (abc - als voorbeeld) ouder dan 15 dagen
find /mijnpad -type f -name *abc -mtime +15
# met -print
find /mijnpad -type f -name *abc -mtime 15 -print
# gevonden resultaat weggooien met -exec rm {} \;
# zoek bestanden met extensie abc (abc - als voorbeeld) ouder dan 15 dagen, en verwijder ze. Let op, er is geen undo !!!
# -type en -name samen gaat wel of niet ?
find /mijnpad -type f -name *abc -mtime +15 -exec rm {}\;
# probeer dan alleen -name *abc
find /mijnpad -name *abc -mtime +15 -exec rm {} \;
# zoek jpg of JPG bestanden, ouder dan 365 dagen. ctime is anders dan mtime !!!
find $HOME -type f -name '*[JjPpGg]'
find $HOME -type f -name '*[JjPpGg]' -ctime +365
find $HOME -type f -name '*[JjPpGg]' -mtime +365
# zoek png of PNG bestanden, ouder dan 365 dagen. ctime is anders dan mtime !!!
find $HOME -type f -name '*[PpNnGg]'
find $HOME -type f -name '*[PpNnGg]' -ctime +365
find $HOME -type f -name '*[PpNnGg]' -mtime +365
# zoek mappen/directories, gemaakt in de jongste 30 dagen.
find /mijnpad -type d -ctime +30
# zoek mappen/directories, ouder dan 30 dagen.
find /mijnpad -type d -ctime +30
find /mijnpad -type d -mtime +30
# alternatief op bovenstaande !??? : -exec rm -f {} +
# zoek bestanden ouder dan 15 dagen, en verwijder ze.
# Werkt dit ook ?
find /mijnpad -type f -mtime +15 -exec rm -f {} +
Zoeken met find - aantal bestanden in onderliggende mappen
https://askubuntu.com/questions/791864/count-number-of-files-in-a-folder-per-day
# Leuk find /mijnpad -type f -printf '%TY_%Tm%Td\n' | sort | uniq -c
# Zo mooi, met awk, maar helaas deze keer # Hierin gaat was mis find . -maxdepth 1 -type f -printf '%TY%Tm%Td\n' | awk '{array[$0]+=1}END{ for(val in array) print val“ “array[val] }'
# Maak een script :
#!/bin/bash # Dit is /home/ikzelf/bin/opruimscript.sh IMGSPATH="/path/to/somewhere" # count of all files within your directory count=$(find $IMGSPATH -type f | wc -l) # remove the ones older than of 7 days while [ "$count" -gt "20" ] do find $IMGSPATH -type f -mtime +7 -print -delete -quit count=$((--count)) done
Zoeken met find - leeftijd newerXY
https://serverfault.com/questions/122824/linux-using-find-to-locate-files-older-than-date
From man find: -newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select which time belonging to how reference is used for the comparison.
- a The access time of the file reference
- B The birth time of the file reference
- c The inode status change time of reference
- m The modification time of the file reference
- t reference is interpreted directly as a time
Example: find -newermt "mar 03, 2010" -ls find -newermt yesterday -ls find -newermt "mar 03, 2010 09:00" -not -newermt "mar 11, 2010" -ls
Linux Dokumenten inpakken - met Zip in Nemo
Dat kan mooi met de bestanden bladeraar Nemo, en de rechtermuisknop. Er kan ook een paswoord op. Dat heet versleutelen / encrypt.
Werkwijze met Nemo :
- zet de in te pakken documenten bij elkaar in een map. Geef die map een logische naam, die de lading dekt. Bijvoorbeeld in /home/hans/dokumentenvanhans
- open bestanden bladeraar Nemo,
- open de map dokumentenvanhans,
- selecteer alle bestanden
- rechtermuisknop - Samenpersen (Comprimeren)
- kies extensie zip
- lokatie /home/hans
- het zipbestand voorstel is al : dokumentenvanhans.zip
- Encrypt : Ja. Dit is inpakken met paswoord.
- Vul je wachtwoord in : ditisgeheim
- Overige opties zijn niet nodig (voor mij niet) …
- Klik op 'Maken'
- En er wordt voor u gemaakt : dokumentenvanhans.zip
- Die kun je per mail naar iemand sturen.
- Het paswoord geef je door per ander communicatiemiddel (niet met het zelfde mail adres !)
- Uitpakken : selecteer het zip bestand, en kies 'Pak hier uit'
Linux Dokumenten inpakken - met Zip in de terminal
In de terminal gaat het prachtig :
https://vsys.host/how-to/how-to-zip-a-file-in-linux
The zip command provides a range of work modes and options to facilitate the creation of ZIP files. Here is a brief summary of the available options:
Tag Option or Mode Description -u—update Mode Updates and adds new files. Creates a new archive if not found. -f—freshen Mode Updates files without adding new ones. Creates a new archive if not found. -d—delete Mode Chooses entries in an existing archive and removes them. -U—copy-entries Mode Chooses entries from an existing archive and copies them into a new archive. -e—encrypt Option Encrypts ZIP archive contents with a password. Starts a password entry prompt. -i <files>—include <files> Option Includes only specified files. -R—recurse-patterns Option Archives files recursively. -sf—show-files Option Lists files the command would operate on, then exits. -x <files>—exclude <files> Option Excludes specified files. -<number> Option Regulates compression speed (0-9). Lower numbers are faster. Numerous additional options are available with the zip command, which can be accessed by using the man command : man zip
Linux Terminal : Cheat Sheets
2024 0724 : Linux Zob Aktief avond :
Zoek op : linux cheat sheet
Linux Terminal : Cheat Sheets
Er zijn ook Android Apps :
- Linux Command with Examples
- Linux Cheat Sheet
- Linux Command Library
- …
Linux Terminal : Commando's Intro
Kleuren in de terminal
- ls -l –color=never
https://linuxhandbook.com/a-to-z-linux-commands/
https://www.howtogeek.com/175641/how-to-boot-and-install-linux-on-a-uefi-pc-with-secure-boot/, onderaan deze pagina staat een heel overzicht
https://phoenixnap.com/kb/linux-set
https://www.howtogeek.com/175641/how-to-boot-and-install-linux-on-a-uefi-pc-with-secure-boot/ onderaan staat een hele rij commando's met uitleg
Op https://de-help-desk.nl staan veel goede tips rondom Linux en de terminal
Zie ook :
Systeem info opvragen
inxi
inxi -Fzx
ishw
how to replace end of line by space
Deze handleiding begon in https://duckduckgo.com/aichat met : “linux gnome terminal how to replace end of line by space”
You can use the tr command in Linux to replace the end of line with a space. Here's how you can do it:
bash
tr '\n' ' ' < input.txt > output.txt
In this command:
tr is the command for translating or deleting characters. '\n' represents the newline character (end of line). ' ' represents a space. input.txt is the file you want to modify. output.txt is the file where the modified text will be written.
If you want to do this directly in the terminal without writing to a file, you can use:
ls -1 | od -c
bash
echo -e “line1\nline2\nline3” | tr '\n' ' '
This will output: line1 line2 line3
Met sed werkt het niet, lijkt het …
linux gnome terminal how to replace end of line by space with sed
linux gnome terminal how to remove end of line by space with sed
