1. Computing & Technology

GNU/Linux Command-Line Tools Summary

From


   GNU/Linux Command-Line Tools Summary
   Prev    Chapter 7. Working with the file-system    Next

7.1. Moving around the filesystem

  • cd
  •    

    Change directory. Use " cd .." to go up one directory.

    One dot '.' represents the current directory while two dots '..' represent the parent directory.

    " cd -" will return you to the previous directory (a bit like an "undo").

    You can also use cd absolute path or cd relative path (see below):

    • Absolute paths
    •    

      An " absolute path" is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.


    For example to get to /boot/grub you would type:


       

    cd /boot/grub

    This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).

    • Relative paths
    •    

      A " relative path" doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.

      For example if you are in root's home directory and want to get to /root/music, you type:


         

      cd music


    Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.


  • ls
  •    

    List files and directories. Typing "ls" will list files and directories, but will not list hidden files or directories that start with a leading full stop ".".

    Example options:

    • ls -l --- long style, this lists permissions, file size, modification date, ownership.

    • ls -a --- this means "show all", this shows hidden files, by default any file or directory starting with a '.' will not be shown.

    • ls -d --- list directory entires rather than contents (see example below)

    • ls -F --- append symbols to particular files, such as * (asterisk) for executable files.

    • ls -S --- sort the output of the command in decending order sorted by size.

    • ls -R --- (recursive) to list everything in the directories below as well as the current directory.

    Command syntax, either:


       

    ls -options

    This simply lists everything in the current directory, the options are not required (options such as -l , -a et cetera).


       

    ls -options string

    This lists files using a certain string. The string can contain standard wildcards to list multiple files, to learn more about standard wildcards please read Section 20.4.1

    You can use ls -d to show directories that match an exact string, or use standard wildcards. Type " ls -d */" to list all subdirectories of the current directory. Depending on the setup of your aliases (see Chapter 4 ) you may simply be able to type lsd as the equivalent to ls -d */ .

    Examples for ls -d :


       

    ls -d
    */

    Lists all subdirectories of current directory.


       

    ls -d string*

    Lists directories that start with "string".


       

    ls -d /usr/*/*/doc

    Lists all directories that are two levels below the /usr/ directory

* License

* GNU/Linux Command-Line Tools Summary Index

©2012 About.com. All rights reserved.

A part of The New York Times Company.