Commands by knoppix5 (55)

  • Copy this function to command line, press 'Enter' 'f'' 'Enter' to execute (sentence on the left written only for newbies). Hint 'e|x|v|1..9' in front of displayed last modified file name means: "Press 'e' for edit,'x' for execute,'v' for view or a digit-key '1..9' to touch one file from the recent files list to be last modified" and suggested (hidden files are listed too, else remove 'a' from 'ls -tarp' statement if not intended). If you find this function useful you can then rename it if needed and append or include into your ~/.bashrc config script. With the command . ~/.bashrc the function then can be made immediately available. In the body of the function modifications can be made, i.e. replaced joe editor command or added new option into case statement, for example 'o) exo-open $h;;' command for opening file with default application - or something else (here could not be added since the function would exceed 255 chars). To cancel execution of function started is no need to press Ctrl-C - if the mind changed and want to leave simple Enter-press is enough. Once defined, this function can with typeset -f f command be displayed in easy readable form Show Sample Output

    f() { ls -lart;e="ls -tarp|grep -v /|tail -9";j=${e/9/1};g=${e/9/9|nl -nln};h=$(eval $j);eval $g;read -p "e|x|v|1..9 $(eval $j)?" -n 1 -r;case $REPLY in e) joe $h;;v)cat $h;;x) eval $h;;[1-9]) s=$(eval $g|egrep ^$REPLY) && touch "${s:7}" && f;;esac ; }
    knoppix5 · 2019-09-26 11:58:37 0
  • include in the list human readable hidden files too: file .* *|grep 'ASCII text'|sort -rk2 more reliable command: ls|xargs file|grep 'ASCII text'|sort -rk2 and include hidden files: ls -a|xargs file|grep 'ASCII text'|sort -rk2

    file *|grep 'ASCII text'|sort -rk2
    knoppix5 · 2019-08-23 00:47:07 0
  • Number of days back: change/append arbitrary amount of '\|'$[$(date +%Y%j)-x] expressions or specify any n-th day before today for a single day (you have to replace x with 3, 4, 5, whatever ... above I replaced it with 1 and 2 to get listing for yesterday and day before yesterday and 0 for today was not necessary, so left out). Q: How to narrow to *.pdf , *.png, *.jpg, *.txt, *.doc, *.sh or any type of files only? A: Pipe to grep at the end of command. Even shorter: cd && day=3;for a in $(seq $day -1 0);do tree -aicfnF --timefmt %Y%j-%d-%b-%y|grep $[$(date +%Y%j)-$a];done Here it's only needed to change amount of variable day to list period of days back - here is set to three days back (the seq command is adjusted for listing the oldest stuff first). Show Sample Output

    cd && tree -aicfnF --timefmt %Y%j-%d-%b-%y|grep $(date +%Y%j)'\|'$[$(date +%Y%j)-1]'\|'$[$(date +%Y%j)-2]
    knoppix5 · 2019-08-04 02:22:24 0

  • 0
    for a in $(seq 16); do xdotool key Num_Lock;sleep .5; xdotool key Caps_Lock;done
    knoppix5 · 2019-07-11 23:47:20 0
  • Credits go to Flatcap

    echo abcd89efghij340.20kl|grep --color -e "[0-9]\+" -e "$"
    knoppix5 · 2019-06-30 15:06:28 2
  • Even shorter: seq -s '*' 120|tr -d '[0-9]'

    seq -s '*' 40|tr -c '*' '*' && echo
    knoppix5 · 2019-06-30 13:40:53 2

  • 1
    echo $[321*4]
    knoppix5 · 2019-06-30 12:43:55 0

  • 3
    while true; do echo -e "\e[?5h\e[38;5;1m A L E R T $(date)"; sleep 0.1; printf \\e[?5l; read -s -n1 -t1 && printf \\e[?5l && break; done
    knoppix5 · 2019-06-18 15:27:36 0
  • You can append these commands to the bottom of the history file to access them easier with the Up key: sort ~/.bash_history|uniq -c|sort -n|tail -n 10|tr -s " "|cut -d' ' -f3- >> ~/.bash_history

    sort ~/.bash_history|uniq -c|sort -n|tail -n 10
    knoppix5 · 2019-04-15 14:20:00 0
  • Only the first appearance of a repeated command in the history will be kept. Otherwise, if you prefer to keep last occurrence of a repeated command then maybe you can achieve that by including reverse input/output i.e with 'tac' command in expression above. To see statistics of removed repeated commands: diff --suppress-common-lines -y ~/.bash_history.bak ~/.bash_history|uniq -c|sort -n|tr -s " "|sed '/^ 1/d'|grep '<'

    cp -a ~/.bash_history ~/.bash_history.bak && perl -ne 'print unless $seen{$_}++' ~/.bash_history.bak >~/.bash_history
    knoppix5 · 2019-04-15 12:39:09 0
  • tput setaf 1 && tput rev && seq -ws "___|" 81|fold -69|tr "0-9" "_" && tput sgr0 # (brick wall)

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

  • 2
    seq -s " \\_/" 256|tr -d "0-9"|fold -70
    knoppix5 · 2018-11-12 23:25:25 0
  • (example above is the 'ls' command with reduced output speed)

    ls -lart|lolcat -a
    knoppix5 · 2016-11-18 02:45:39 3
  • Display recursive file list (newest file displayed at the end) and be free to access last file in the list simply by pressing arrow_up_key i.e. open it with joe editor. BTW IMHO the list of files with newest files at the end is often more informative. Put this 'lsa' function somewhere in your .bashrc and issue . ~/.bashrc or source ~/.bashrc to have access to the 'lsa' command immediately. . (the function appends command "joe last_file_in_the_list" at the end of command history)

    lsa() { ls -lart; history -s "joe \"$(\ls -apt|grep -v /|head -1)\"" ; }
    knoppix5 · 2016-07-07 21:27:55 2
  • Should work even when very large files exist.

    tree -isafF /var|grep -v "/$"|tr '[]' ' '|sort -k1nr|head
    knoppix5 · 2016-05-27 16:41:20 6
  • Hold 'Ctrl' + 'Alt' key while selecting rectangular text area of the screen with left mouse button. Should work in any terminal screen (xterm, konsole, ...) under X, if not then try with 'Ctrl' + 'Shift' + 'Alt' or two-combination of these.

    Ctrl + Alt
    knoppix5 · 2015-11-10 22:08:57 3
  • This command will display the file, but you can change 'cat' to anything else (type 'n' when prompted to cancel the command or anything else to proceed). . Some hints for newbies: type unset bar to make 'bar' function annihilated. For permanent usage you can put this (bar) function in your .bashrc (for bash) or in .profile (for sh). With: . ~/.bashrc you can get all new inserted functions in .bashrc (so the function 'bar' or whatever name you choose) immediately available. Show Sample Output

    bar() { foo=$(ls -rt|tail -1) && read -ep "cat $foo? <y/n> " a && [[ $a != "n" ]] && eval "cat $foo" ;}
    knoppix5 · 2015-10-21 20:09:33 2
  • (here is character '+' repeated 80 times) Sometimes needed to enhance the title of the script. Show Sample Output

    echo -e ''$_{1..80}'\b+'
    knoppix5 · 2015-05-05 22:13:33 9

  • 3
    clear; while sleep 1; do d=$(date +"%H:%M:%S"); e=$(echo "toilet -t -f mono12 $d");tput setaf 1 cup 0; eval $e; tput setaf 4 cup 8; eval "$e -F flop";tput cup 0; done
    knoppix5 · 2015-05-03 01:51:27 0
  • Thanks to pooderbill for the idea :-) Show Sample Output

    for a in $(ls /usr/sbin /usr/bin); do ps -fC $a;done|grep -v PPID
    knoppix5 · 2015-04-27 18:15:56 1
  • Usage example: display output of a command running in the background at desired time The example in details: report disk quotas and that backup process will start soon In my /etc/crontab file I added following four lines for weekly automatic incremental backup: . 52 13 * * 7 root mount /dev/sda3 /media/da2dc69c-92cc-4249-b2c3-9b00847e7106 . 53 13 * * 7 knoppix5 df -h >~/df.txt . 54 13 * * 7 knoppix5 env DISPLAY=:0 /usr/bin/gedit ~/df.txt && wmctl -a gedit . 55 13 * * 7 root /home/knoppix5/ . line one: as root mount media for backup on Sunday 13:52 line two: as user knoppix5 write out to text file in home directory the free space of all mounted disks on Sunday 13:53 line three: in front of you open and display a very simple text editor (I prefer gedit) with content of previously reported disk usage at Sunday 13:54 wmctl -a gedit means (from the manual): -a Switch to the desktop containing the window , raise the window, and give it focus. line four: as root run incremental backup script as root on Sunday 13:54 . my, with root permissions backups in short time (writes only changes from the last backup) the etire linux system (except excluded - i.e. you don't want backup recursively your backup disk), looks like this (Show sample output): Show Sample Output

    env DISPLAY=:0 /usr/bin/gedit ~/df.txt && wmctl -a gedit
    knoppix5 · 2015-04-12 13:48:31 4

  • 1
    a=$(b=$(($LINES/2));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr '\t' ' ');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '
    knoppix5 · 2015-04-08 02:33:05 7
  • dir1 and all its subdirs and subdirs of subdirs ... but *no files* will be copied to dir2 (not even symbolic links of files will be made). To preserve ownerships & permissions: cp -Rps dir1 dir2 Yes, you can do it with rsync -a --include '*/' --exclude '*' /path/to/source /path/to/dest too, but I didn't test if this can handle attributes correctly (experiment rsync command yourself with --dry-run switch to avoid harming your file system) You must be in the parent directory of dir1 while executing this command (place dir2 where you will), else soft links of files in dir2 will be made. I couldn't find how to avoid this "limitation" (yet). Playing with recursive unlink command loop maybe? PS. Bash will complain, but the job will be done. Show Sample Output

    cp -Rs dir1 dir2
    knoppix5 · 2015-04-01 22:51:16 1
  • hypnotizing pendulum

    clear;while true;sleep 1;do for((a=1;a<=$(tput cols)/3;a++));do tput cup 0 $a;echo " " $(date);done;sleep 1;for((a;a>=1;a--));do tput cup 0 $a;echo $(date) " ";done;done
    knoppix5 · 2015-01-05 18:56:49 3

  • 6
    sed 's/[0-9]\+/ [&] /g'
    knoppix5 · 2014-09-18 18:25:55 3
  •  1 2 3 > 

What's this? 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

Random quote from Borat -- no html parsing
Turns out has a text file containing every single one of the borat quotes, each one on a newline. This makes it very convenient, as this can be done without any sed-parsing, and uses less bandwitdth! Note that borate quotes are quite offensive, much more so than "fortunes-off"!

list files recursively by size

Update your journal
prerequisite: $ mkdir ~/journal

Stream YouTube URL directly to mplayer.

List and delete files older than one year

Check if the files in current directory has the RPATH variable defined
Using gentoo prefix portage I got in a situation where some packages did not contain the needed RPATH variable. This command helped me to find out which ones I should recompile

Create and access directory at the same time
Create and access directory (edited)

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

exec chmod to subfiles
Using `-exec cmd {} +` causes find to build the command using all matching filenames before execution, rather than once per file.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

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.


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: