commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
This command gives a model information of a computer. Also useful in determining the host is a VM machine or actual physical machine.
Useful in scripts while you just need an IP address in a variable.
I've had this as mute.sh in my ~/bin/ for some time.
greps for search word in directory and below (defaults to cd).
-i case insensitive
-n shows line number
-H shows file name
Note that the file at the given path will have the contents of the (still) deleted file, but it is a new file with a new node number; in other words, this restores the data, but it does not actually "undelete" the old file.
I posted a function declaration encapsulating this functionality to http://www.reddit.com/r/programming/comments/7yx6f/how_to_undelete_any_open_deleted_file_in_linux/c07sqwe (please excuse the crap formatting).
If the 'lm' flag is present, then the CPU is 64-bit.
If no output, then CPU is 32-bit.
From 'man netstat'
"netstat -i | -I interface [-abdnt] [-f address_family] [-M core] [-N system]
Show the state of all network interfaces or a single interface
which have been auto-configured (interfaces statically configured
into a system, but not located at boot time are not shown). An
asterisk (``*'') after an interface name indicates that the
interface is ``down''. If -a is also present, multicast
addresses currently in use are shown for each Ethernet interface
and for each IP interface address. Multicast addresses are shown
on separate lines following the interface address with which they
are associated. If -b is also present, show the number of bytes
in and out. If -d is also present, show the number of dropped
packets. If -t is also present, show the contents of watchdog
This is a nice way to kill processes.. the example here is for firefox!!! substitute firefox for whatever the process name is...
To save the result, redirect the output to another file.
grep -v "^$" file1 > file2
Useful to check DDoS attacks on servers.
Yet another ps grep function, but this one includes the column headings.
My variant on this common function. Some highlights:
Allows you to override the default ps args of "aux"
Uses bracket trick to omit the grep process itself without having to use a second grep
Always prints the correct header row of ps output
Limitations: Ugly ps error output if you forget to quote your multi word grep argument
This command takes the output of the 'last' command, removes empty lines, gets just the first field ($USERNAME), sort the $USERNAMES in reverse order and then gives a summary count of unique matches.
Searching for a String in Multiple Files With Grep