commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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:
The taskkill command has the option of the curve, for a complete list just type: taskkill /? As we know, but to give a practical example, suppose you want to act only on the user's processes Cicciopalla use this command
when editing .bash_profile (or .bashrc), run this to use the new version without having to exit and open a new terminal
One time you logged in, you can prove these method just writing "firefox".
if you lose your sound, this will restart alsa and you will get your sound back
Parsing the output of ls is never a good idea for any reason. Using find this way:
- works with files that have spaces in their names.
- actually lists "sub folders" and not of all files and folders.
- does not break if there are a huge number of files in the current directory.
_ff(){
cd /mnt;
echo /mnt/*/* |sed '
s/ \/mnt\//\&/g;
'|sed '/'"$1"'/!d';
cd -;
}
ff(){
case $# in
0)
echo "usage: ff glob [sed-cmds] [--|var-name]"
;;
1)
_ff $1 |sed =
;;
[2-9])
case $2 in
--) _ff $1 |less -SN
;;
*) _ff $1 |sed -n ''"$2"''|tr '\n' '\040' |sed 's/.*/export '"$3"'=\"&/;s/=\" /=\"/;s/ $/\"/' > $HOME/.ff;
case $# in
3)
. $HOME/.ff
;;
esac;
sed '
s/export .*=\"/\$'"$3"' = \"/;' $HOME/.ff;\
;;
esac
;;
esac;
}
v(){
local a=$HOME;
sed '
s/export /less -n \$/;
s/=.*//;
' $a/.ff > $a/.v ;
. $a/.v ;
}
Another approach using ls(1)
lsl(){
_lsl ()
{
ls -l $3 /mnt/*/$1* 2>/dev/null;
};
case $# in
0)
echo "usage: lsl pat [ls-options|result-no]";
echo "usage: lsle pat [sed-cmds]"
;;
1)
_lsl $1 |sed =
;;
2)
case $2 in
-*) _lsl $1 $@;;
*)
_lsl $1 |sed 's/.* //;
'"$2"'!d;
'"$2"'q' > $HOME/.lsl ;
export v=$(sed 1q $HOME/.lsl);
echo \$v = $v
;;
esac
;;
esac;
}
exp(){
echo "%s/\$/ /";
echo "%j";
echo "s/^/export v=\"";
echo "s/\$/\"";
echo "s/ \"\$/\"";
echo ".";
echo "wq";
}
lsle(){
lsl $1 -1 |sed $2 > .lsl&&
exp |ed -s .lsl >&-&&
. .lsl&&
echo \$v = $v;
}
A simple but effective replacement for ps aux. I used to waste my time running ps over and over; top is the way to go. It also allows complex sorting options. Press q to exit "nicely" (Ctrl + C is always an option, of course). Note that the list updates each second, resorting in the process; if you're trying to grab a specific PID, you might be better off with ps.
htop
Alternatively, htop is available, though it may not come pre-installed. htop is slightly more interactive than top and includes color coding, visuals, and a nice interface for selecting and then killing processes. (Thanks to bwoodacre for this great tool.)
The pgrep retrieves the PID, then the KILL receive it, and kill it...
It works also if the application has more than one instance....
Just find out the daemon with $ netstat -atulpe. Then type in his name and he gets the SIGTERM.
IMVHO if you are using cpan to install perl modules you are doing it wrong.
Aside from curl one will need iconv windows binary since windows lacks a native utf-8 cli interface. In my case I need a proxy in China and iconv to convert gbk status string into utf-8. GnuWin32 is a good choice with loads of coreutils natively ported to Windows
"FOR /f" is the solution to pass iconv output to curl.
If you need to print some portion of a huge file, let's say you want to print from line 200 to 300, you can use this command to print the line from LINE1 to LINE2 of file FILE.