View and Search Text and Directories

Goal: Use various commands to view, inspect and search a text file.



Exercise: Setting Up

Question:

  • There is a folder called intro_to_linux within the /project/<project-name>/ folder.

  • How would you copy this folder into your home folder?

  • Before moving on, please make sure you get this copied over correctly.

  • All further exercises assume you will be working within this folder, within the home folder

  • As you work through exercises take note of the []$ cd ~/intro_to_linux - remember the tilda character ~ is a shortcut for the home folder.


Setting Up: Answer(s)

Answer: There are a number of ways…

Method 01: Move into your home folder and copy into this location.

The . marks the current working directory.

[]$ cd [~]$ cp -r /project/<project-name>/intro_to_linux/ . cp: cannot open 'intro_to_linux/workshop_me.txt' for reading: Permission denied [~]$ ls Desktop Documents Downloads intro_to_linux
[~]$ cd /project/<project-name>/ [<project-name>]$ cp -r intro_to_linux/ ~ cp: cannot open 'intro_to_linux/workshop_me.txt' for reading: Permission denied [<project-name>]$ ls ~ Desktop Documents Downloads intro_to_linux
# -rw------- 1 <arcc-username> <project-name> 23 Oct 5 07:20 workshop_me.txt

View the content of files

Command

Description

cat

more

head


View the content of files

Command

Description

tail


Exercises: View Files: Give it a go.


Answers


Search for a string within a text file (grep) 

Command

Description

grep


Examples: Search a file


Examples: Search folders and files


Exercises: Search Files


Answers