Notes - Command Line Tips
Overview
Tips
Random String (password) Generation
tr -dc '[:alnum:][:punct:]' < /dev/urandom | head -c 20; echo
$ chatgpt_ask.sh can i get random string using alphabets, numbers, and symbols in command li ne? I guess using tr, /dev/urandom, head would work. YOUR MSG: can i get random string using alphabets, numbers, and symbols in command line? I guess using tr, /dev/urandom, head would work. REPLY: Yes, you can generate a random string with alphabets, numbers, and symbols using command line utilities like `tr`, `/dev/urandom`, and `head`. Here's the command: ``` tr -dc '[:alnum:][:punct:]' < /dev/urandom | head -c 12 ``` This command generates a random string with a length of 12 characters by using the `tr` utility to filter out unwanted characters and the `/dev/urandom` device file as a source of random data. The `head -c 12` command then selects the first 12 characters. The `[:alnum:]` character class represents alphabetic characters and numbers, and `[:punct:]` represents punctuation symbols. By combining them using `[:alnum:][:punct:]`, we ensure that the generated string contains a mix of alphabets, numbers, and symbols. You can modify the number `12` to change the length of the generated string according to your requirements. Note that the randomness of `/dev/urandom` may depend on your operating system and configuration.