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
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 http://mywiki.wooledge.org/BashFAQ/081 for more ways on avoiding which(1). Show Sample Output
While going through the source code for the well known ps command, I read about some interesting things.. Namely, that there are a bunch of different fields that ps can try and enumerate for you. These are fields I was not able to find in the man pages, documentation, only in the source. Here is a longer function that goes through each of the formats recognized by the ps on your machine, executes it, and then prompts you whether you would like to add it or not. Adding it simply adds it to an array that is then printed when you ctrl-c or at the end of the function run. This lets you save your favorite ones and then see the command to put in your .bash_profile like mine at : http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Note that I had to do the exec method below in order to pause with read. t () { local r l a P f=/tmp/ps c='command ps wwo pid:6,user:8,vsize:8,comm:20' IFS=' '; trap 'exec 66 exec 66 $f && command ps L | tr -s ' ' >&$f; while read -u66 l >&/dev/null; do a=${l/% */}; $c,$a k -${a//%/} -A; yn "Add $a" && P[$SECONDS]=$a; done } Show Sample Output
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 http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Show Sample Output
shell generate random strong password Show Sample Output
* Add comment with # in your command * Later you can search that command on that comment with CTRL+R In the title command, you could search it later by invoking the command search tool by first typing CTRL+R and then typing "revert" Show Sample Output
eg:
Already running cmd
sleep 120
Substitution cmd
c=$(pgrep sleep) && sleep 5 && kill $c
Execute a process or list of commands in the given interval and output the difference in output. Show Sample Output
Top 30 History Command line with histogram display Show Sample Output
in this examp start htop command in tmux session over the shell cosole and set title for the tmux without doing it manuelly in tmux
This will show you any links that a command follows (unlike 'file -L'), as well as the ultimate binary or script. Put the name of the command at the very end; this will be passed to perl as the first argument. For obvious reasons, this doesn't work with aliases or functions. Show Sample Output
Normally the bash builtin command 'set' displays all vars and functions. This just shows the vars. Useful if you want to see different output then env or declare or export.
Alias 'sete' shows sets variables
alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'
Alias setf shows the functions.
alias setf='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/,\$p"'
Also see: http://www.commandlinefu.com/commands/view/6899/print-all-environment-variables-including-hidden-ones
At the very least, some cool sed commands!
From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Show Sample Output
Using the output of 'ps' to determine CPU usage is misleading, as the CPU column in 'ps' shows CPU usage per process over the entire lifetime of the process. In order to get *current* CPU usage (without scraping a top screen) you need to pull some numbers from /proc/stat. Here, we take two readings, once second apart, determine how much IDLE time was spent across all CPUs, divide by the number of CPUs, and then subtract from 100 to get non-idle time. Show Sample Output
# AllInOne: Update what packages are available, upgrade to new versions, remove unneeded packages # (some are no longer needed, replaced by the ones from ap upgrade), check for dependencies # and clean local cached packages (saved on disk but not installed?,some are needed? [this only cleans unneeded unlike ap clean]). # aliases (copy into ~/.bashrc file): alias a='alias' a ap='apt-get' a r='ap autoremove -y' a up='ap update' a u='up && ap upgrade -y --show-progress && r && ap check && ap autoclean' # && means "and run if the previous succeeded", you can change it to ; to "run even if previous failed". I'm not sure if ap check should be before or after ap upgrade -y, you can also change the alias names. # To expand aliases in bash use ctrl alt e or see this ow.ly/zBKHs # For more useful aliases go to ow.ly/zBMOx
Requires mencoder. Show Sample Output
Explination: https://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits/23728630#23728630 Why 16 Characters: https://www.wired.com/story/7-steps-to-password-perfection/ Show Sample Output
Change :alnum: to :graph: for all printable characters Show Sample Output
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.
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
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: