Commands by LinuxMan (9)

  • A commandline version of the notepad in a browser: All credit to the origional author of this fantastic command, whos only failing as most of the comments pointed out was that it wasn't a command... well, now its a command. Send all upvotes to dtlp747.

    firefox 'data:text/html, <html contenteditable>'
    LinuxMan · 2013-04-14 02:13:03 1
  • I don't know why anyone would use this, I was just messing around tonight and managed to start bash without using any letters and thought I would share. It's pretty simple, first it tries to execute "-" redirecting stderr to stdout which prints the error "bash: -: command not found" to standard output, then I try to execute "bash: -: command not found" which produces the output "bash: bash: -: command not found: command not found". lastly, (on the other side of the semicolon) I use the underscore environment variable which refers to the last command run ("bash: -: command not found") and take out everything after the first ":" character using brace expressions and your left with "bash" Show Sample Output

    "$(- 2>&1)";${_%%:*}
    LinuxMan · 2012-12-29 09:21:09 2
  • Shows all configurations to apt and dpkg, rarely changed, you probably still have the default configuration. Go ahead and explore your configuration if you dare, perhaps change your apt-cache directory, Dir::Cache "var/cache/apt/"; or the names of the log files. Show Sample Output

    apt-config dump
    LinuxMan · 2011-12-13 19:11:02 1
  • Normally, if you just want to see directories you'd use brianmuckian's command 'ls -d *\', but I ran into problems trying to use that command in my script because there are often multiple directories per line. If you need to script something with directories and want to guarantee that there is only one entry per line, this is the fastest way i know Show Sample Output

    ls -l | grep ^d | sed 's:.*\ ::g'
    LinuxMan · 2011-08-06 23:52:46 4
  • short enough to be tweetable Show Sample Output

    ifconfig | grep "inet\ " | grep -v "127.0" | sed -e 's/inet\ addr://g' | sed -e 's/Bcast:/\ \ \ \ \ \ \ /g' | cut -c 1-29 | sed -e 's/\ //g'
    LinuxMan · 2010-12-01 19:06:11 1
  • This command finds all of the functions defined in any shell script you specify including .bashrc

    functions(){ read -p "File name> "; sort -d $REPLY | grep "(){" | sed -e 's/(){//g' | less; }
    LinuxMan · 2010-12-01 18:49:48 0
  • Never read the documentation? No, then why have that ~ 20 MB sit there and take up space? This command preserves directory structure wile removing all of those unnecessary help and documentation files. Works on Ubuntu, Debian, and most related systems. Gives a lot of directory errors, I'll fix those later.

    for i in {a..z};do sudo rm /usr/share/doc/$i*/*;done
    LinuxMan · 2010-07-23 01:52:25 2
  • Thanks th John_W for suggesting the fix allowing ~/ to be used when saving a directory. directions: Type in a url, it will show a preview of what the file will look like when saved, then asks if you want to save the preview and where you want to save it. Great for grabbing the latest commandlinefu commands without a full web browser or even a GUI. Requires: w3m Show Sample Output

    read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE
    LinuxMan · 2010-07-13 22:36:38 2
  • Thanks to flatcap for optimizing this command. This command takes advantage of the ext4 filesystem's resistance to fragmentation. By using this command, files that were previously fragmented will be copied / deleted / pasted essentially giving the filesystem another chance at saving the file contiguously. ( unlike FAT / NTFS, the *nix filesystem always try to save a file without fragmenting it ) My command only effects the home directory and only those files with your R/W (read / write ) permissions. There are two issues with this command: 1. it really won't help, it works, but linux doesn't suffer much (if any ) fragmentation and even fragmented files have fast I/O 2. it doesn't discriminate between fragmented and non-fragmented files, so a large ~/ directory with no fragments will take almost as long as an equally sized fragmented ~/ directory The benefits i managed to work into the command: 1. it only defragments files under 16mb, because a large file with fragments isn't as noticeable as a small file that's fragmented, and copy/ delete/ paste of large files would take too long 2. it gives a nice countdown in the terminal so you know how far how much progress is being made and just like other defragmenters you can stop at any time ( use ctrl+c ) 3. fast! i can defrag my ~/ directory in 11 seconds thanks to the ramdrive powering the command's temporary storage bottom line: 1. its only an experiment, safe ( i've used it several times for testing ), but probably not very effective ( unless you somehow have a fragmentation problem on linux ). might be a placebo for recent windows converts looking for a defrag utility on linux and won't accept no for an answer 2. it's my first commandlinefu command Show Sample Output

    find ~ -maxdepth 20 -type f -size -16M -print > t; for ((i=$(wc -l < t); i>0; i--)) do a=$(sed -n ${i}p < t); mv "$a" /dev/shm/d; mv /dev/shm/d "$a"; echo $i; done; echo DONE; rm t
    LinuxMan · 2010-07-07 04:29:22 6

What's this? 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.

Share Your Commands

Check These Out

grep processes list avoiding the grep itself
Trick to avoid the form: grep process | grep - v grep

Restart openssh-server on your Synology NAS from commandline.
The correct way to restart openssh-server on your synology nas.

Suspend to ram

Print every Nth line
Sometimes commands give you too much feedback. Perhaps 1/100th might be enough. If so, every() is for you. $ my_verbose_command | every 100 will print every 100th line of output. Specifically, it will print lines 100, 200, 300, etc If you use a negative argument it will print the *first* of a block, $ my_verbose_command | every -100 It will print lines 1, 101, 201, 301, etc The function wraps up this useful sed snippet: $ ... | sed -n '0~100p' don't print anything by default $ sed -n starting at line 0, then every hundred lines ( ~100 ) print. $ '0~100p' There's also some bash magic to test if the number is negative: we want character 0, length 1, of variable N. $ ${N:0:1} If it *is* negative, strip off the first character ${N:1} is character 1 onwards (second actual character).

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Remove duplicate rows of an un-sorted file based on a single column
$F[0] filters using first word. $F[1] - 2nd, and so on.

Push your present working directory to a stack that you can pop later
If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd. cd /home/complicated/path/.I/dont/want/to/forget pushd /tmp cd thing/in/tmp popd (returns you to /home/complicated/path/.I/dont/want/to/forget)

Grep for regular expression globally, list files and positions.
Grep for expression globally, list files and positions. "Hirn" is a nice german crib meaning "Brain". :-) Afterwards you can edit the line you want with "vi ./p_common/common_main.pbt +1550"

A command to copy mysql tables from a remote host to current host via ssh.
This version compresses the data for transport.

Generat a Random MAC address

Stay in the loop…

Follow the Tweets.

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.


Subscribe to the feeds.

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: