Difference between revisions of "Core utilities"

From ArchWiki
Jump to: navigation, search
(Undo revision 165205 by Aroko (talk) scope is not limited to coreutils package (e.g. less, grep))
(new templates, see Help:Style)
Line 9: Line 9:
 
{{Article summary end}}
 
{{Article summary end}}
  
This article deals with so-called "core" utilities on a GNU/Linux system, such as '''less''', '''ls''', and '''grep'''. The scope of this article includes -- ''but is not limited to'' -- those utilities included with the GNU {{Package Official|coreutils}} package. What follows are various tips and tricks and other helpful information related to these utilities. If sections grow too detailed, please split into separate articles.
+
This article deals with so-called "core" utilities on a GNU/Linux system, such as '''less''', '''ls''', and '''grep'''. The scope of this article includes -- ''but is not limited to'' -- those utilities included with the GNU {{Pkg|coreutils}} package. What follows are various tips and tricks and other helpful information related to these utilities. If sections grow too detailed, please split into separate articles.
  
 
==grep==
 
==grep==
[[Wikipedia:grep|grep]] is a command line text search utility originally written for Unix. The {{codeline|grep}} command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
+
[[Wikipedia:grep|grep]] is a command line text search utility originally written for Unix. The {{ic|grep}} command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
  
Beyond aesthetics, {{Codeline|grep}}'s color output is immensely useful for learning {{Codeline|regexp}} and {{Codeline|grep}}'s functionality.
+
Beyond aesthetics, {{ic|grep}}'s color output is immensely useful for learning {{ic|regexp}} and {{ic|grep}}'s functionality.
  
To add it, write the following entry to {{Filename|~/.bashrc}}:
+
To add it, write the following entry to {{ic|~/.bashrc}}:
 
  export GREP_COLOR="1;33"
 
  export GREP_COLOR="1;33"
 
  alias grep='grep --color=auto'
 
  alias grep='grep --color=auto'
  
The variable {{codeline|GREP_COLOR}} is used to specify the output color, in this example a light yellow color.
+
The variable {{ic|GREP_COLOR}} is used to specify the output color, in this example a light yellow color.
  
Although {{codeline|grep}}'s [[man page]] states that {{codeline|GREP_COLOR}} is deprecated and that {{codeline|GREP_COLORS}} is preferable, this variable does not work as of {{Package Official|grep}} version 2.5.4, so use {{codeline|GREP_COLOR}} for now.
+
Although {{ic|grep}}'s [[man page]] states that {{ic|GREP_COLOR}} is deprecated and that {{ic|GREP_COLORS}} is preferable, this variable does not work as of {{Pkg|grep}} version 2.5.4, so use {{ic|GREP_COLOR}} for now.
  
 
==less==
 
==less==
[[Wikipedia:less (Unix)|less]] is a terminal pager program used to view the contents of a text file one screen at a time. Whilst similar to other pages such as {{Codeline|more}} and {{Codeline|pg}}, {{Codeline|less}} offers a more advanced interface and complete feature-set.[http://www.greenwoodsoftware.com/less/faq.html]
+
[[Wikipedia:less (Unix)|less]] is a terminal pager program used to view the contents of a text file one screen at a time. Whilst similar to other pages such as {{ic|more}} and {{ic|pg}}, {{ic|less}} offers a more advanced interface and complete feature-set.[http://www.greenwoodsoftware.com/less/faq.html]
  
 
Enable code syntax coloring by adding this line to .bashrc:
 
Enable code syntax coloring by adding this line to .bashrc:
 
  export LESS="-R"
 
  export LESS="-R"
  
Frequent users of the command line interface might want to install {{Package Official|lesspipe}}:
+
Frequent users of the command line interface might want to install {{Pkg|lesspipe}}:
 
  # pacman -S lesspipe
 
  # pacman -S lesspipe
  
 
Users may now list the compressed files inside of an archive using their pager:
 
Users may now list the compressed files inside of an archive using their pager:
  
{{Command
+
{{hc
|name=$ less compressed_file.tar.gz
+
|$ less compressed_file.tar.gz
|output=<nowiki>
+
|<nowiki>
 
==> use tar_file:contained_file to view a file in the archive
 
==> use tar_file:contained_file to view a file in the archive
 
-rw------- username/group  695 2008-01-04 19:24 compressed_file/content1
 
-rw------- username/group  695 2008-01-04 19:24 compressed_file/content1
Line 44: Line 44:
 
</nowiki>}}
 
</nowiki>}}
  
{{Codeline|lesspipe}} also grants {{Codeline|less}} the ability of interfacing with files other than archives; serving as an alternative for the specific command associated for that file-type (such as viewing HTML via {{Package Official|html2text}}).
+
{{ic|lesspipe}} also grants {{ic|less}} the ability of interfacing with files other than archives; serving as an alternative for the specific command associated for that file-type (such as viewing HTML via {{Pkg|html2text}}).
  
Re-login after installing {{Codeline|lesspipe}} in order to activate it, or source {{Filename|/etc/profile.d/lesspipe.sh}}.
+
Re-login after installing {{ic|lesspipe}} in order to activate it, or source {{ic|/etc/profile.d/lesspipe.sh}}.
  
 
==ls==
 
==ls==
 
[[Wikipedia:ls|ls]] is a command to list files in Unix and Unix-like operating systems.
 
[[Wikipedia:ls|ls]] is a command to list files in Unix and Unix-like operating systems.
  
Colored output can be enabled with a simple alias. File {{Filename|~/.bashrc}} should already have the following entry copied from {{Filename|/etc/skel/.bashrc}}:
+
Colored output can be enabled with a simple alias. File {{ic|~/.bashrc}} should already have the following entry copied from {{ic|/etc/skel/.bashrc}}:
 
  alias ls='ls --color=auto'
 
  alias ls='ls --color=auto'
  
The next step will further enhance the colored {{Codeline|ls}} output; for example, broken (orphan) symlinks will start showing in a red hue. Add the following to {{Filename|~/.bashrc}} and relogin, or source the file:
+
The next step will further enhance the colored {{ic|ls}} output; for example, broken (orphan) symlinks will start showing in a red hue. Add the following to {{ic|~/.bashrc}} and relogin, or source the file:
 
  eval $(dircolors -b)
 
  eval $(dircolors -b)

Revision as of 14:27, 17 November 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Summary help replacing me
Tips and tricks related to so-called "core" utilities on a GNU/Linux system.
Related
Commandline Tools
General Recommendations
GNU Project

This article deals with so-called "core" utilities on a GNU/Linux system, such as less, ls, and grep. The scope of this article includes -- but is not limited to -- those utilities included with the GNU coreutils package. What follows are various tips and tricks and other helpful information related to these utilities. If sections grow too detailed, please split into separate articles.

grep

grep is a command line text search utility originally written for Unix. The grep command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.

Beyond aesthetics, grep's color output is immensely useful for learning regexp and grep's functionality.

To add it, write the following entry to ~/.bashrc:

export GREP_COLOR="1;33"
alias grep='grep --color=auto'

The variable GREP_COLOR is used to specify the output color, in this example a light yellow color.

Although grep's man page states that GREP_COLOR is deprecated and that GREP_COLORS is preferable, this variable does not work as of grep version 2.5.4, so use GREP_COLOR for now.

less

less is a terminal pager program used to view the contents of a text file one screen at a time. Whilst similar to other pages such as more and pg, less offers a more advanced interface and complete feature-set.[1]

Enable code syntax coloring by adding this line to .bashrc:

export LESS="-R"

Frequent users of the command line interface might want to install lesspipe:

# pacman -S lesspipe

Users may now list the compressed files inside of an archive using their pager:

$ less compressed_file.tar.gz
==> use tar_file:contained_file to view a file in the archive
-rw------- username/group  695 2008-01-04 19:24 compressed_file/content1
-rw------- username/group   43 2007-11-07 11:17 compressed_file/content2
compressed_file.tar.gz (END)

lesspipe also grants less the ability of interfacing with files other than archives; serving as an alternative for the specific command associated for that file-type (such as viewing HTML via html2text).

Re-login after installing lesspipe in order to activate it, or source /etc/profile.d/lesspipe.sh.

ls

ls is a command to list files in Unix and Unix-like operating systems.

Colored output can be enabled with a simple alias. File ~/.bashrc should already have the following entry copied from /etc/skel/.bashrc:

alias ls='ls --color=auto'

The next step will further enhance the colored ls output; for example, broken (orphan) symlinks will start showing in a red hue. Add the following to ~/.bashrc and relogin, or source the file:

eval $(dircolors -b)