Posted: . At: 11:13 AM. This was 5 years ago. Post ID: 13629
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


It is very useful to have knowledge of the command line. Here are some useful tips for you.


A nice Linux workstation.
A nice Linux workstation.

If you need to perform a command a second time on a different file, you can use command replacement with the ^ symbol. e.g. cp foo.txt /to/some/directory then ^foo^bar, expanding to: cp bar.txt /to/some/directory.

To find information about a particular command, the apropos utility can be very helpful, this will search the system and find any matching manual pages for a certain command.

Here is an example.

┌─[][jason@darkstar][~]
└──╼ $apropos fdisk
cfdisk (8)           - display or manipulate a disk partition table
fdisk (8)            - manipulate disk partition table
sfdisk (8)           - display or manipulate a disk partition table

Use the help command to get information about a bash scripting command. This can really help out if you are stuck on a scripting issue and need help.

┌─[jason@darkstar][~]
└──╼ $help echo
echo: echo [-neE] [arg ...]
    Write arguments to the standard output.
 
    Display the ARGs, separated by a single space character and followed by a
    newline, on the standard output.
 
    Options:
      -n        do not append a newline
      -e        enable interpretation of the following backslash escapes
      -E        explicitly suppress interpretation of backslash escapes
 
    `echo' interprets the following backslash-escaped characters:
      \a        alert (bell)
      \b        backspace
      \c        suppress further output
      \e        escape character
      \E        escape character
      \f        form feed
      \n        new line
      \r        carriage return
      \t        horizontal tab
      \v        vertical tab
      \[tab]backslash
      \0nnn     the character whose ASCII code is NNN (octal).  NNN can be
        0 to 3 octal digits
      \xHH      the eight-bit character whose value is HH (hexadecimal).  HH
        can be one or two hex digits
 
    Exit Status:
    Returns success unless a write error occurs.

Use it like this to get more verbose help output.

┌─[jason@darkstar][~]
└──╼ $help -m echo

Print only a short usage synopsis for each command.

┌─[jason@darkstar][~]
└──╼ $help -s echo
echo: echo [-neE] [arg ...]

Another way to get information about a certain Linux command. The whatis command returns a short description of a Linux command you are curious about.

┌─[][jason@darkstar][~]
└──╼ $whatis ls
ls (1)               - list directory contents

The free command tells you the status of your memory and swap, how much you have used and how much you have left.

To make a backup without typing the full path twice: cp /long/path/to/file/name{,.orig} to create a copy with the suffix .orig.

Use lsof to find out which process has open handles for a file. ‘lsof +D /path’ will find all processes for the given path. This is useful for unmounting media.

Edit the command line with cut and paste: ctrl-k for cut, and ctrl-y for paste.

To manage Apache modules use “a2enmod” to enable and “a2dismod” to disable.

e.g. sudo a2enmod rewrite


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.