Commands using command (55)

  • Pipe any command through figlet to make the output more awesome. Example: ls | figlet Show Sample Output

    command | figlet
    isaacs · 2009-05-03 21:20:46 3
  • Test scenario: * Open xterm (or konsole, ...) * Start xeyes with: ( xeyes & ) * Close the xterminal The xeyes process should be still running.

    ( command & )
    wiburg · 2011-01-07 19:06:30 10
  • In the sample output, I pressed ctrl+r and typed the letters las. I can't imagine how much typing this has saved me. Show Sample Output

    ^r in bash begins a reverse-search-history with command completion
    abcde · 2009-02-19 18:17:54 2
  • Don't do this: echo word | command Using a bash "here strings" and "here documents" look leeter than piping echo into the command. Also prevents subshell execution. Word is also expanded as usual.

    command <<< word
    adeverteuil · 2012-02-29 03:14:54 3
  • This little function will smarten 'cd'. If you try to cd into a file (which I guess we all have done), it cd's into the directory of that file instead. I had to use nesten if's, to get cd to still work with 'cd' (to get to $HOME), 'cd -' (to get to last directory), and 'cd foo\ bar'. Show Sample Output

    cd() { if [ -z "$1" ]; then command cd; else if [ -f "$1" ]; then command cd $(dirname "$1"); else command cd "$1"; fi; fi; }
    xeor · 2010-04-23 19:17:43 4

  • 9
    command > >(tee stdout.log) 2> >(tee stderr.log >&2)
    bandie91 · 2011-10-20 15:08:33 1

  • 9
    command systemctl --no-page --no-legend --plain -t service --state=running
    Xk2c · 2016-04-30 10:35:05 1
  • I don't truly enjoy many commands more than this one, which I alias to be ps1.. Cool to be able to see the heirarchy and makes it clearer what need to be killed, and whats really going on. Show Sample Output

    command ps -Hacl -F S -A f
    AskApache · 2009-08-19 07:08:19 1
  • If BREs can be used, this sed version will also get the job done.

    command | sed -n '1,/regex/p'
    putnamhill · 2009-12-22 15:04:38 0
  • Calls sudo tee like all the other lines, but also automatically reloads the file. Optionally you can add command Wq :execute ':W' | :q and command WQ :Wq to make quitting easier

    command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
    unixmonkey26167 · 2011-10-06 20:37:54 1

  • 6
    command !$
    chrisindallas · 2009-02-25 14:00:24 5
  • Same as the cool matrix style command ( ), except replacing the printed character with randomness. The command mentioned is much faster and thus more true to the matrix. However, mine can be optimized, but I wasted ... i mean spent enough time on it already Show Sample Output

    check the sample output below, the command was too long :(
    pykler · 2009-09-29 19:30:10 2
  • Run this before you run a command in order to see what the command does as it starts. The -c flag is useful here as the PID is unknown before startup. All config files, libraries, logs, ports, etc used by the command as it starts up, (and shuts down) will be captured at 1s intervals and written to a file. Useful for debugging etc. Show Sample Output

    sudo lsof -rc command >> /tmp/command.txt
    zlemini · 2011-08-03 20:19:53 0
  • The improvement is that you can re-attach to the screen at a later point.

    screen -d -m command &
    unixmonkey10455 · 2010-06-22 18:24:22 0
  • Copies whatever is piped to the pbcopy command to the clipboard. pbpaste ... well pastes whats on the clipboard.

    command | pbcopy && pbpaste
    vaporub · 2009-02-16 07:40:36 0
  • An easy function to get a process tree listing (very detailed) for all the processes of any gived user. This function is also in my Show Sample Output

    psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
    AskApache · 2009-11-13 06:10:33 1
  • it is generally advised to avoid using which(1) whenever possible. which(1) is usually a csh(1) script, or sometimes a compiled binary. It's output is highly variable from operating system to operating system, so platform independent scripts could become quite complicated with the logic. On HP-UX 10.20, for example, it prints "no bash in /path /path /path ..."; on OpenBSD 4.1, it prints "bash: Command not found."; on Debian (3.1 through 5.0 at least) and SuSE, it prints nothing at all; on Red Hat 5.2, it prints "which: no bash in (/path:/path:...)"; on Red Hat 6.2, it writes the same message, but on standard error instead of standard output; and on Gentoo, it writes something on stderr. And given all these differences, it's still variable based on your shell. This is why POSIX is king. See for more ways on avoiding which(1). Show Sample Output

    command -v bash
    atoponce · 2011-09-26 10:17:41 4
  • Useful to add a timestamp to every line printed to stdout. You can use `-Ins` instead of `-Iseconds` if you want more precision. Show Sample Output

    any command | while read line; do echo "[`date -Iseconds`] $line"; done
    ayosec · 2014-02-07 22:27:29 0
  • Check out the usage of 'trap', you may not have seen this one much. This command provides a way to schedule commands at certain times by running them after sleep finishes sleeping. In the example 'sleep 2h' sleeps for 2 hours. What is cool about this command is that it uses the 'trap' builtin bash command to remove the SIGHUP trap that normally exits all processes started by the shell upon logout. The 'trap 1' command then restores the normal SIGHUP behaviour. It also uses the 'nice -n 19' command which causes the sleep process to be run with minimal CPU. Further, it runs all the commands within the 2nd parentheses in the background. This is sweet cuz you can fire off as many of these as you want. Very helpful for shell scripts.

    ( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & )
    AskApache · 2009-10-10 04:43:44 1
  • I've wanted this for a long time, finally just sat down and came up with it. This shows you the sorted output of ps in a pretty format perfect for cron or startup scripts. You can sort by changing the k -vsz to k -pmem for example to sort by memory instead. If you want a function, here's one from my aa_top_ps(){ local T N=${1:-10};T=${2:-vsz}; ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -${T} -A|sed -u "/^ *PID/d;${N}q"; } Show Sample Output

    command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'
    AskApache · 2010-05-18 18:41:38 1
  • Useful when you have only one terminal session e.g. ssh. and want to queue up another command after the currently running has finished(in case if you forget to run that command). Originally used as ; python-updater when running emerge. When I have noticed that a package failed due to that command not run.

    a command is running... <^z> fg; scheduled_command
    denysonique · 2010-07-28 19:25:19 0
  • 5 helpful aliases for using the which utility, specifically for the GNU which (2.16 tested) that is included in coreutils. Which is run first for a command. Same as type builtin minus verbosity alias which='{ command alias; command declare -f; } | command which --read-functions --read-alias' Which (a)lias alias whicha='command alias | command which --read-alias' Which (f)unction alias whichf='command declare -f | command which --read-functions' Which e(x)ecutable file in PATH alias whichx='command which' Which (all) alias, function, builtin, and files in PATH alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a' # From my .bash_profile Show Sample Output

    alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a'
    AskApache · 2010-11-18 03:32:04 5
  • Uses the shell builtin `declare` with the '-f' flag to output only functions to grep out only the function names. You can use it as an alias or function like so: alias shfunctions="builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'" shfunctions () { builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'; } Show Sample Output

    builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'
    sciro · 2018-07-23 05:24:04 0
  • An apt-get wrapper function which will run the command via sudo, but will run it normally if you're only downloading source files. This was a bit of an excuse to show off the framework of cmd && echo true || echo false ...but as you can see, you must be careful about what is in the "true" block to make sure it executes without error, otherwise the "false" block will be executed. To allow the apt-get return code to pass through, you need to use a more normal if/else block: apt-get () { if [ "$1" = source ]; then command apt-get "$@"; else sudo apt-get "$@"; fi }

    apt-get () { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" }
    mulad · 2009-02-19 04:17:24 1
  • Slightly simpler version of previous sed command that does the same thing. In this case, the output will stop at the command, and the entire command will be terminated as well, instead of proceeding through the whole file.

    command | sed '/regex/q'
    taliver · 2009-12-29 14:52:41 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

Open a file at the specified line
You may also use +line:column syntax.

Run bash on top of a vi session (saved or not saved), run multiple commands, instead of one at a time with :!(bashcommand), type exit and [enter] to get back to where you left off in vi.
Helps when I'm editing a script and want to double check some commands without having to exit out of vi multiple times or having to use another terminal session.

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" }

Number of CPU's in a system
/proc/cpuinfo contains information about the CPU. Search for "processor" in the /proc/cpuinfo file wc -l, counts the number of lines.

Clean up after a poorly-formed tar file
These days, most software distributed in tar files will just contain a directory at the top level, but some tar files don't have this and can leave you with a mess of files in the current folder if you blindly execute $ tar zxvf something.tar.gz This command can help you clean up after such a mistake. However, note that this has the potential to do bad things if someone has been *really* nasty with filenames.

Check if your desired password is already available in haveibeenpwnd database. This command uses the API provided by HIBP

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

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"

LVM2 Reduce
Just the commands for the lvreduce I keep forgetting.

convert a mp4 video file to mp3 audio file (multiple files)

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: