Whenever you right-click and choose to open a folder or simply double-click, or select the folder and press “Enter” on your keyboard, you are changing your current working directory/folder to that new folder you are selecting.
Either you are on Desktop, Trash, My Computer, Downloads, Pictures, or Documents, you are inside a directory. These are just a graphical way to present what is happening behind the scenes (the white-on-black screen).
To be honest, it is pleasing and easier to navigate on my laptop without worrying about the hundreds and thousands of commands I must use to accomplish the same simple task. At least, these were my thoughts before I started discovering more Linux commands and evaluating how handy, fast, flexible, and convenient for me, especially as a cybersecurity student.
My advice is “if you are a Computer Science/Engineering student you should, at the best of your abilities, learn the Linux CLI commands.” I know they might not seem attractive and convenient at first, but trust me the more you use them, the easier they will become.
Before we start, I assume you already have a linux distribution like Ubuntu, Kali Linux, Parrot Security or you are using a MAC OS. If you are using Windows cmd or PowerShell, some of the commands may not be the same.
So let’s start with the basics:
- “pwd” Command
“pwd” stands for “Print your Working Directory.” As you may have already understood it, pwd prints or outputs at the next line of your CLI the path to your current working directory.
/home/kali means we are in the directory called “kali” which itself is in the parent directory called “home”.
Now that we know in which directory we are (“kali”), we want to see all the files and sub-directories that are in our working directory. This is when the “ls” command comes into play.
- “ls” Command
ls stands for “list” and is quite an interesting command. It lists all the content(directories and files) of your current directory. Let’s explore the flags we can use with the ls command.
ls: lists the contents of the current or working directory (“kali”)
ls Desktop: lists the content of the directory “Desktop”
ls -a: list all files including hidden files like the ones starting with a dot “.”
ls -l: lists all files and directories with a lot more information about them.
We will cover more on what you see in a future project. For now, let’s take a look at the first char
d → stands for directory
– → stands for file
l → stands for line
Following are 9 characters composed of letters ‘r’ → read, ‘w’ → write , ‘x’ → execute.
Eg. for the directory “Desktop
owner | Group | rest of the world
d | r w x | r – x | r – x
owner: the user that creates and owns this directory.
r → means the user can read the content of the directory. It is their permission or privilege
w → means the user has the privilege to write/delete/edit/make changes in the directory
x → means the user has the privilege to execute/run the directory or program.
group: every linux account belongs to a group/groups that gives them certain privileges on programs in the system.
rest of the world: is anyone that is not part of the groups.
Also, you can see the size of the directory/file in bytes, the last date or time it was modified, and the name of the directory/file.
ls -R: this flag will list all directories’ and subdirectories’ content.
ls -t: lists the content of the directory by order of time. The most recent edited element is the first element in the list. ls -tv does the opposite.
ls -1: lists the content of the directory 1 element by line
Now that we know where we are working (pwd) and how to see/list the directory content, we want to be able to navigate and jump around our system. This is when the cd command comes into play.
cd stands for Change Directory.
cd directory_name: takes you into the directory directory_name.
cd ..: In every directory of linux system, a hidden directory “..” gets created that points to the previous directory. So, using the command cd .. takes you to the parent directory.
One reply on “Linux Commands: pwd, ls, cd”
rbt_inbio October 27, 2021 at 3:34 pm
Nulla non ligula vel nisi blandit egestas vel eget leo. Praesent fringilla dapibus dignissim. Pellentesque quis quam enim. Vestibulum ultrices, leo id suscipit efficitur, odio lorem rhoncus dolor, a facilisis neque mi ut ex. Quisque tempor urna a nisi pretium, a pretium massa tristique. Nullam in aliquam diam. Maecenas at nibh gravida, ornare eros non, commodo ligula. Sed efficitur sollicitudin auctor. Quisque nec imperdiet purus, in ornare odio. Quisque odio felis, vestibulum et.