Often you will grep for certain strings in a text file, but need to find which line it’s on within that file. On a standard grep output, you will see the output, but have no idea which line the string has been found on. grep has an option, -n, which resolves that. As an example, …
Tag Archives: linux
Add Line Numbers to “cat” Output
cat can be used to print the contents of a file in a Terminal, and it’s often useful to number each line of the output (including empty lines). Adding line numbers is as simple as adding the -n switch to the command: cat -n filename.txt Example Output, with -n switch: $ cat -n filename.txt 1 Line …
Using grep and Ignoring Case (Case Insensitive grep)
grep is a great way to find phrases, words, and characters in text. One of the biggest stumbling blocks is case – is the word “Hello”, “hello”, “HELLO”, or even “HeLLo”? All of these are different, and a “grep “Hello”” would only find lines containing the first “Hello” example. You can, however, exclude case from …
Continue reading “Using grep and Ignoring Case (Case Insensitive grep)”
Using dig to Query a Specific DNS Server (Name Server) Directly (Linux, BSD, OSX)
There may be occasions when you wish to query a DNS server directly. I often do it before changing DNS servers for a domain; I’ll setup the new records on the new DNS servers, and then query them directly to ensure they are returning the correct records. I recommend that anyone running DNS services for …
Continue reading “Using dig to Query a Specific DNS Server (Name Server) Directly (Linux, BSD, OSX)”
Using grep to Exclude Lines Containing Certain Characters/Text
I like to watch Apache log files using tail -f but they often get filled up with data I don’t want/need to see – like, when I access the web site. grep is a great tool to search for certain information in text files – but it can also exclude certain pieces of information which …
Continue reading “Using grep to Exclude Lines Containing Certain Characters/Text”
Kill a GNU Screen Session from the Command Line
This article is about GNU Screen – you can read about GNU Screen here: http://www.gnu.org/software/screen/ There may be times when you have multiple, or even a single, screen session which you want to kill without attaching to it and ending it as you normally would. You can kill a screen session using the session ID or the …
Continue reading “Kill a GNU Screen Session from the Command Line”
Removing packages only installed as dependancies and no longer needed (Ubuntu, Debian)
We’ve all installed packages, using apt-get, where it’s installed a lot of other packages to satisfy dependancies. But what if you remove that package at a later date that needed all of those dependancies? You’ll probably find it’s left the dependancies installed.. and if you’ve not installed any other packages which also need those dependacies, …
Finding out when (and where from) a user last logged into a Linux/BSD machine
There may be times when you want to find out when and where from a user last logged into a Linux or BSD machine. Of course, you could trawl through auth logs, but there is a quicker way by using “lastlog“. lastlog is a command which shows you the last login time and also from …
Continue reading “Finding out when (and where from) a user last logged into a Linux/BSD machine”
Viewing Another Users’ Crontab Entries in Ubuntu, Debian or CentOS
There may be occasions where you, as the administrator of a machine, may want to see what cron entries your users have. Maybe you have slow downs at a particular time every day, and want to see who’s running what. All crontab’s, for all users, are stored in /var/spool/cron/crontabs on Debian and Ubuntu, as plain …
Continue reading “Viewing Another Users’ Crontab Entries in Ubuntu, Debian or CentOS”
Using SCP Aliases to Upload Files Quicker (OS X, BASH)
If like me, you have a particular path on a server you always upload files to, via SCP, then you’ll probably want a better way than typing the full path into the scp command everytime you upload a file! This command has been tested on OS X, but there’s no reason it wouldn’t work on …
Continue reading “Using SCP Aliases to Upload Files Quicker (OS X, BASH)”