Etc : Bash - whoami, pwd, ls

Below is Mate's Terminal running a BASH shell, the most common Linux CLI. An Initialising Script has set the Command Prompt to consist of the users name bryan then @ then the Computers name Debian10, then a colon : and finally the location, currently its ~ tilde this stands for your Home Directory, this will change as you bop from Directory(Folder) to Directory .

so it's bryan@Debian10:~ with the location being /home/bryan.

In case your command prompt is not set up to display as below and you have actually forgotten your name, type in whoami, all lowercase and hit the Enter Key to reconnect to yourself.

Who are you and where are you??
If Bash is to bare for you try Fish which has many more features: Autosuggestion -suggests commands as you type based on history and completions, syntax highlighting, Web Based Configuration etc. Fish is fully scriptable, its syntax is simple, clean and consistent.

There is no whereami command, so type in pwd which stands for Print Working Directory and hit Enter to find out where you are, this will give you the full path to your current directory, yes this is home aka ~.

Using the Bash Terminal I am going to explore the contents of my home directory and show how Linux views files and directories...

Filenames use a forward slash to separate directories, the same as web site addresses, rather than a backslash that you see in Windows filenames. Another major difference with Windows is that filenames are CaSe-Sensitive, that is /home/supertux/hello.txt and /home/supertux/Hello.txt are two different files in supertux's home directory.

Also there is no C:\ as the root directory just / which is root, this may seem strange but makes for a very flexible file system, for instance the /home directory containing all the users files (similar to the Windows C:\Users folder) could and often is on a separate partition on the hard drive or even on a separate hard drive or in the "cloud" and the normal user would not know or even care.

Now to turn the lights on and see what's there, type in the ls command which is short for light switch kidding its short for list as in list the files Enter.

ls to List files in a directory

The ls command above is set to use colour thanks to that initialising file, directories are blue and image files are pink, very tasteful, otherwise it would be hard to distinguish directories from files.

ls on its own lacks detail so time to use some options, these start with a "-" for single letter options or "--" for options that are words. The one that everyone learns first is ls -l, l is for long list, as in more details and for extra polish add a h for human to display the file sizes in KB, MB and GB rather than Bytes.

So type in ls -lh make sure to leave a space between ls and -lh

Files and folders are by default arranged in alphabetical order, this time there is a line for each item with info arranged in columns.

ls -lh: lists all the file details, file sizes in KB, MB and GB rather that bytes

The very first column is most important, the first character tells what the item is:

- is a file and

d is a directory.

The next six characters deal with File Permissions: who can Read or Write to a File or Directory and who can eXecute a File or look at the contents of a Directory.

There are three sets of these

  1. The Owner of the file in this case bryan
  2. The Group again bryan
  3. Others everybody else

More fun with that later!!!

The Second Column deals with the number of links that each file has, normally its 1, for a directory its 2 plus the number of its sub-directories (if they exist), yet more fun later taking about soft links and hard links, yippee.

The third and forth column states who owns the file, bryan and which Group owns the file bryan.

In most Linux Distros when you add new users to a PC a group with the users name is also created.

It gets easier from column six onwards

There are many options to ls and you can see them using the command man ls (man is short for manual).

All you need is man short for manual as in RTFM

This opens in less a brill utility that you use to go through/search .. less is more and less has many options hit h to see and Esc to go back to the man page.

TMI all you need to know for now is how to navigate these man pages is..

With Man Pages the options are arranged in alphabetical order rather that in order of most useful so I just note a few below that I find useful.

In Linux files starting with a . are hidden, they tend to be configuration files that you only need to edit occasionally so best to hide them.
ls -la: lists all the files, including hidden files and their details
The first two entries are . which stands for this directory /home/bryan and .. which is the parent directory /home.
so ls -ld will give the details of the current directory same as . on the first entry and ls -ld /home will give the same info as the .. entry.
ls -d: just list the Directory Details