Difference between revisions of "Core utilities"

From ArchWiki
Jump to: navigation, search
m (typo)
(consistency; remove subheadings until more detail is added)
Line 68: Line 68:
 
</nowiki>}}
 
</nowiki>}}
  
==Extracting compressed files==
+
==bsdtar, bzip2, gzip, ...==
 
The following function will extract a wide range of compressed file types. Add the function to {{Filename|~/.bashrc}} and use it with the syntax {{Codeline|extract <file1> <file2> ...}}
 
The following function will extract a wide range of compressed file types. Add the function to {{Filename|~/.bashrc}} and use it with the syntax {{Codeline|extract <file1> <file2> ...}}
  
Line 75: Line 75:
 
|content=<nowiki>
 
|content=<nowiki>
 
extract() {
 
extract() {
local e=0 i c
+
  local e=0 i c
 
   for i; do
 
   for i; do
 
     if [[ -f $i && -r $i ]]; then
 
     if [[ -f $i && -r $i ]]; then
Line 93: Line 93:
 
         esac
 
         esac
 
         [[ $c ]] && command $c "$i"
 
         [[ $c ]] && command $c "$i"
      else
+
    else
 
         echo "$0: cannot extract \`$i': File is unreadable" >&2; e=2
 
         echo "$0: cannot extract \`$i': File is unreadable" >&2; e=2
 
     fi
 
     fi
Line 106: Line 106:
 
[[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 {{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.
  
===Colored output===
 
 
Beyond aesthetics, {{Codeline|grep}}'s color output is immensely useful for learning {{Codeline|regexp}} and {{Codeline|grep}}'s functionality.
 
Beyond aesthetics, {{Codeline|grep}}'s color output is immensely useful for learning {{Codeline|regexp}} and {{Codeline|grep}}'s functionality.
  
Line 120: Line 119:
 
[[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 {{Codeline|more}} and {{Codeline|pg}}, {{Codeline|less}} offers a more advanced interface and complete feature-set.[http://www.greenwoodsoftware.com/less/faq.html]
  
===Browsing compressed files===
 
 
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 {{Package Official|lesspipe}}:
 
  # pacman -S lesspipe
 
  # pacman -S lesspipe
Line 142: Line 140:
 
[[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===
+
Colored output can be enabled with a simple alias. File {{Filename|~/.bashrc}} should already have the following entry copied from {{Filename|/etc/skel/.bashrc}}:
File {{Filename|~/.bashrc}} should already have the following entry copied from {{Filename|/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 {{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:
 
  eval $(dircolors -b)
 
  eval $(dircolors -b)

Revision as of 00:34, 16 February 2010

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

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 Template:Package Official 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.

alias

alias is a command in various shells, such as Bash, which enables a replacement of a word with another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command.

Personal aliases are preferably stored in Template:Filename, and system-wide aliases (which affect all users) belong in Template:Filename.

An example excerpt from Template:Filename covering several time-saving aliases: Template:File

bsdtar, bzip2, gzip, ...

The following function will extract a wide range of compressed file types. Add the function to Template:Filename and use it with the syntax Template:Codeline

Template:File

Note: Bash users should make sure extglob is enabled: Template:Codeline. It is enabled by default if using Bash completion. Zsh users should do: Template:Codeline instead.

grep

grep is a command line text search utility originally written for Unix. The Template:Codeline 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, Template:Codeline's color output is immensely useful for learning Template:Codeline and Template:Codeline's functionality.

To add it, write the following entry to Template:Filename:

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

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

Although Template:Codeline's man page states that Template:Codeline is deprecated and that Template:Codeline is preferable, this variable does not work as of Template:Package Official version 2.5.4, so use Template:Codeline 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 Template:Codeline and Template:Codeline, Template:Codeline offers a more advanced interface and complete feature-set.[1]

Frequent users of the command line interface might want to install Template:Package Official:

# pacman -S lesspipe

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

Template:Command

Template:Codeline also grants Template:Codeline 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 Template:Filename via Template:Package Official).

Re-login after installing Template:Codeline in order to activate it, or source Template:Filename.

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 Template:Filename should already have the following entry copied from Template:Filename:

alias ls='ls --color=auto'

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

eval $(dircolors -b)