Difference between revisions of "Core utilities"

From ArchWiki
Jump to: navigation, search
(alias: added note about /etc/bash.bashrc.local not being sourced by default anymore)
m (ip: some style fixes, see Help:Style and Help talk:Style/Formatting and Punctuation)
(46 intermediate revisions by 18 users not shown)
Line 1: Line 1:
[[Category:Utilities (English)]]
+
[[Category:System administration]]
 +
[[Category:Command shells]]
 +
[[it:Core Utilities]]
 +
[[zh-CN:Core Utilities]]
 
{{Article summary start}}
 
{{Article summary start}}
{{Article summary text|Tips and tricks related to so-called "core" utilities on a GNU/Linux system.}}
+
{{Article summary text|Tips and tricks related to so-called ''core'' utilities on a GNU/Linux system.}}
 
{{Article summary heading|Related}}
 
{{Article summary heading|Related}}
{{Article summary wiki|Commandline Tools}}
+
{{Article summary wiki|Bash}}: improved Bourne shell, Linux standard
 +
{{Article summary wiki|Zsh}}: improved Bourne/C shell, very good as interactive shell
 
{{Article summary wiki|General Recommendations}}
 
{{Article summary wiki|General Recommendations}}
 +
{{Article summary wiki|GNU Project}}
 
{{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.
 
  
==alias==
+
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.
[[Wikipedia:alias|alias]] is a command in various shells, such as [[Bash]], which enables a replacement of a word with another string. It is often used for abbreviating a system command, or for adding default arguments to a regularly used command.
+
  
Personal aliases are preferably stored in {{Filename|~/.bashrc}}, and system-wide aliases (which affect all users) belong in {{Filename|/etc/bash.bashrc.local}}.
+
== cat ==
  
{{Note|{{Filename|/etc/bash.bashrc.local}} is not sourced by default anymore.}}
+
[[Wikipedia:cat_(Unix)|cat]] (''catenate'') is a standard Unix utility that concatenates and lists files.
  
An example excerpt from {{Filename|~/.bashrc}} covering several time-saving aliases:
+
* As ''cat'' is not a shell built-in, in many occasions you may find more convenient to use a [[wikipedia:Redirection (computing)|redirection]], for example in scripts, or if you care a lot about performance. In fact {{ic|< ''file''}} does the same of {{ic|cat ''file''}}.
{{File
+
|name=~/.bashrc
+
|content=<nowiki>
+
# modified commands
+
alias diff='colordiff'             # requires colordiff package
+
alias grep='grep --color=auto'
+
alias more='less'
+
alias df='df -h'
+
alias du='du -c -h'
+
alias mkdir='mkdir -p -v'
+
alias nano='nano -w'
+
alias ping='ping -c 5'
+
alias ..='cd ..'
+
  
# new commands
+
* To append multiple lines to a file a construct like this one is used:
alias da='date "+%A, %B %d, %Y [%T]"'
+
alias du1='du --max-depth=1'
+
alias hist='history | grep $1'      # requires an argument
+
alias openports='netstat --all --numeric --programs --inet --inet6'
+
alias pg='ps -Af | grep $1'        # requires an argument (note: /usr/bin/pg is installed by the util-linux package; maybe a different alias name should be used)
+
  
# privileged access
+
{{bc|
if [ $UID -ne 0 ]; then
+
$ cat << EOF >> ''path/file''
    alias sudo='sudo '
+
''first line''
    alias scat='sudo cat'
+
...
    alias svim='sudo vim'
+
''last line''
    alias root='sudo su'
+
EOF
    alias reboot='sudo reboot'
+
}}
    alias halt='sudo halt'
+
    alias update='sudo pacman -Su'
+
    alias netcfg='sudo netcfg2'
+
fi
+
  
# ls
+
* If you need to cat file lines in reverse order, there is a utility called [[Wikipedia:tac (Unix)|tac]] (''cat'' reversed).
alias ls='ls -hF --color=auto'
+
alias lr='ls -R'                    # recursive ls
+
alias ll='ls -l'
+
alias la='ll -A'
+
alias lx='ll -BX'                  # sort by extension
+
alias lz='ll -rS'                  # sort by size
+
alias lt='ll -rt'                  # sort by date
+
alias lm='la | more'
+
  
# safety features
+
== grep ==
alias cp='cp -i'
+
alias mv='mv -i'
+
alias rm='rm -I'                    # 'rm -i' prompts for every file
+
alias ln='ln -i'
+
alias chown='chown --preserve-root'
+
alias chmod='chmod --preserve-root'
+
alias chgrp='chgrp --preserve-root'
+
</nowiki>}}
+
  
==extract==
+
[[Wikipedia:grep|grep]] (from [[Wikipedia:ed|ed]]'s ''g/re/p'', ''global/regular expression/print'') 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.
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> ...}}
+
* Remember that ''grep'' handles files, so a construct like {{ic|$ cat ''file'' <nowiki>|</nowiki> grep ''pattern''}} is replaceable with {{ic|$ grep ''pattern'' ''file''}}
  
{{File
+
* If you have to grep VCS source code, there is an optimized utility written in Perl and called {{Pkg|ack}}. See the [http://beyondgrep.com/ official web site].
|name=~/.bashrc
+
|content=<nowiki>
+
extract() {
+
    local c e i
+
  
    (($#)) || return
+
=== Colored output ===
  
    for i; do
+
Beyond aesthetics, ''grep''&#39;s color output is immensely useful for learning [[Wikipedia:regexp|regexp]] and ''grep''&#39;s functionality.
        c=''
+
        e=1
+
  
        if [[ ! -r $i ]]; then
+
To use the default colors for ''grep'', write the following entry to your shell configuration file, e.g. if using [[Bash]]:
            echo "$0: file is unreadable: \`$i'" >&2
+
{{hc|~/.bashrc|2=alias grep='grep --color=auto'}}
            continue
+
Alternatively, you can set the {{ic|GREP_OPTIONS}} [[Environment Variables|environment variable]] bearing in mind this may break some scripts that use ''grep'' [http://brainstorm.ubuntu.com/idea/24141/]:
        fi
+
export GREP_OPTIONS='--color=auto'
 +
To include file line numbers in the output, add {{ic|-n}}:
 +
alias grep='grep -n --color=auto'
  
        case $i in
+
The environment variable {{ic|GREP_COLORS}} may be used to specify different colors than the defaults.
        *.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz)))))
+
              c='bsdtar xvf';;
+
        *.7z)  c='7z x';;
+
        *.Z)  c='uncompress';;
+
        *.bz2) c='bunzip2';;
+
        *.exe) c='cabextract';;
+
        *.gz)  c='gunzip';;
+
        *.rar) c='unrar x';;
+
        *.xz)  c='unxz';;
+
        *.zip) c='unzip';;
+
        *)    echo "$0: unrecognized file extension: \`$i'" >&2
+
              continue;;
+
        esac
+
  
        command $c "$i"
+
== ip ==
        e=$?
+
[[wikipedia:Iproute2|ip]] allows you to show information about network devices, IP addresses, routing tables and other objects in the Linux [[Wikipedia:Internet Protocol|IP]] software stack. By appending various commands, you can also manipulate or configure most of these objects.
    done
+
  
    return $e
+
{| class="wikitable" border="1" cellpadding="5" cellspacing="0"
}
+
! Object !! Purpose !! manpage
</nowiki>}}
+
|-
 +
| ip addr || protocol address management || ip-address
 +
|-
 +
| ip addrlabel || protocol address label management || ip-addrlabel
 +
|-
 +
| ip l2tp || tunnel ethernet over IP (L2TPv3) || ip-l2tp
 +
|-
 +
| ip link || network device configuration || ip-link
 +
|-
 +
| ip maddr || multicast addresses management || ip-maddress
 +
|-
 +
| ip monitor || watch for netlink messages || ip-monitor
 +
|-
 +
| ip mroute || multicast routing cache management || ip-mroute
 +
|-
 +
| ip mrule || rule in multicast routing policy db
 +
|-
 +
| ip neigh || neighbour/arp tables management|| ip-neighbour
 +
|-
 +
| ip netns || process network namespace management || ip-netns
 +
|-
 +
| ip ntable ||  neighbour table configuration || ip-ntable
 +
|-
 +
| ip route || routing table management || ip-route
 +
|-
 +
| ip rule || routing policy database management || ip-rule
 +
|-
 +
| ip tcp_metrics || management for TCP Metrics || ip-tcp_metrics
 +
|-
 +
| ip tunnel || tunnel configuration || ip-tunnel
 +
|-
 +
| ip tuntap ||  manage TUN/TAP devices
 +
|-
 +
| ip xfrm ||  manage IPSec policies || ip-xfrm
 +
|}
  
{{note|[[Bash]] users should make sure extglob is enabled: {{codeline|shopt -s extglob}}. It is enabled by default if using [[Bash#Advanced completion|Bash completion]]. [[Zsh]] users should do: {{codeline|setopt kshglob}} instead.}}
+
The help command is available for all objects. For example, typing {{ic|ip addr help}} will show you the command syntax available for the address object.
  
Another way to do this is to install ''unp'' package.
+
The [[Network Configuration]] article shows how the ''ip'' command is used in practice for various common tasks.
  
==grep==
+
== less ==
[[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.
+
  
Beyond aesthetics, {{Codeline|grep}}'s color output is immensely useful for learning {{Codeline|regexp}} and {{Codeline|grep}}'s functionality.
+
[[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
 +
[[Wikipedia:more (command)|more]] and [[Wikipedia:pg (Unix)|pg]], ''less'' offers a more advanced interface and complete [http://www.greenwoodsoftware.com/less/faq.html feature-set].
  
To add it, write the following entry to {{Filename|~/.bashrc}}:
+
=== Colored output through environment variables ===
export GREP_COLOR="1;33"
+
alias grep='grep --color=auto'
+
  
The variable {{codeline|GREP_COLOR}} is used to specify the output color, in this example a light yellow color.
+
Add the following lines to your shell configuration file:
  
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.
+
{{hc|~/.bashrc|2=
 +
export LESS=-R
 +
export LESS_TERMCAP_me=$(printf '\e[0m')
 +
export LESS_TERMCAP_se=$(printf '\e[0m')
 +
export LESS_TERMCAP_ue=$(printf '\e[0m')
 +
export LESS_TERMCAP_mb=$(printf '\e[1;32m')
 +
export LESS_TERMCAP_md=$(printf '\e[1;34m')
 +
export LESS_TERMCAP_us=$(printf '\e[1;32m')
 +
export LESS_TERMCAP_so=$(printf '\e[1;44;1m')
 +
}}
  
==less==
+
Change values as you like. References: [[Wikipedia:ANSI_escape_code#Colors|ANSI escape code]].
[[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]
+
  
Enable code syntax coloring by adding this line to .bashrc:
+
=== Colored output through wrappers ===
export LESS="-R"
+
  
Frequent users of the command line interface might want to install {{Package Official|lesspipe}}:
+
You can enable code syntax coloring in ''less''. First, install {{Pkg|source-highlight}}, then add these lines to your shell configuration file:
# pacman -S lesspipe
+
{{hc|~/.bashrc|<nowiki>
 +
export LESSOPEN="| /usr/bin/source-highlight-esc.sh %s"
 +
export LESS='-R '
 +
</nowiki>}}
 +
 
 +
Frequent users of the command line interface might want to install {{Pkg|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|$ less ''compressed_file''.tar.gz|2=
|name=$ less compressed_file.tar.gz
+
|output=<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''
-rw------- username/group  43 2007-11-07 11:17 compressed_file/content2
+
-rw------- ''username''/''group''   43 2007-11-07 11:17 ''compressed_file''/''content2''
compressed_file.tar.gz (END)
+
''compressed_file''.tar.gz (END)
</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}}).
+
''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 {{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 ''lesspipe'' in order to activate it, or source {{ic|/etc/profile.d/lesspipe.sh}}.
  
==ls==
+
=== Vim as alternative pager ===
[[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}}:
+
[[Vim]] (''visual editor improved'') has a script to view the content of text files, compressed files, binaries, directories. Add the following line to your shell configuration file to use it as a pager:
 +
{{hc|~/.bashrc|2=alias less='/usr/share/vim/vim73/macros/less.sh'}}
 +
 
 +
There is also an alternative to ''less.sh'' macro, which may work as the {{ic|PAGER}} environment variable. Install {{AUR|vimpager-git}} and add the following to your shell configuration file:
 +
{{hc|~/.bashrc|2=
 +
export PAGER='vimpager'
 +
alias less=$PAGER
 +
}}
 +
 
 +
Now programs that use the {{ic|PAGER}} environment variable, like [[git]], will use ''vim'' as pager.
 +
 
 +
== ls ==
 +
 
 +
[[Wikipedia:ls|ls]] (''list'') is a command to list files in Unix and Unix-like operating systems.
 +
 
 +
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 ''ls'' output; for example, broken (orphan) symlinks will start showing in a red hue. Add the following to your shell configuration file:
 +
{{hc|~/.bashrc|eval $(dircolors -b)}}
 +
 +
== man ==
 +
 +
[[Wikipedia:Man page|man]] (''manual page'') is a form of online software documentation usually found on a Unix or Unix-like operating system. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts. See [[Man Pages]].
 +
 +
== mkdir ==
 +
 +
[[Wikipedia:mkdir_(Unix)|mkdir]] (''make directory'') is a command to create directories. To create a directory and its whole hierarchy, {{ic|-p}} switch is used, if not a error is printed. As users are supposed to know what they want, {{ic|-p}} switch may be used as a default.
 +
alias mkdir='mkdir -p -v'
 +
The {{ic|-v}} switch make it verbose.
 +
{{Tip|If you want just a temporary directory a better alternative may be [[Wikipedia:Temporary file|mktemp]] (''make termporary''): {{ic|mktemp -p}}.
 +
}}
 +
 +
== mv ==
 +
 +
[[Wikipedia:mv_(Unix)|mv]] (''move'') is a command to move and rename files and directories. It can be very dangerous so it is prudent to limit its scope:
 +
alias mv=' timeout 8 mv -iv'
 +
This alias suspends ''mv'' after eight seconds, asks confirmation to delete three or more files, lists the operations in progress and does not store itself in the shell history file if the shell is configured to ignore space starting commands.
 +
 +
== rm ==
 +
 +
[[Wikipedia:rm_(Unix)|rm]] (''remove'') is a command to delete files and directories. It can be very dangerous so it is prudent to limit its scope:
 +
alias rm=' timeout 3 rm -Iv --one-file-system'
 +
This alias suspends ''rm'' after three seconds, asks confirmation to delete three or more files, lists the operations in progress, does not involve more than one file systems and does not store itself in the shell history file if the shell is configured to ignore space starting commands. Substitute {{ic|-I}} with {{ic|-i}} if you prefer to confirm even for one file.
 +
 +
== sed ==
 +
 +
[[Wikipedia:sed|sed]] (''stream editor'') is a Unix utility that parses and transforms text.
 +
 +
Here is a handy [http://sed.sourceforge.net/sed1line.txt list] of ''sed'' one-liners examples.
 +
 +
{{Tip|More powerful alternatives are [[Wikipedia:AWK|AWK]] and even [[Wikipedia:Perl|Perl]] language.}}
 +
 +
== seq ==
 +
 +
'''seq''' (''sequence'') is a utility for generating a sequence of numbers. Shell built-in alternatives are available, so it is good practice to use them as explained on [[Wikipedia:seq|Wikipedia]].
 +
 +
== shred ==
 +
 +
[[Wikipedia:Shred_(Unix)|shred]] is a command to securely delete files and directories. It can be very dangerous so it is prudent to limit its scope:
 +
alias shred=' timeout 3 shred -v'
 +
This alias suspends ''shred'' after three seconds, lists the operations in progress, and does not store itself in the shell history file if the shell is configured to ignore space starting commands.
 +
 +
== sudo ==
 +
 +
[[Wikipedia:Sudo|Sudo]] (''as superuser do'') is a program for Unix-like computer operating systems that allows users to run programs with the security privileges of another user (normally the superuser, or root). See [[Sudo]].
 +
 +
== See also ==
  
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:
+
* [http://www.reddit.com/r/commandline/comments/19garq/a_sampling_of_coreutils_120/ A sampling of coreutils] [http://www.reddit.com/r/commandline/comments/19ge6v/a_sampling_of_coreutils_2040/ , part 2] [http://www.reddit.com/r/commandline/comments/19j1w3/a_sampling_of_coreutils_4060/ , part 3] - Overview of commands in coreutils
eval $(dircolors -b)
+

Revision as of 13:34, 2 August 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki: improved Bourne shell, Linux standard Template:Article summary wiki: improved Bourne/C shell, very good as interactive shell Template:Article summary wiki Template:Article summary wiki Template: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 coreutils package. What follows are various tips and tricks and other helpful information related to these utilities.

cat

cat (catenate) is a standard Unix utility that concatenates and lists files.

  • As cat is not a shell built-in, in many occasions you may find more convenient to use a redirection, for example in scripts, or if you care a lot about performance. In fact < file does the same of cat file.
  • To append multiple lines to a file a construct like this one is used:
$ cat << EOF >> path/file
first line
...
last line
EOF
  • If you need to cat file lines in reverse order, there is a utility called tac (cat reversed).

grep

grep (from ed's g/re/p, global/regular expression/print) 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.

  • Remember that grep handles files, so a construct like $ cat file | grep pattern is replaceable with $ grep pattern file
  • If you have to grep VCS source code, there is an optimized utility written in Perl and called ack. See the official web site.

Colored output

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

To use the default colors for grep, write the following entry to your shell configuration file, e.g. if using Bash:

~/.bashrc
alias grep='grep --color=auto'

Alternatively, you can set the GREP_OPTIONS environment variable bearing in mind this may break some scripts that use grep [1]:

export GREP_OPTIONS='--color=auto'

To include file line numbers in the output, add -n:

alias grep='grep -n --color=auto'

The environment variable GREP_COLORS may be used to specify different colors than the defaults.

ip

ip allows you to show information about network devices, IP addresses, routing tables and other objects in the Linux IP software stack. By appending various commands, you can also manipulate or configure most of these objects.

Object Purpose manpage
ip addr protocol address management ip-address
ip addrlabel protocol address label management ip-addrlabel
ip l2tp tunnel ethernet over IP (L2TPv3) ip-l2tp
ip link network device configuration ip-link
ip maddr multicast addresses management ip-maddress
ip monitor watch for netlink messages ip-monitor
ip mroute multicast routing cache management ip-mroute
ip mrule rule in multicast routing policy db
ip neigh neighbour/arp tables management ip-neighbour
ip netns process network namespace management ip-netns
ip ntable neighbour table configuration ip-ntable
ip route routing table management ip-route
ip rule routing policy database management ip-rule
ip tcp_metrics management for TCP Metrics ip-tcp_metrics
ip tunnel tunnel configuration ip-tunnel
ip tuntap manage TUN/TAP devices
ip xfrm manage IPSec policies ip-xfrm

The help command is available for all objects. For example, typing ip addr help will show you the command syntax available for the address object.

The Network Configuration article shows how the ip command is used in practice for various common tasks.

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.

Colored output through environment variables

Add the following lines to your shell configuration file:

~/.bashrc
export LESS=-R
export LESS_TERMCAP_me=$(printf '\e[0m')
export LESS_TERMCAP_se=$(printf '\e[0m')
export LESS_TERMCAP_ue=$(printf '\e[0m')
export LESS_TERMCAP_mb=$(printf '\e[1;32m')
export LESS_TERMCAP_md=$(printf '\e[1;34m')
export LESS_TERMCAP_us=$(printf '\e[1;32m')
export LESS_TERMCAP_so=$(printf '\e[1;44;1m')

Change values as you like. References: ANSI escape code.

Colored output through wrappers

You can enable code syntax coloring in less. First, install source-highlight, then add these lines to your shell configuration file:

~/.bashrc
export LESSOPEN="| /usr/bin/source-highlight-esc.sh %s"
export LESS='-R '

Frequent users of the command line interface might want to install 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.

Vim as alternative pager

Vim (visual editor improved) has a script to view the content of text files, compressed files, binaries, directories. Add the following line to your shell configuration file to use it as a pager:

~/.bashrc
alias less='/usr/share/vim/vim73/macros/less.sh'

There is also an alternative to less.sh macro, which may work as the PAGER environment variable. Install vimpager-gitAUR and add the following to your shell configuration file:

~/.bashrc
export PAGER='vimpager'
alias less=$PAGER

Now programs that use the PAGER environment variable, like git, will use vim as pager.

ls

ls (list) 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 your shell configuration file:

~/.bashrc
eval $(dircolors -b)

man

man (manual page) is a form of online software documentation usually found on a Unix or Unix-like operating system. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts. See Man Pages.

mkdir

mkdir (make directory) is a command to create directories. To create a directory and its whole hierarchy, -p switch is used, if not a error is printed. As users are supposed to know what they want, -p switch may be used as a default.

alias mkdir='mkdir -p -v'

The -v switch make it verbose.

Tip: If you want just a temporary directory a better alternative may be mktemp (make termporary): mktemp -p.

mv

mv (move) is a command to move and rename files and directories. It can be very dangerous so it is prudent to limit its scope:

alias mv=' timeout 8 mv -iv'

This alias suspends mv after eight seconds, asks confirmation to delete three or more files, lists the operations in progress and does not store itself in the shell history file if the shell is configured to ignore space starting commands.

rm

rm (remove) is a command to delete files and directories. It can be very dangerous so it is prudent to limit its scope:

alias rm=' timeout 3 rm -Iv --one-file-system'

This alias suspends rm after three seconds, asks confirmation to delete three or more files, lists the operations in progress, does not involve more than one file systems and does not store itself in the shell history file if the shell is configured to ignore space starting commands. Substitute -I with -i if you prefer to confirm even for one file.

sed

sed (stream editor) is a Unix utility that parses and transforms text.

Here is a handy list of sed one-liners examples.

Tip: More powerful alternatives are AWK and even Perl language.

seq

seq (sequence) is a utility for generating a sequence of numbers. Shell built-in alternatives are available, so it is good practice to use them as explained on Wikipedia.

shred

shred is a command to securely delete files and directories. It can be very dangerous so it is prudent to limit its scope:

alias shred=' timeout 3 shred -v'

This alias suspends shred after three seconds, lists the operations in progress, and does not store itself in the shell history file if the shell is configured to ignore space starting commands.

sudo

Sudo (as superuser do) is a program for Unix-like computer operating systems that allows users to run programs with the security privileges of another user (normally the superuser, or root). See Sudo.

See also