grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}' OR awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}' In this example, we are having a text file that is having several entries like: --- c1 c2 c3 c4 this is some data HOME /dir1/dir2/.../dirN/somefile1.xml HOME /dir1/dir2/somefile2.xml some more data --- for lines starting with HOME, we are extracting the second field that is a 'file path with file name', and from that we need to get the filename only and ignore the slash delimited path. The output would be: somefile1.xml somefile2.xml (In case you give a -ive - pls give the reasons as well and enlighten the souls :-) )
Replace FILE with a filename (or - for stdin).
This will, for an application that has already been removed but had its configuration left behind, purge that configuration from the system. To test it out first, you can remove the last -y, and it will show you what it will purge without actually doing it. I mean it never hurts to check first, "just in case." ;)
ls -l may vary depending on operating system, so "print $8" may have to be changed
For disk space constraint testing. Leaves a little space available for creating temp files, etc. Easily free up the used disk space again by deleting the dummy00 file. Can tailor the testing by building smaller 'blocks' to suit the needs of the testing. WARNING: do not do this to the '/' (root) filesystem unless you know what you are doing... on some systems it could crash the OS.
grabs your local IP Address. Show Sample Output
This command toggles the touchpad on and off, when it's on, the right side scroll strip (annoying) and the tap-clicking are disabled, you can change this by changing occurances of 2 in the command to 0. this whole command can then be given a keyboard shortcut so that the touchpad is disableable without using a special fn key (which linux doesn't recognize on some computers) or a seperate button.
gets the last number of the mac address to use it for other stuff Show Sample Output
This will get the mac address of the eth0 and change lowercase to uppercase. The sed command removed the colons.
most usefull when creating batch scripts using several usb drives and some commands like mkntfs needs a device name the -w option for grep is here to filter lines when you have multiple drives with the same volume label. Without this option, the grep command will return /media/KINGSTON /media/KINGSTON_ /media/KINGSTON__ Show Sample Output
Get external IP of the current machine via http://cmyip.com Show Sample Output
I use this command to select a random movie from my movie collection.. Show Sample Output
when you can do it , avoid pipe Show Sample Output
* ps -ef # list running processes * grep string * pull the process names from 8th field * cut and delimiter '/' * print 4th field * get rid of trailing grep * for loop killall -9 $i which is the process name Show Sample Output
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: