SED useful commands

Valic —  February 5, 2013 — Leave a comment

1. How to remove lines ending with ‘baddump’ from a text file:

You’ve got a file with a bunch of lines end with “baddump”  and you need those lines to be removed completely without leaving any blank lines behind? This is the command to do it:

sed -i '/baddump$/d' file

2. You have text files with tons of empty lines and you want to get rid of those in one second?

sed '/^$/d' file > new_file

You may have multiple html files to correct at the same time.You can do that with foreach command:

foreach file (*html)
sed '/^$/d' $file > new_files Continue Reading...

Beginners – Finding Things

Valic —  January 17, 2013 — Leave a comment

The following commands are used to find files.  If you don’t know approximately where they are you need more powerful tools to find files such as these:

Linux Command Description


This command shows the full path of shell commands found in your path. For example, if you want to know exactly where the grep command is located on the filesystem, you can type which grep.

The output should be something like: /bin/grep


Locates the program, source code, and manual page for a command. For example, to find out where ls and its man page are type: whereis ls.

The output will look something like: ls: /bin/ls /usr/share/man/man1/ls.1.gz


A quick way to search for files anywhere on the filesystem. For example, you can find all files and directories that contain the name firefox by typing: locate firefox.

To update the locate database run the following command: updatedb.


Find is a very powerful command, but sometimes tricky to use. It can be used to search for files matching certain patterns as well as many other types of searches.
Example: find . -name \*debThis example starts searching in the current directory  and all sub-directories looking for files with deb at the end of their names.
Page 1 of 11