HB Computer Security | Aide Memoire
  • Introduction
  • Core Technical Skills
    • Core Skills
      • Linux
        • Getting to Know Linux
          • Using the Shell
            • Shells, Terminals, and Virtual Consoles
            • Choose your Shell
            • Shell Commands
              • Non-PATH Commands
              • Command History
                • Command Line Editing
                  • Keystrokes for Navigating Command Lines
                  • Keystrokes for Editing Command Lines
                  • Keystrokes for Cutting and Pasting Text from within Command Lines
                • Command Line Recall
                  • Keystrokes for Command Line Recall
              • Connecting and Expanding Commands
                • Piping Between Commands
                • Sequential Commands
                • Expanding Commands
            • Shell Variables
              • Common Shell Variables
            • Aliases
            • Create your Own Shell Environment
              • Modification Ideas
          • Navigating the Linux File System (LFS)
            • Filesystem Commands
            • Listing Files and Directories
            • File Permissions and Ownership
              • Modifying Permissions with chmod
              • Modifying Default Permissions with umask
              • Change File Ownership with chown
            • Copying, Moving, and Removing Files
            • Finding Files
              • locate
              • find
              • grep
            • Downloading Files
              • axel
              • wget
              • curl
                • User-Agent: Googlebot
          • Working with Text Files
            • Using vim and vi to Edit Text Files
              • Starting with vi
              • Adding Text
              • Moving Around in the Text
            • Text Manipulation
        • System Administration
          • Installing Linux
            • Installing from Live Media
            • Installing in the Enterprise
            • Partitioning Hard Disks
              • Tips for Creating Partitions
          • Account Administration
            • The root Account
              • Becoming root with su
              • sudo
                • The /etc/sudoers File
                • Granting sudo privileges
                  • visudo Guidance
                • Useful sudo Hints
            • Other Administrative Accounts
            • Standard User Accounts
              • Risks of userdel: Orphaned Files
          • Graphical Remote Administration
            • Cockpit
              • Installation Guide
            • Remote Desktop Protocol with xrdp
              • Installation and Configuration
            • Remote Desktop with vnc
              • Installation and Configuration
              • Running VNC as a System Service
          • Managing Running Processes
            • Listing Processes
              • ps
              • top
              • htop
            • Backgrounding and Foregrounding
              • Starting a Background Process
              • Using Foreground and Background Commands
            • Killing and Recining Processes
              • kill and killall
          • Managing Software
            • Managing Software from the Desktop
            • Going Beyond the Limitations of Software Center
              • Debian Packages
                • Advanced Package Tool (apt)
                • Repositories
                • dpkg
        • Shell Scripting
          • Variables
            • Command Substitution
            • Arguments
          • Reading User Input
          • if, else, and elif
          • BOOLEAN Logic
          • Loops
            • for Loops
            • while Loops
          • Functions
          • Local Vs Global Variables
          • Summary
        • Securing Linux
      • Windows
        • Security Hardening
Powered by GitBook
On this page
  • List Example

Was this helpful?

  1. Core Technical Skills
  2. Core Skills
  3. Linux
  4. Getting to Know Linux
  5. Navigating the Linux File System (LFS)

Listing Files and Directories

PreviousFilesystem CommandsNextFile Permissions and Ownership

Last updated 1 year ago

Was this helpful?

The ls command is like your trusty torch in the maze-like filesystem – it lights up the contents of wherever you're standing. With it, you can look at, or "list" all the files and folders around you. ls has a bunch of options you can use to get a more detailed or different view.

Now, by just typing ls and pressing enter, you'll see a list of all the non-secretive items in your current location, otherwise known as the current working directory. However, some versions of Linux ( and , for instance) like to be a bit clever. They've given ls a few additional settings right out of the box. To find out if your system has done something similar, you can try out the following command:

alias ls

List Example

Lets return to our $HOME directory, create a new directory called test, add a couple of different types of files, and then see what they look like with the ls command:

cd $HOME
mkdir test; cd test
touch scriptx.sh apple
chmod 755 scriptx.sh
mkdir Stuff
ln -s apple pointer_to_apple
ls

Don't worry about the commands above for the moment as I'll cover them more comprehensively later - for now, just know that some new files were created and some permissions were set.

With the default ls alias in place, we can see that the directory Stuff shows up in blue, pointer_to_apple (a symbolic link, or "shortcut") appears as aqua, and scriptx.sh (which is an executable file) appears in green. All other regular files show up in white.

Typing ls -l to see a long listing of those files can make these different types of files clearer still:

ls -l

Examining the long listing above, you will notice that the first character of each line shows the type of file:

  • - : indicates a regular file

  • d: indicates a directory

  • l: indicates a symbolic link

An executable file (a script or binary file that runs as a command) has execute bits turned on, x - more on this shortly...

The ls command lets you peek at hidden files too; those that start with a dot . By using the -a option, you can unveil these hidden treasures. If you take a look at a typical user's home directory, you'll spot a bunch of these dot-prefixed files and directories, including the .bashrc file that we were looking at earlier on:

Note at the top of the output that the . and .. directories are listen when -a is used.

A single . means this directory. So, if you want to use a relative PATH to execute a binary that is in the current working directory, and importantly, NOT in the PATH, you preface the executables name with ./

The double .. means Parent Directory. So, you you were to execute the command cd .. , you would change your working directory to the parent directory of where you currently are.

Fedora
RHEL
The --color=auto option causes different types of files and directories to be displayed in different colours.
Example of ls with different file types
An example of a "long listing"
A long listing that also shows "hidden" files and directories