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.
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:
Creating feature-branches off master, and trying to merge them in an integration branch (preview), sometimes causes conflicts because the feature-branch might hold changes from 'master' that aren't on preview yet. So this ensures only the commits added to the feature-branch are moved to integration (preview).
Note: This assumes you're currently on the feature-branch. Adjust 'master/preview' branch names to suit your environment.
Useful for finding newly added lines to a file, tail + can be used to show only the lines starting at some offset. A syslog scanner would look at the file for the first time, then record the end_of_file record number using wc -l. Later (hours, days), scan only at the lines that were added since the last scan.
When you block any hosts using this method, the hosts can't do anything in the network.
The block is applied on firewall or gateway of the network.
view is the command: vi -r which opens a file in read-only mode. The + character jumps to the bottom of the logfile where the most relevant information starts. Other aliases can be created for commonly viewed logfiles.
ps and grep is a dangerous combination -- grep tries to match everything on each line (thus the all too common: grep -v grep hack). ps -C doesn't use grep, it uses the process table for an exact match. Thus, you'll get an accurate list with: ps -fC sh rather finding every process with sh somewhere on the line.
I used this fragment with Imagemagick convert so that I can place long text strings in pictures. The "\n" gets converted to a true newline in the image.
So this fragment uses fold command to wrap the line and then sed to convert newlines (and any trailing spaces on the line) to the text "\n"
this command is used to locate all pom.xml files, access the dir and do a mvn clean, but I do recommend you to disable network interfaces to not download dependencies packages to be faster.
After you run this script, you can check status for broken symlink with this command:
find -L . -type l
Will stop all running containers, then remove all containers
**This isn't for selectively handling containers, it removes everything**
Usage example: display output of a command running in the background at desired time
The example in details: report disk quotas and that backup process will start soon
In my /etc/crontab file I added following four lines for weekly automatic incremental backup:
52 13 * * 7 root mount /dev/sda3 /media/da2dc69c-92cc-4249-b2c3-9b00847e7106
53 13 * * 7 knoppix5 df -h >~/df.txt
54 13 * * 7 knoppix5 env DISPLAY=:0 /usr/bin/gedit ~/df.txt && wmctl -a gedit
55 13 * * 7 root /home/knoppix5/rdiff-backup.sh
line one: as root mount media for backup on Sunday 13:52
line two: as user knoppix5 write out to text file in home directory the free space of all mounted disks on Sunday 13:53
line three: in front of you open and display a very simple text editor (I prefer gedit) with content of previously reported disk usage at Sunday 13:54
wmctl -a gedit means (from the manual):
-a Switch to the desktop containing the window , raise the window, and give it focus.
line four: as root run incremental backup script rdiff-backup.sh as root on Sunday 13:54
my rdiff-backup.sh, with root permissions backups in short time (writes only changes from the last backup) the etire linux system (except excluded - i.e. you don't want backup recursively your backup disk), looks like this (Show sample output):
This counts all established sessions on port 80. You can change :80 to any port number you want to check.
gets network ports
only ones for the sshd service
only logged in a specific user (changed for public posting)
only in a specific localhost:port range
Only the part of the response after the ":" character
Only the part of the response before the 1st space
Output is just the rssh port
Return the creation date of a file on ext2, 3, 4 filesystems, because stat command won't show it.
Useful on ubuntu, debian, and else
runonchange /etc/nginx nginx -t
Ignores vim temp files. Depends on 'inotify-tools' for monitoring of file changes. Alternative to tools like 'entr', 'watchr'.
The leading plus sign is removed - Minus sign is left intact
Uses the lm-sensors package in Linux to display fan speed. Grep RPM is used to discover lines containing the text RPM, and sed is used to edit out everything but the RPM number. The watch utility is used to update the display every 10 seconds and -d highlights any changes from the previous value. The eval function of Bash is used to execute the command enclosed in the ".." string.
Queries whether the monitor is on according to DPMS. If true then turns the monitor off, if false turns it on. The -display option on xset means the command will work from sessions other than the console, such as ssh or a cron'd script. Command should display any errors if there are any problems (eg no X available), otherwise no output if successful.
Welcome to Jon H. (@fart), the new maintainer of CommandLineFu.
In the absence of a forum, I encourage people welcome him, here, in the comments.
Also... What would you like to improve/change about the site?