Home > Unix > UNIX – Lesson 006 – ln, file and grep commands

UNIX – Lesson 006 – ln, file and grep commands

The “ln” command creates a link to a file. A link is an indirect pointer to a file
Syntax :
ln –s source_file new_file

$ ln -s Report.log Report.log.link
Creates a symbolic link to Report.log with the name of the Report.log.link.

$ ls –al
drwxr—–     2   xarabas admins 96           Feb 28 09:49 .
drwxr—–     11 xarabas admins 8192       Feb 28 09:47 ..
-rw-r—–       1  xarabas admins 160498   Feb 28 09:47 Report.log
lrwxrwxrwx 1   xarabas admins 10           Feb 28 09:49 Report.log.link -> Report.log


The “file” is a standard Unix comand for determining the type of data contained in a computer file.
Syntax :
file “filename”

$ file file.c
file.c: C program text

$ file Temp
Temp: directory

$ file compressed.gz
compressed.gz: gzip compressed data, deflated, original filename, `compressed’, last
modified: Thu Jan 26 14:08:23 2006, os: Unix

$ file backup.sh
backup.sh: executable /usr/bin/sh script


The “grep” command searches inside a text file for a pattern and prints all lines that contain the pattern
Syntax :
grep pattern filename

Key argument :

  • -i Ignore upper/lower case distinction during comparisons.
  • -c Print only a count of the lines that contain the pattern.
  • -v Print all lines except those that contain the pattern.

$ grep -i path ~xarabas/.cshrc
setenv LD_LIBRARY_PATH /usr/local2/lib:/usr/local2/include
set path=(. /bin /usr/bin /usr/sbin /usr/local/bin /usr/openwin/bin /usr/atria/bin /usr/atria/etc )
if (-f ~/.xarabas_path) then
source ~/.xarabas_path

$ grep -c path ~xarabas/.cshrc
# The LD_LIBRARY_PATH word hasn’t been examined because it’s in lower case

$ grep -ci path ~xarabas/.cshrc
# It’s similar the first one, it ignores upper and lower case with the “-i” option and with “-c” option it counts them.

Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: