4 ms·
Nice list, here are suggestions for improving a few of the commands: Generate Random Passwords >_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6 This prod
by hyper_reality 6y ago
Nice list, here are suggestions for improving a few of the commands:
Generate Random Passwords
>_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
This produces a 6-character password which only has 35 bits of entropy. It also doesn't print a newline, causing the password to be on the same line as the next prompt. Better to use something like:
>_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12 && echo
Or the "pwgen" utility which can do this for you.
Find the process that is using a certain port e.g. port 3000
>_ lsof -P | grep ':30000'
This command will be extremely slow on large systems with a lot of open files. It is essentially listing every open file (the -P flag just inhibits port mappings from e.g. "port 22" to "SSH") and then grepping the output. Much better to run:
>_ lsof -i :30000
Which is not only shorter, but much faster as it directly gets info about that port.
Add your public SSH key to a server in one command
>_ cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
This is what the "ssh-copy-id" utility, which is part of the openssh-client package, does already.
Harder, Faster, Stronger SSH clients
>_ ssh -4 -C -c blowfish-cbc
All three of those points are debatable with that command. Just use the defaults.
- deleted 6y ago[deleted]
- rovr138 6y ago>_ find . -empty -type d -exec rmdir {} + alternative >_ find . -empty -type d -delete
- chasil 6y agoPlease don't use -exec. Use -print0 and xargs -0 instead, as it's much safer, and correctly passes newlines and other problem characters. Even BSD adopted this idiom. GNU find says this very specifically: "There are unavoidable security problems surrounding the -exec action..."
- rovr138 6y agoI'm pretty sure it's a bit faster too. Or for some reason I moved to it.
- chasil 6y agoIt would be faster because the exec takes place for every single result of the find. Simple xargs builds the longest possible command line with as many find results as can fit. If the -n option were used with xargs, it might slow down to similar performance as -exec, but it would still be safer. Multiple processes can also be launched by the xargs, increasing performance by using multiple CPUs. Here is a script using xargs -0 to launch 6 compression processes at a time on files specified to a shell script: #!/bin/sh N_CPUs=6 EXT="xz" S="$(mktemp -t PARALLEL-XXXXXX)" printf '#!/bin/sh \n exec xz -9e "$1"' > "$S" chmod 500 "$S" if [[ -z "$1" ]] then echo "Specify files to pack into ${EXT} files." else for x do printf '%s\0' "$x" done | xargs -0 -P "$N_CPUs" -Ifname "$S" fname fi rm -f "$S"
- Izkata 6y ago> It would be faster because the exec takes place for every single result of the find. Only if you end the exec with \; If you end it with + then the results are built up and appended to the command much like xargs.
- pnutjam 6y agoA couple helpful tips: pwgen is a package available on most linux's. It's great for generating passwords. For finding a process on a port, use ss ss -pn| grep :22 for a listening process ss -lpn |grep :22
- rovr138 6y agoanother, Find biggest 10 files in current and subdirectories and sort by file size >_ find . -type f -print0 | xargs -0 du -h | sort -hr | head -10 alternative, >find ./ -printf '%s--%p\n'| sort -nr | head
- armSixtyFour 6y agoThe list contains a few different password generators, but I'm a little disappointed they didn't mention https://linux.die.net/man/1/apg https://linux.die.net/man/1/apg
- jbrnh 6y agoOr use 'shuf' for passwords: shuf -r -e --random-source=/dev/urandom {a..z} {0..9} {A..Z} | paste -d "" -s | fold -w 25
- cpach 6y agoFor generating passwords, I like this one: head -c 33 /dev/urandom | base64 It has 264 bits of entropy.
- skinnyasianboi 6y agoAuthor of linuxcommandlibrary.com here. You and some other commenters have a great knowledge. Can't wait to dig into it and add it to the page! Thanks a lot