Commands using echo (1,383)

  • If we've many files containing (?, ?, ?, ?, ? ) characters instead of ?, ?,... etc,... we can ue this simple command line running a sed command inside a for loop searching for files containing that characters. Hope u like it! Enjoy! ;) Show Sample Output


    0
    for i in `grep -ri "?\|?\|?\|?\|?" * --col | cut -d: -f1 |sort -u `;do sed -i "s/?/\á/g" $i; sed -i "s/?/\é/g" $i; sed -i "s/?/\í/g" $i; sed -i "s/?/\ó/g" $i; sed -i "s/?/\ú/g" $i; echo "HTMLizing file [$i]";done
    linuxninja · 2014-04-24 11:43:36 0
  • In this example I am returning all the files in /usr/bin that weren't put there by pacman, so that they can be moved to /usr/local/bin where they (most likely) belong. Show Sample Output


    0
    for file in /usr/bin/*; do pacman -Qo "$file" &> /dev/null || echo "$file"; done
    malathion · 2014-04-22 21:57:08 0
  • For a given filesystem return the LUN ID. Command assumes 1:1 relationship between fs:lv:hdisk:lun which may not be the case in all environments. Show Sample Output


    0
    getlunid() { lv=$(df -P $1|grep "^/dev/"|awk '{print $1}'|awk -F/ '{print $3}'); hd=$(lslv -l $lv|tail -1|awk '{print $1}');id=$(odmget -q "name like $hd AND attribute=unique_id" CuAt|grep "value ="|awk -F= '{print $2}'|tr -d '"');echo $id;}
    bigstupid · 2014-04-20 18:43:21 0

  • 2
    : $(cal [$month $year]) ; echo $_
    kseistrup · 2014-04-20 09:05:09 0

  • 1
    echo -n test@example.com | md5sum | (read hash dash ; echo "https://secure.gravatar.com/avatar/${hash}")
    kseistrup · 2014-04-20 08:56:59 0
  • Lost your luks passphrase? You can always bruteforce from the command line. See the sample output, a simple command using a dictionary. Show Sample Output


    0
    cat dictionary.txt|while read a; do echo $a|cryptsetup luksOpen /dev/sda5 sda5 $a && echo KEY FOUND: $a; done
    rodolfoap · 2014-04-16 18:49:53 1
  • Lost your luks passphrase? You can always bruteforce from the command line. See the sample output, a simple command for the "pass" word, using combinations of upper/lowercase or number replacement. The generated combinations are: for a in {p,P}{a,A,4}{s,S,5}{s,S,5}; do echo $a; done pass pasS pas5 paSs paSS paS5 ... Show Sample Output


    1
    for a in {p,P}{a,A,4}{s,S,5}{s,S,5}; do echo $a|cryptsetup luksOpen /dev/sda5 $a && echo KEY FOUND: $a; done
    rodolfoap · 2014-04-16 18:41:50 0
  • Find all private keys and dump their fingerprints. Show Sample Output


    0
    for id in `ls -1 ~/.ssh | grep -v "authorized\|known_hosts\|config\|\."` ; do echo -n "$id: " ; ssh-keygen -l -f .ssh/$id ; done
    drockney · 2014-04-16 14:12:20 4

  • 0
    for file in $(find . -name *.mp4); do ogv=${file%%.mp4}.ogv; if test "$file" -nt "$ogv"; then echo $file' is newer then '$ogv; ffmpeg2theora $file; fi done
    fatlinesofcode · 2014-04-14 23:26:19 0
  • Convert a camelCase string into snake_case. To complement senorpedro's command. Show Sample Output


    1
    echo thisIsATest | sed -r 's/([A-Z])/_\L\1/g'
    flatcap · 2014-04-11 13:36:08 0
  • You have an external USB drive or key. Apply this command (using the file path of anything on your device) and it will simulate the unplug of this device. If you just want the port, just type : echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") Show Sample Output


    30
    echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") | sudo tee /sys/bus/usb/drivers/usb/unbind
    tweet78 · 2014-04-06 12:06:29 9
  • Prints out an ascii chart using builtin bash! Then formats using cat -t and column. The best part is: echo -e "${p: -3} \\0$(( $i/64*100 + $i%64/8*10 + $i%8 ))"; From: http://www.askapache.com/linux/ascii-codes-and-reference.html Show Sample Output


    6
    for i in {1..256};do p=" $i";echo -e "${p: -3} \\0$(($i/64*100+$i%64/8*10+$i%8))";done|cat -t|column -c120
    AskApache · 2014-04-04 16:54:53 2

  • 2
    echo "this_is_a_test" | sed -r 's/_([a-z])/\U\1/g'
    senorpedro · 2014-04-03 14:21:37 1

  • 0
    echo 1395767373016 | gawk '{print strftime("%c", ( $0 + 500 ) / 1000 )}'
    3rl4ng · 2014-03-26 06:59:28 0
  • I tried a few curses based mp3 players for playing back choir practice songs for my wife. Unfortunately none of the ones I tried were capable of scrubbing a track. Firefox saves the day.


    2
    find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
    hendry · 2014-03-24 15:01:49 0
  • Filter out lines of input that contain 72, or fewer, characters. This uses bash only. ${#i} is the number of characters in variable i. Show Sample Output


    1
    while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
    flatcap · 2014-03-20 12:27:06 0
  • this version only uses shell builtins


    1
    alias ...='while read line; do echo -n "."; done && echo ""'
    fpunktk · 2014-03-17 17:34:19 0
  • Typing a word in terminal is easier than digging your phone out, opening your two-factor authentication app and typing the code in manually. This alias copies the one-time code to your clipboard for 3 seconds (long enough to paste it into a web form), then restores whatever was on the clipboard beforehand. This command works on Mac. Replace pbpaste/pbcopy with your distribution's versions.


    0
    alias oath='temp=$(pbpaste) && oathtool --base32 --totp "YOUR SEED HERE" | pbcopy && sleep 3 && echo -n $temp | pbcopy'
    unixmonkey44825 · 2014-03-14 19:21:18 0
  • - recompresses all gz files to bz2 files from this point and below in the directory tree - output shows the size of the original file, and the size of the new file. Useful. - conceptually easier to understand than playing tricks with awk and sed. - don't like output? Use the following line: for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz ; done Show Sample Output


    0
    for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && echo -n `ls -s $gz` "... " && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz && echo `ls -s $d/$f.bz2`; done
    pdwalker · 2014-03-13 08:36:24 0

  • 1
    inotifywait -mr -e CREATE $HOME/bin/ | while read i; do chmod +x $(echo "$i" | sed 's/ \S* //'); done
    Sepero · 2014-03-08 19:21:53 1
  • It find out the mic recording level at the moment of run the command and if a noise level is higher it starts to record an mp3 file. The resulting file will have only the sounds not the silences.


    2
    arecord -q -f cd -d 1 recvol.wav;sox recvol.wav -n stat 2>&1|grep RMS|grep amplitude|cut -d"." -f2|cut -c 1-2>recvol;echo $((`cat recvol`+1))>recvol;rec -t wav - silence 1 0.1 `cat recvol` -1 1.0 `cat recvol`%|lame -s 44.1 -a -v - >record.mp3
    geaplanet · 2014-02-27 23:23:55 0
  • Very quick! Based only on the content sizes and the character counts of filenames. If both numbers are equal then two (or more) directories seem to be most likely identical. if in doubt apply: diff -rq path_to_dir1 path_to_dir2 AWK function taken from here: http://stackoverflow.com/questions/2912224/find-duplicates-lines-based-on-some-delimited-fileds-on-line Show Sample Output


    1
    find . -type d| while read i; do echo $(ls -1 "$i"|wc -m) $(du -s "$i"); done|sort -s -n -k1,1 -k2,2 |awk -F'[ \t]+' '{ idx=$1$2; if (array[idx] == 1) {print} else if (array[idx]) {print array[idx]; print; array[idx]=1} else {array[idx]=$0}}'
    knoppix5 · 2014-02-25 22:50:09 6
  • You need to be root to do this. So check the command before running it. You enter the same password for Enter LUKS passphrase: Verify passphrase: Enter passphrase for /dev/loopn: ___ You can then copy the .img file to somewhere else. Loop it it with losetup -f IMAGENAME.img and then mount it with a file manager (eg nemo) or run mount /dev/loopn /media/mountfolder Acts similar to a mounted flash drive Show Sample Output


    2
    edrv() { N=${1:-edrv}; truncate -s ${2:-256m} $N.img && L=$(losetup -f) && losetup $L $N.img && cryptsetup luksFormat --batch-mode $L && cryptsetup luksOpen $L $N && mkfs.vfat /dev/mapper/$N -n $N; cryptsetup luksClose $N; echo losetup -d $L to unmount; }
    snipertyler · 2014-02-24 01:38:21 3
  • You need to apt-get install python-sqlparse. This command simply formats a sql query and prints it out. It is very useful when you want to move a sql query from commandline to a shell script. Everything is done locally, so you don't need to worry about copying sql query to external websites. Show Sample Output


    1
    echo "select a, b, c from table where a = 3;"| python -c "import sys;import sqlparse;print sqlparse.format(sys.stdin.read(), reindent=True, keyword_case='upper')"
    hide1713 · 2014-02-21 23:17:15 0
  • hexdump could be used for conversion too!


    0
    echo -n text | hexdump -C
    Tomofumi · 2014-02-21 09:15:15 0
  • ‹ First  < 6 7 8 9 10 >  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



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: