Commands using tr (349)

  • Even shorter. Stolen from comment posted by eightmillion.


    7
    tr "\n" " " < file
    randy909 · 2010-12-08 16:13:54 4
  • Little faster alternative.


    7
    head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt && wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt -O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt
    marssi · 2010-12-26 11:04:42 4
  • This command will give you a list of available keyboard shortcuts according to stty. Show Sample Output


    7
    echo -e "Terminal shortcut keys\n" && sed -e 's/\^/Ctrl+/g;s/M-/Shift+/g' <(stty -a 2>&1| sed -e 's/;/\n/g' | grep "\^" | tr -d ' ')
    cicatriz · 2011-02-10 17:38:05 5

  • 7
    tr -dc a-z0-9 </dev/urandom | tr 0-8 \ | tr 9 \\n | sed 's/^[ \t]*//' | fmt -u
    rubenmoran · 2011-02-19 10:29:17 12

  • 7
    tr -dc A-Za-z0-9_ < /dev/urandom | head -c 10 | xargs
    nottings · 2012-10-17 14:04:14 9
  • Transforms a file to all uppercase.


    6
    tr '[:lower:]' '[:upper:]' <"$1"
    opexxx · 2009-10-08 11:34:07 3
  • Print a row of characters across the terminal. Uses tput to establish the current terminal width, and generates a line of characters just long enough to cross it. In the example '#' is used. It's possible to use a repeating sequence by dividing the columns by the number of characters in the sequence like this: seq -s'~-' 0 $(( $(tput cols) /2 )) | tr -d '[:digit:]' or seq -s'-~?' 0 $(( $(tput cols) /3 )) | tr -d '[:digit:]' You will lose chararacters at the end if the length isn't cleanly divisible. Show Sample Output


    6
    seq -s'#' 0 $(tput cols) | tr -d '[:digit:]'
    jgc · 2010-04-01 09:06:44 5
  • Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.


    6
    </dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""
    TexasDex · 2010-06-17 19:30:36 3

  • 6
    tr A-Z a-z | tr -cs a-z '\n' | sort | uniq -c
    putnamhill · 2010-10-19 22:49:13 7
  • This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it. USAGE: SEE SAMPLE OUTPUT The file is composed of three parts: a) The legible script (about 242 bytes) b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242) c) The actual filesystem Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option. PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :) It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file. The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables. Show Sample Output


    6
    dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
    rodolfoap · 2013-01-31 01:38:30 13

  • 6
    tr -s ' ' | cut -d' ' -f2-
    sesom42 · 2015-05-08 12:47:09 9
  • tput setaf 1 && tput rev && seq -ws "___|" 81|fold -69|tr "0-9" "_" && tput sgr0 # (brick wall)


    6
    seq -ws "\\__/" 99|fold -69|tr "0-9" " "
    knoppix5 · 2018-11-13 06:39:37 262

  • 6
    head -4 /etc/passwd | tr : , | sed -e 's/^/| /' -e 's/,/,| /g' -e 's/$/,|/' | column -t -s,
    wuseman1 · 2022-04-22 03:03:15 963
  • Calculates the size on disk for each package installed on the filesystem (or removed but not purged). This is missing the | sort -rn which would put the biggest packges on top. That was purposely left out as the command is slightly on the slow side Also you may need to run this as root as some files can only be checked by du if you can read them ;) Show Sample Output


    5
    dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done
    pykler · 2009-10-12 14:57:54 5
  • Uses the dumb terminal option in gnuplot to plot a graph of frequencies. In this case, we are looking at a frequency analysis of words in all of the .c files. Show Sample Output


    5
    cat *.c | { printf "se te du\nplot '-' t '' w dots\n"; tr '[[:upper:]]' '[[:lower:]]' | tr -s [[:punct:][:space:]] '\n' | sort | uniq -c | sort -nr | head -n 100 | awk '{print $1}END{print "e"}'; } | gnuplot
    taliver · 2009-11-20 14:53:26 7
  • A bit different from some of the other submissions. Has bold and uses all c printable characters. Change the bs=value to speed up and increase the sizes of the bold and non-bold strings.


    5
    echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done
    psykotron · 2009-12-19 19:05:04 4
  • Get there by going backwards and forgetting the numbers.


    5
    seq -s" " -50 -1 | tr -dc -
    DoNotRememberMe · 2010-03-25 06:00:24 32
  • This command will format your alias or function to a single line, trimming duplicate white space and newlines and inserting delimiter semi-colons, so it continues to work on a single line. Show Sample Output


    5
    goclf() { type "$1" | sed '1d' | tr -d "\n" | tr -s '[:space:]'; echo }
    meathive · 2010-06-26 21:44:17 17
  • Tired copy paste to get opcode from objdump huh ? Get more @ http://gunslingerc0de.wordpress.com Show Sample Output


    5
    objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'
    gunslinger_ · 2010-07-11 15:44:48 110
  • Gets a BOFH excuse from the BOFH excuse server (towel.blinkenlights.nl port 666), and passes it through sed and tr to get rid of telnet connection stuff. Show Sample Output


    5
    telnet towel.blinkenlights.nl 666 | sed "s/=== The BOFH Excuse Server ===//" | tr -d '\n' && echo
    hintss · 2011-03-31 05:50:57 3

  • 5
    paste <(seq 7 | shuf | tr 1-7 A-G) <(seq 7 | shuf) | while read i j; do play -qn synth 1 pluck $i synth 1 pluck mix $2; done
    kev · 2012-04-09 15:22:19 3
  • Opposite: Convert an one-liner to script: foo() { <one-liner> ; } ... typeset -f foo ... unset -f foo


    5
    (sed 's/#.*//g'|sed '/^ *$/d'|tr '\n' ';'|xargs echo) < script.sh
    knoppix5 · 2013-10-26 23:23:51 16

  • 5
    function hibp() { sha1=$(echo -n "$1"|sha1sum|awk '{print toupper($0)}'|tr -d '\n'); curl -s -H $'Referer: https://haveibeenpwned.com/' https://api.pwnedpasswords.com/range/$(echo -n $sha1|cut -c1-5)|grep -i $(echo -n $sha1|cut -c6-40); }
    zmonkey · 2018-08-14 07:41:55 277
  • Fill the entire terminal screen. Is COLUMNS or LINES are undefined run "resize"


    5
    yes "\\__/ " | tr "\n" " " | fold -$((($COLUMNS-3)/6*6+3)) | head -$LINES
    tomhol · 2018-11-23 08:21:55 373
  • Reads psuedorandom bytes from /dev/urandom, filtering out non-printable ones. Other character classes can be used, such as [:alpha:], [:digit:] and [:alnum:]. To get a string of 10 lowercase letters: tr -dc '[:lower:]' < /dev/urandom | head -c 10


    4
    tr -dc '[:print:]' < /dev/urandom
    gracenotes · 2009-02-05 21:51:14 16
  •  < 1 2 3 4 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Visit wikileaks.com
Who needs a DNS server

resume other user's screen session via su, without pty error
Normally, if you su to another user from root and try to resume that other user's screen session, you will get an error like "Cannot open your terminal '/dev/pts/0' - please check." This is because the other user doesn't have permission for root's pty. You can get around this by running a "script" session as the new user, before trying to resume the screen session. Note you will have to execute each of the three commands separately, not all on the same line as shown here. Credit: I found this at http://www.hjackson.org/blog/archives/2008/11/29/cannot-open-your-terminal-dev-pts-please-check.

Place the NUM-th argument of the most recent command on the shell
After executing a command with multiple arguments like cp ./temp/test.sh ~/prog/ifdown.sh you can paste any argument of the previous command to the console, like ls -l ALT+1+. is equivalent to ls -l ./temp/test.sh ALT+0+. stands for command itself ('ls' in this case) Simple ALT+. cycles through last arguments of previous commands.

Get your external IP address without curl
Curl is not installed by default on many common distros anymore. wget always is :) $ wget -qO- ifconfig.me/ip

power off system in X hours form the current time, here X=2

awk date convert
Convert readable date/time with `date` command

Alias TAIL for automatic smart output
Run the alias command, then issue $ps aux | tail and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand. $ ${LINES:-`tput lines 2>/dev/null||echo -n 12`} Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the default of 80. The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, ie the prompt. Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( http://www.askapache.com/linux/bash-power-prompt.html ) 275MB/748MB [7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~ $ In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device.

generate a unique and secure password for every website that you login to
usage: sitepass MaStErPaSsWoRd example.com description: An admittedly excessive amount of hashing, but this will give you a pretty secure password, It also eliminates repeated characters and deletes itself from your command history. tr '!-~' 'P-~!-O' # this bit is rot47, kinda like rot13 but more nerdy rev # this avoids the first few bytes of gzip payload, and the magic bytes.

Route outbound SMTP connections through a addtional IP address rather than your primary


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: