Data and file manipulation (head, tail, wc, grep, find)

Oh, there you are! I was waiting for you to come back from 202!

Now that you’re here we’re going to talk about new Linux commands you might not know about yet, these commands allow the modification of files and data streams.

Note : We are not going to discuss file creation or deletion in this class for technical reasons regarding the terminal on hack.courses, but it might be part of another future class ;).


Let’s start with the command head, it seems appropriate to start with this specific one since it displays the start of a given file or data stream. By default, head will only display the 10 first lines of the contents passed to it as parameters.

You can try it using the following command :

$> head /etc/passwd
root:x:0:0:root:/root:/usr/bin/shell.sh
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/sbin/nologin

As you can see, only the 10 first lines of the /etc/passwd are displayed, you can also specify the number of lines you want to print using the -n parameter, for instance if you only want the first two lines of the same file :

$> head -n 2 /etc/passwd

tail

wc

grep

find

Wow, you’re there early aren’t you?

I’m still working on this part, it will be available soon, come back later!