useful_commands
Table of Contents
Useful Commands
How to Exclude in Grep
To specify two or more search patterns, use the -e option:
grep -wv -e nologin -e bash /etc/passwd
Delete large directory fast (rm is too slow)
mkdir empty_dir rsync -a --delete empty_dir/ yourdirectory/
Start a webserver in current directory:
Use RangeHTTPServer Python module:
“python -m RangeHTTPServer” or “python3 -m http.server”
or use caddy:
caddy file-server –listen 0.0.0.0:8000
Get first field of a commands output:
awk -F ' ' '{print $1}'
Replace newlines with whitespaces in a file
Using sed
sed ':a;N;$!ba;s/\n/ /g' input_filename
Source: https://stackoverflow.com/questions/1251999/how-can-i-replace-each-newline-n-with-a-space-using-sed
Using tr
A better option here is to use the tr command as follows:
tr '\n' ' ' < input_filename
or remove the newline characters entirely:
tr -d '\n' < input.txt > output.txt
or if you have the GNU version (with its long options)
tr --delete '\n' < input.txt > output.txt
Export and import private and public GPG keys
Export
gpg -a --export > mypubkeys.asc gpg -a --export-secret-keys > myprivatekeys.asc gpg --export-ownertrust > otrust.txt
Import
gpg --import myprivatekeys.asc gpg --import mypubkeys.asc gpg -K gpg -k gpg --import-ownertrust otrust.txt
useful_commands.txt · Last modified: 2024-03-20 by hanez