Find if $b is in $a in bash Show Sample Output
Find if $b is in $a in bash Show Sample Output
Launch a command from within a manpage, vim style. This is rather trivial, but can be very useful to try out the functions described in a manpage without actually quitting it (or switching to another console/screen/...). Show Sample Output
Compares two versions with dpkg. It is not always obvious what version dpkg/apt will consider to be more recent. Operators include the following : * These treat an empty version as earlier than any version: lt le eq ne ge gt. * These treat an empty version as later than any version: lt-nl le-nl ge-nl gt-nl. * These are provided only for compatibility with control file syntax: < > >. This command doesn't output anything. It only returns with status 0 or 1, hence the echo "y" || echo "n" to get an output. Show Sample Output
Create a persistent SSH connection to the host in the background. Combine this with settings in your ~/.ssh/config: Host host ControlPath ~/.ssh/master-%r@%h:%p ControlMaster no All the SSH connections to the machine will then go through the persisten SSH socket. This is very useful if you are using SSH to synchronize files (using rsync/sftp/cvs/svn) on a regular basis because it won't create a new socket each time to open an ssh connection.
Notes: * Adjust the find command to your own filters. * The -P flag forces to keep absolute paths in the tarball, so that you can be sure that the exact same file hierarchy will be created on the second machine.
Opens or closes the cdrom device.
Useful to archive files once a day:
cp file file.$(date --iso)
Show Sample Output
Displays a list of all the basic keyboard shortcuts in screen. Show Sample Output
You can then switch from a file to another with ^W^W
Cleanly create tempfiles using mktemp and remove them using traps instead of removing them in the end of the script. This way, you make sure the tempfiles are removed properly even if the script is killed or interrupted.
For a user script in KDE4, you can set TMPROOT using :
TMPROOT=$(kde4-config --path tmp)
This one-liner outputs a random number between the values given for FLOOR and RANGE. Show Sample Output
Requires: imagemagick and graphviz
On Debian systems, displays a graph of package dependencies. Works also with other image formats, like svg :
apt-cache dotty bash | dot -T svg | display
List the commands you have the right to use with sudo. Show Sample Output
Requires: signing-party (on Debian). Note: you need a working MTA on your machine.
This is the solution to the common mistake made by sudo newbies, since
sudo echo "foo bar" >> /path/to/some/file
does NOT add to the file as root.
Alternatively,
sudo echo "foo bar" > /path/to/some/file
should be replaced by
echo "foo bar" | sudo tee /path/to/some/file
And you can add a >/dev/null in the end if you're not interested in the tee stdout :
echo "foo bar" | sudo tee -a /path/to/some/file >/dev/null
Show Sample Output
On Debian systems, choose which command provides java. Works for all alternatives listed in /etc/alternatives.
Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)
This is useful when you want to copy a file and also force a user, a group and a mode for that file.
Note: if you want to move that file instead of copying it, you can use
install -o user -g group -m 755 /path/to/file /path/to/dir/ && rm -f /path/to/file
which will remove the file only if the install command went fine.
Filter comments and empty lines in files. I find this very useful when trying to find what values are actually set in a very long example config file. I often set an alias for it, like : alias nocomment='grep -v "^\($\|#\)"' Show Sample Output
!$ recalls the last argument of the previous command. This is very useful when you have to operate several operations on the same file for example. Show Sample Output
KDE4 is great, but still a bit buggy, and sometimes plasma requires to be restarted. Instead of quitting it with "killall plasma", which might loose your preferences (widgets, etc.), kquitapp will cleanly quit it. Tip: you can type this in the "Alt+F2" window, and then type "plasma" in Alt+F2 again to restart plasma (be patient though...).
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: