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:
This command will ask for remote sudo password before executing a remote command.
you will be sad after you run a command and find out it needs root, so you should run it again but with prefix sudo.
so this line is to make it simple. just 'sudo !!'
Example: remote install an application(wine).
sshpass -p 'mypssword' ssh -t mysshloginname@192.168.1.22 "echo 'mypassword' | sudo -S apt-get install wine"
Tested on Ubuntu.
If you want to carry on your aliases while using sudo, put this into a file which will be parsed when logging in.
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
Find the USERid of a SUDOed user who has either left their terminal logged in or for scripting purposes to track who ran what commands.
This only applys to users that do sudo su - USERNAME. not sudo su USERNAME
Sudo su without the dash allows use of (echo $SUDO_USER)
probably just like 1204, but uses tee as a filter (+ I actually understand how this one works)
Will limit the amount of CPU time Grooveshark the greedy yet useful Adobe Air app will have.
Leaves the UI lagging a little, but crucially does not ruin the audio.
a simple command in order to make iptables rules permanent, run @ sudo!
Destination IPs will become invisible to source IPs!
Run program as root by SSH key forwarding instead of sudoers.
Put this alias line in .bashrc or wherever you like. Alias arguments might need extra escaping.
You might wonder about security. But you'd block out root login as much as possible of course. In sshd_config you put this:
PermitRootLogin no
Match Address 127.0.0.1
PermitRootLogin without-password
"The -b (background) option tells sudo to run the given command in the background." -- after it asks you for the password in the foreground.
Take advantage of sudo keeping you authenticated for ~15 minutes.
The command is a little longer, but it does not require X (it can run on a headless server).
Need package: gksu
Note:
Launching gui app in background that needs sudo, won't work great with our old
friendly style of launching:
sudo gedit /etc/passwd &
because this would put sudo in background !
Using gksudo as demonstrated, would popup a gui sudo window.
May be this is a common knowledge, but not knowing this
frustrated me during my newbie year.
By default sudo 'remembers' password for a few minutes, so that you do not need to re-enter password for a series of sudo commands that might follow within a short time duration.
However, sometime you might want sudo to instantly 'forget' the password.
(Next sudo command will need you to reenter the password)
Credit: I first learned this while listening to one of the 'tuxradar' podcast.
Like the http://www.commandlinefu.com/commands/view/6327/open-file-with-sudo-when-there-is-no-write-permission, but works (in zsh; my commandlinefu is not strong enough to understand why bash don't like it) with vim options, like -O, and many input files.
There could be other mistakes.
this avoids several VIM warnings, which I seem too stupid to disable: warning, readonly! and: file and buffer have changed, reload?!
USAGE: $ sudor your command
This command uses a dirty hack with history, so be sure you not turned it off.
WARNING!
This command behavior differ from other commands. It more like text macro, so you shouldn't use it in subshells, non-interactive sessions, other functions/aliases and so on. You shouldn't pipe into sudor (any string that prefixes sudor will be removed), but if you really want, use this commands:
proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; pre_sudor_command="`history 1 | cut -d ' ' -f 5- | sed -r -e 's/sudor.*$//' -e 's/\"/\\\"/g'`"; if [ -n "${pre_sudor_command/ */}" ] ; then eval "${pre_sudor_command%| *}" | sudo sh -c "$sudor_command"; else sudo sh -c "$sudor_command" ;fi ;}; alias sudor="proceed_sudo # "
Great for sysadmins! Don't forget to pass the vlan to your port in a manageable switch.
After vconfig, you should use
sudo ifconfig eth0.[VID] up
Now the interface is up, you can use dhclient or ifconfig again to get an ip address.