Wikipedia:Reference desk/Archives/Computing/2019 October 4
Appearance
| Computing desk | ||
|---|---|---|
| < October 3 | << Sep | October | Nov >> | Current desk > |
| Welcome to the Wikipedia Computing Reference Desk Archives |
|---|
| The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
October 4
[edit]Generating random characters in Linux terminal including special characters
[edit]I have this command for the terminal:
dd if=/dev/urandom bs=13 count=1 status=none | od -An -x | tr -d " \n"
It is meant to generate some random characters but I want to include special characters (punctuations marks etc). How do I modify this command to include special characters? Thanks. --88.106.182.98 (talk) 19:10, 4 October 2019 (UTC)
- Why are you generating the string? If it is for a password, then look at pwgen(1). For a single eight character password try
pwgen -ynC1, or for a screenful of random text leave the "1" off. Martin of Sheffield (talk) 19:37, 4 October 2019 (UTC)
- I will use the output to generate a scheme for making passwords. I would like five rows of 26 characters including special characters (e.g. $, £, ^, %, <, &, *, ( etc). Any idea how to include those special characters? Thanks. --88.106.182.98 (talk) 19:48, 4 October 2019 (UTC)
- I have a very good idea, in fact it's the one I mentioned above! The -y means "Include at least one special character in the password", read the man page. It's then a bit of pretty basic coding to get what you're after:
- I will use the output to generate a scheme for making passwords. I would like five rows of 26 characters including special characters (e.g. $, £, ^, %, <, &, *, ( etc). Any idea how to include those special characters? Thanks. --88.106.182.98 (talk) 19:48, 4 October 2019 (UTC)
$ for i in 1 2 3 4 5; do pwgen -ync -N4 | tr -d " \n" | cut -c -26; done
wei4Id_aHe)l6kaeeiW3ooj"Ee
at4Ahm+eIez7ku]avae,J6aiSh
ahPh-ah1Ahl7jeu-sao3Ca)wle
ja7Bai}weeM/eet7fap9wu~LTa
ja"oph1Ithee\Me3ef4eM+ahto
- Please note that the parameter to tr is
" \n"and not"\n". Martin of Sheffield (talk) 20:22, 4 October 2019 (UTC)
- Please note that the parameter to tr is
- Thanks very much, Martin! −−88.106.182.98 (talk) 20:35, 4 October 2019 (UTC)
You could also try this:
alias randompass='tr -cd '\a-zA-Z0-9!@#$%^&*('\ < /dev/urandom | head -16c | xargs echo'
You're not guaranteed to get a non-alphanumeric character every time, but you can retry if you don't get one. 173.228.123.207 (talk) 18:28, 5 October 2019 (UTC)