Commands by knoppix5 (61)

  • Last listed files presumably have higher precedency then files listed first, i.e. configuration files in the personal .config directory will be listed last and their config parameters will be more authoritative then default config parameters defined in /etc directory which are usually listed above them. If you replace ".conf" with ".ini" in the command, initial files will be listed instead of config files. If you do not like to list multiple access to the same config file, pipe to "uniq" or "uniq -c" to prefix lines by the number of occurrences Show Sample Output

    strace 2>&1 <any_executable> |egrep -o "\".*\.conf\""
    knoppix5 · 2020-07-31 10:57:29 0

  • 0
    strace 2>&1 geany |grep geany.conf
    knoppix5 · 2020-04-20 19:42:39 5
  • Will delete empty directories and sub-directories (hideen too = whose names are starting with dot .). Used 'rm' command instead of 'rmdir' to give the possibility of asking for confirmation before deleting i.e. it is not wise do delete all empty directories in /etc folder. Replace dot in 'find .' with any for other starting directory instead of current. in 'rm -i -R' 'i' stands for ask before delete and 'R' for delete folder recursively or folder itself if it is empty

    find . -type d -empty -exec rm -i -R {} \;
    knoppix5 · 2020-03-29 13:12:21 4
  • I can think of using this command after compiling an downloaded source from anywhere as an easy way to find all executable products. We usually issue the find command (without arguments) to list the full paths of all directories and sub-directories and files in the entire current tree. Similar command is tree -aicfnF

    find -executable -type f
    knoppix5 · 2020-03-29 11:46:18 10
  • ( Or ls -lat|lolcat -a if you like it in technicolor - apt install lolcat if needed )

    ls -alt|awk '{if (system("sleep .5 && exit 2") != 2) exit; print}'
    knoppix5 · 2020-02-13 02:59:48 2
  • Use flag "--" to stop switch parsing Show Sample Output

    grep -- -
    knoppix5 · 2019-11-29 23:45:06 0
  • 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 4
  • 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 1
  • 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 3

  • 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 1
  • 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
  •  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

Graphical tree of sub-directories
Prints a graphical directory tree from your current directory

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Create a new file

Automaticly cd into directory
Makes bash-4.x like zsh. Automatic cd into a directory if a command with that name doesnt exists. Ready for your ~/.bashrc file

Get the full path to a file
Part of coreutils - so needs no extra package...

Annotate tail -f with timestamps

creeate file named after actual date
Create a file with actual date as filename

list block devices
Shows all block devices in a tree with descruptions of what they are.

add files to existing growable DVD using growisofs
replace "directory name with files to add to DVD" with actual directory containing files you want to add to growable DVD

Find common groups between two users
Updated according to flatcap's suggestion, thanks!

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: