If you can see this check that

Main Page

FIND and regex


Basic File Handling

User:
Password:

Objectives

In this session you will be covering the basics of file content searching and manipulation, including regular expressions.

Use the caine virtual machine.

To reset all the check buttons from a previous attempt click here

Question 1: FIND command

Use the find command to locate all files which start with an "a" and end in a ".conf" which exist somewhere in /usr/share. Save this list to a file '/home/caine/alist'. Make sure that the first parameter of find is "/usr/share". Run the command as user "caine" and do not worry about any permission error messages.

Tests - not attempted
/home/caine/alist exists UNTESTED
Files found UNTESTED

Use the find command to locate all FILES in /usr/share which have the permissions "rwxr-xr-x". This is test "-perm 755", but you need another test to ensure you are talking about files and not things like directories. Save this list to /home/caine/blist. Make sure that the first parameter of find is "/usr/share". Run the command as user "caine" and ignore any permission error messages.

Tests - not attempted
/home/caine/blist exists UNTESTED
Files found UNTESTED

Use the find command to locate all directories in /usr/share which have the permissions "rwxr-xr-x". Pipe this list to wc and count the number of DIRECTORIES (so not files).
Number of directories:

Tests - not attempted
Correct number of directories UNTESTED

Again using the find command find out how many files in /usr/share are in group caine. Use the "-group caine" test for this, and make sure you are dealing with only files.
Number of files:

Tests - not attempted
Correct number of files UNTESTED

Make a directory called /home/caine/thecopy. Write a find command which copies all the files into /home/caine/thecopy which are owned by caine (use -user) in /usr/share, and which are smaller than 10240 bytes, and which have a filename starting with "a".

Tests - not attempted
/home/caine/thecopy exists UNTESTED
copy correct UNTESTED

Question 2: GREP and regexp

Using a combination of grep, regular expressions, and wc via a pipe count how many words in the /usr/share/dict/words dictionary starts with "anti" and ends with an "n".
Number of words:

Tests - not attempted
Word count UNTESTED

Using grep and regular expressions, create a file /home/caine/aword which contains all the words which start with "tele" from /usr/share/dict/words, and which are exactly 7 characters long.

Tests - not attempted
/home/caine/aword exists UNTESTED
Words correct UNTESTED

How many words have the string "ra" in them twice in /usr/share/dict/words?
Number of words:

Tests - not attempted
Word count UNTESTED

How many words are in /usr/share/dict/words which contains "ice" then an "s" or a "d" without a space in between (i.e. ices or diced). Use square brackets to form a set in your regular expression.
Number of words:

Tests - not attempted
Word count UNTESTED

Use grep on words to find a word that contains each of the vowels in alphabetical (i.e first an A, then an E, etc) order in /usr/share/dict/words. How many such words are there? (you may include words with extra vowels such as adventitious. A vowel is one of A,E,I,O,U.
Number of words:

Tests - not attempted
all vowels in order UNTESTED

The word interlinking includes the same two characters (e.g. "in") which appear three times. The word "priestessess" also contains the same two characters repeated three time (e.g. "es").

How many words can you find which contain any two characters repeated three times, like the examples "interlinking" and "priestessess". Use /usr/share/dict/words as your list of possible words and grep to find the answer.
Number of words:

Note. Do a case sensitive match, so do not use "-i".

Tests - not attempted
Two character string appears 3 times (takes a few seconds) UNTESTED

Challenge Question: This is a tricky question. Just give it 10 minutes before moving onto the next question!

How many words are 5 character palindromes? A palindrome is a word spelled the same way forward and backwards, such as "sagas". Use /usr/share/dict/words. Hint: Use multiple groups and backreferences.
Number of words:

Tests - not attempted
Number of 5 character palindromes UNTESTED


Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
Caine 13.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2024 Edinburgh Napier University