Category Archives: Uncategorized

Home / Uncategorized
1 Post

In my time working with Linux, there have been a number of very useful "obscure" commands that I've discovered. These are commands that I'll use pretty frequently. However, the problem is that they can be difficult to memorize. As a result, whenever I need to use the command again, I end up google searching to find out exactly what the syntax for it is.

I'm creating this post mostly for personal use. I wanted to consolidate all of these commands into a single location so that I don't have to search the internet each time I need to use one. I hope others find it useful. Feel free to comment with your own if you want to share!

Really clear the terminal in PuTTY

When working in PuTTY, the clear command doesn't truly clear the terminal, it just shifts all of the text up. One alternative is the reset command, but it completely re-initializes the terminal which isn't what I want. What does work is:

I don't know why it works, but it does. I've only ever used it on PuTTY, but I hear it works on many other terminals, including OSX and most *nix terminals.

Replace a string in multiple files in a directory

Replace oldString with the string you want to replace, and set newString to be whatever you want to replace it with. Set directory to specify which directory this command will act on (it works recursively).

This command will search through every file in directory and replace all occurrences of oldString with newString.

Kill all processes that contain a string in the name

There are two methods for this.

Replace string with the text you are searching for in the processes. Either of these commands will then kill all processes that have string in their name.

Remove extra carriage return from DOS (if you don't have dos2unix)

DOS such as Windows append an extra carriage return for a newline, whereas Linux does not. This can be an issue. dos2unix is a useful that can convert DOS/MAC text to Linux text, but it's not available on every machine. This function will do the trick as well:

This takes the file infile, removes all of the extra carriage returns ('\r'), and outputs it to a new text file outfile. Warning: This will remove all of the carriage returns in the file, not just the ones from newline. This command is nice because it keeps the original in case you ever need it again.

Find all files that contain specified text

This command searches the specified directory (recursively) and outputs all of the files that contain the specified text. To clarify, this command searches the contents of the files themselves for the specified search text. It does not just search for the file names.

Count the number of processes containing specified string in process name

This command will output the number of processes that contain searchstring in the process name:

A short explanation: ps aux prints all currently running processes. The grep command filters out all processes that don't have the word searchstring in them. The [] brackets remove command itself so that it is not counted as a running process. The -c flag specifies the count command.

Display date and time in terminal

Outputs the date and time in the top right corner of the terminal.