0% found this document useful (0 votes)
44 views2 pages

General File Commands

This document discusses various file commands and operations in Linux/Unix including reading and writing files, setting file permissions, using pipes to connect commands, and using filters like grep and sort. Pipes allow the output of one command to serve as input for another command without creating temporary files. Filters can be used to extract or arrange the contents of files based on patterns, sorting, and merging files. Specifically, grep searches for regular expressions in files, sort arranges files in alphabetical order, and chmod is used to set read/write/execute permissions on files.

Uploaded by

jagardian
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

General File Commands

This document discusses various file commands and operations in Linux/Unix including reading and writing files, setting file permissions, using pipes to connect commands, and using filters like grep and sort. Pipes allow the output of one command to serve as input for another command without creating temporary files. Filters can be used to extract or arrange the contents of files based on patterns, sorting, and merging files. Specifically, grep searches for regular expressions in files, sort arranges files in alphabetical order, and chmod is used to set read/write/execute permissions on files.

Uploaded by

jagardian
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

General file commands

$read variable-name

$echo “pec uni”

$wc abc (word count---in file abc)

FILE ACCESS PERMISSIONS

$chmod +x abc (to grant permission to file abc to execute (x))

$chmod -x abc (revoking the permission)

R – read

h- hide

$chmod 777 abc (for granting all permissions to file abc)

PIPES (mechanism which takes output of a command as its input for the next
command)
$who |wc (output from who is input of wc -------then result is displayed)

PIPES PREVENTS US FROM MAKING TEMPORARY FILES

FILTERS
To extract lines which contain a specific pattern

To arrange the contents of a file in sorted order

Replace the existing characters with some other characters

To store intermediate results of a long pipe

Merge 2 or more file together using filters

2 types

1. GREP
2. SORT – to sort in alphabetical order
 $sort
Abc
Xyz
Ctrl+d
(press enter ---- result is in sorted order)
 $sort –r (in reverse alphabetical order)
 $sort –f (to ignore the case distinction)
 $sort –n (to sort numbers)

GREP (global search for regular expressions)-----extracts data from file

$grep “pec” abc (searches for lines containing pec in file abc and displays them)

$grep “b$” abc (extracting lines that end with b in file abc and displays them)

$grep “^t” abc (extracting lines that start with t in file abc and displays them)

$grep “pec|uiet|ccet” abc (for multiple lines search)

Fgrep ---------fixed grep,,,extracts only fixed strings

$fgrep “pec is a” abc (only those lines which contain this string as a whole)

Egrep----------extended grep -----------to lok out a pattern

$egrep “(ica)$” abc (searches for the string ica in the file abc , it may be in any word also)

You might also like