TL;DR
pwd
: What is your terminal’s current directory?ls [-l] [-a] [path]
: List Files in [path]cd [path]
: Change Directory to [path]man [command]
: View command documentation in an interactive reader, up and down arrow to scroll. Q to exit./home/kali/folder1/folder2
: Absolute File Path; this will never change.~/folder1/folder2
: Absolute File Path, relative to home directory. This shouldn’t change unless your home directory changes.folder1/folder2/
: Relative File Path, this depends on which folder you are in (seepwd
).
- TL;DR
- What the Shell?
- Flags and Switches, Tacks and Dashes
- Moving around
- Print Working Directory
- List Files
- Change Directory
- Getting Help
- The Linux Manual
- Explainshell.com
- Google
What the Shell?
Your window into the world of the Linux operating system originals from the shell in which you enter commands and read output from different commands ran. There are many different shells out there on different operating systems, below are some examples:
- Bourne Shell, or
sh
or/bin/sh
: One of the OG shells inherited from UNIX, the source material for Linux. It isn’t really used often for entering commands, but works great as a scripting language, and you’ll still find them today with scripts ending in.sh
. - Bourne-again Shell, or
bash
or/bin/bash
: Created to replacesh
, bash is a robust shell with many improvements to the original, with tab completion, history, customization, aliases, variables, and jobs. This is the default shell on most Linux Distributions. - Z-Shell or
zsh
or/bin/zsh
: The shiny new kid (1990) on the block, based onsh
, offers more improvements to customization, tab completion and history along with taking quality-of-life features from other shells likebash
,ksh
, andtcsh
. There is also a community behindzsh
called “oh my zsh” (linked below) which offers installation and configuration scripts for managing yourzsh
shell. Z-Shell is the default shell for your Kali Linux.
Flags and Switches, Tacks and Dashes
Before we start getting into commands, you need to understand Flags, Switches, Tacks, and Dashes. They all are different ways of saying the same thing, so I’ll call it flags for the rest of this tutorial but do keep in mind that they are the same thing, most people use them interchangeably, They are ways of telling the computer to modify how a command is done.
Take, for example, the “list files” command, ls
. By itself, it just lists all your folders and files with spaces in between (example pulled from here).
Okay, that’s great, but can’t we get more information? We can, by telling ls to give us more through flags. If you add the -l
flag (”tack-el”) to the end, we tell ls
to list it in LONG format with more information.
Don’t worry about what each of the columns mean, you’ll learn about that lower on this page and in the next section going over permissions, just remember that flags change how the command runs and/or outputs data, and may possibly require you to specify what you want to change it to, “arguments”.
Moving around
Print Working Directory
This shows you what your current directory of your terminal is. Running processes also have “working directories”. It has no flags.
pwd
/tmp/example
List Files
This shows you what’s in the current directory. With no flags, it just lists files and folders in your current directory.
ls
dir1 dir2 file1 file2
Syntax:
ls [OPTIONS] [FILES]
Common Flags:
-l LONG listing format
-a do not ignore hidden files.
-h print sizes in human readable format
Long listing format:
ls -l
total 8
drwxr-xr-x 2 kali kali 4096 Aug 25 16:43 dir1
drwxr-xr-x 2 kali kali 4096 Aug 25 16:43 dir2
-rw-r--r-- 1 kali kali 0 Aug 25 16:43 file1
-rw-r--r-- 1 kali kali 0 Aug 25 16:43 file2
Long listing format & do not ignore .hidden files:
Column | Example | Description |
1st | drwxr-xr-x | Permission Triplets for the file/folder, If it starts with “d”, it is a folder. Read more about this in our Filesystem Permissions Guide. |
2nd | 2 | Number of “Hard Links” to a file/folder. Files have 1 “hard-link” to their parent folder, Folders have 2 or more “hard-links” to their parent folder and any children folders/files. |
3rd and 4th | kali kali | The user and group owner of the file/folder. Read more about this in our Filesystem Permissions Guide. |
5th | 4096 | The size (on disk) of the file/folder in bytes. UNIX folders are always 4096 because that’s the minimum block size for Ext4 (the filesystem), to keep from possible corruption with variable-sized folders with different amounts of metadata. Empty files are 0 bytes. |
6th | Aug 25 16:43 | Datetime this folder/file was last modified |
7th | dir1 | Name of the folder/file |
ls -la
total 20
drwxr-xr-x 5 kali kali 4096 Aug 25 16:44 .
drwxrwxrwt 19 root root 4096 Aug 25 16:43 ..
drwxr-xr-x 2 kali kali 4096 Aug 25 16:43 dir1
drwxr-xr-x 2 kali kali 4096 Aug 25 16:43 dir2
-rw-r--r-- 1 kali kali 0 Aug 25 16:43 file1
-rw-r--r-- 1 kali kali 0 Aug 25 16:43 file2
drwxr-xr-x 2 kali kali 4096 Aug 25 16:43 .hiddendir
-rw-r--r-- 1 kali kali 0 Aug 25 16:43 .hiddenfile
You can also run ls <path>
on directories outside of your current one.
ls -l dir1
total 0
-rw-r--r-- 1 kali kali 0 Aug 25 19:44 file3
-rw-r--r-- 1 kali kali 0 Aug 25 19:44 file4
Change Directory
Change the current working directory. With no flags, this goes to your home directory “~” or “/home/kali”.
Syntax:
cd [DIRECTORY]
Examples:
#######################
# Relative File Paths #
#######################
# This changes our directory to "/home/kali/dir1", if it exists.
#
# NOTE: This is talking about the "dir1" folder in a *relative-context*. This means that we need to be in the "/home/kali" for this command to work.
cd dir1
# This changes our directory to whatever the PARENT directory is (See File Structure Lesson)
#
# NOTE: Like the previous example, we're referring to the parent directory relative-ly. This means that we should change to "/home" if we run this inside "/home/kali".
cd ..
#######################
# Absolute File Paths #
#######################
# This changes our directory to "/home/kali/dir1", if it exists.
#
# NOTE: Unlike in previous examples, we can run this command *anywhere* and it'll still mean the same thing. Useful for referencing common files that don't change location like "/etc/hostname"
cd /home/kali/dir1
# Go to the "/etc" folder
cd /etc/
# This even works with our ".." notation, although it isn't really useful. This takes us to "/home/kali".
cd /home/kali/dir1/../
# ~ is shorthand for the home directory of the currently logged-in user (/home/kali). You can use this to reference files and folders from anywhere in the computer aswell.
cd ~/dir1
If you are paying attention, you may notice after running ls -a, that those “.
” and “..
” files appear also inside the folders they are in. This is no accident. “..
” will always exist inside any given folder, and it references the “parent” folder “above” the current folder always. “.
” points to the current folder always, and is useful for clarity’s sake sometimes.
# Start at /home/kali
pwd
/home/kali
# This first points to the current directory, then the parent, then "/home/kali/dir1", then pack to that folder's parent, "/home/kali" (which is where we started).
cd ./../kali/dir1/../
Getting Help
The Linux Manual
All of the common Linux commands come with a built in manual accessible with the man
command.
# This opens a manual in your terminal that you can scroll through with UP and DOWN
# arrowkeys. Press SPACE to move down one full text page, and ENTER to move down only
# one line. Press Q to exit.
man [COMMAND]
- NAME: Briefly describes the command and its purpose.
- SYNOPSIS: Shows the command syntax with various options and arguments.
- DESCRIPTION: Provides detailed information about the command's functionality, usage, and behavior.
- OPTIONS: Lists the available flags, switches, and parameters that can be used with the command.
- EXAMPLES: Offers practical usage examples to illustrate how to use the command.
- SEE ALSO: Provides references to related commands, functions, or man pages that might be relevant.
Explainshell.com
If you’re ever in a pickle with understanding a complicating shell command, paste it into this website and it will attempt to explain to you what each part of it does.
You can Google most of your problems away. Chances are 90% of the time if you’re struggling in understanding how a command works the answer is already on the internet.