Linux Commands: Difference between revisions
Jump to navigation
Jump to search
(→rpm) |
(→sed) |
||
Line 31: | Line 31: | ||
sed -n # Silent - suppress automatic printing of pattern space |
sed -n # Silent - suppress automatic printing of pattern space |
||
sed -r # Use extended regular expression |
sed -r # Use extended regular expression |
||
sed -i "s/foo/bar/" *.txt # In-place file modification |
|||
</source> |
</source> |
||
=== References === |
|||
* [http://sed.sourceforge.net/ The SED Homepage on SourceForge] |
|||
* [http://sed.sourceforge.net/sedfaq.html The SED FAQ] |
|||
* [http://www.opengroup.org/onlinepubs/007908799/xcu/sed.html The SED man page] |
|||
* [http://www.gnu.org/software/sed/manual/sed.html Sed, a stream editor] |
|||
* [http://sed.sourceforge.net/sed1line.txt The sed one-liners] |
|||
=== Regular expressions=== |
=== Regular expressions=== |
Revision as of 14:57, 13 October 2008
grep
grep -Rsl PATTERN [FILE] # Recursive, no error output, only list filename
grep BASIC-REG-EXP-PATTERN [FILE] # Use classic regexp (like "dma\|DMA")
egrep EXT-REG-EXP-PATTERN [FILE] # Same as grep -E. Use extended regexp (like "dma|DMA")
fgrep FIXED-STRINGS-REG-EXP [FILE] # Same as grep -F. Pattern is a list of strings to match.
grep -n PATTERN [FILE] # Print matched line numbers.
grep -- "-s" [FILE] # Search for text "-s"
rpm
- RPM RedHat Package Manager
- Using RPM: THe Basics (Part I)
- Install commands
rpm -ivh package # Installing a package - verbose and progress bars
rpm -iv -nodeps package # Installing a package (verbose), ignore dependencies
- Query commands
rpm -ql package # List files provided by a package
- To query a package that has not been installed, add -p option to the command:
rpm -qpl package # List files provided by a package
sed
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
sed -n # Silent - suppress automatic printing of pattern space
sed -r # Use extended regular expression
sed -i "s/foo/bar/" *.txt # In-place file modification
References
- The SED Homepage on SourceForge
- The SED FAQ
- The SED man page
- Sed, a stream editor
- The sed one-liners
Regular expressions
The information below is only illustrative. See e.g. Wikipedia page for reference information. The list below is actually for extended regular expressions, which can be obtained in sed using option -r (sed -r).
Regexp | Description |
---|---|
. | Match any character |
gray|grey | Match gray or grey |
gr(a|e)y | Match gray or grey |
gr[ae]y | Match gray or grey |
file[^0-2] | Match file3 or file4, but not file0, file1, file2. |
colou?r | (zero or one) - Match Color or Colour. |
ab*c | (zero or more) - Match ac, abc, abbc, .... |
ab+c | (one or more) - Match abc, abbc, abbbc, .... |
a{3,5} | (at least m and not more than n times) - Match aaa, aaaa, aaaaa. |
^on single line$ | (start and end of line) - Match on single line on a single line. |
When using standard (non-extended) regular expression, some special meta-characters (like the parenthesis ( ), or braces { }) must be quoted with backslash \.
Miscellaneous
- htop
- an improved top command (http://htop.sourceforge.net/index.php)
- strace
- trace system calls and signals