0% found this document useful (0 votes)
50 views29 pages

Chip Designer S Code Linux CLI Part 1 1741015219

This document provides an introduction to navigating the Linux operating system, focusing on command line usage and essential commands like pwd, ls, cd, and tree. It explains directory structure, the difference between absolute and relative paths, and how to use directory stack commands such as pushd and popd. Additionally, it covers the xdg-open command for switching to GUI applications from the command line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views29 pages

Chip Designer S Code Linux CLI Part 1 1741015219

This document provides an introduction to navigating the Linux operating system, focusing on command line usage and essential commands like pwd, ls, cd, and tree. It explains directory structure, the difference between absolute and relative paths, and how to use directory stack commands such as pushd and popd. Additionally, it covers the xdg-open command for switching to GUI applications from the command line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Chip Designer’s Code

Automation and Programming in VLSI


Chapter 2 : Linux – Part 1 : Navigation

LINUX
Command Line
TCL PYTHON REGEX
&
Scripting

Amr Adel Mohammady


VCS /amradelm

/amradelm
MAKEFILE
Introduction

• In this part, we will start our journey with Linux by learning how to move around directories and view their contents.
• Commands Covered
o pwd : Print current working directory
o ls : List contents of a directory
o tree : List contents of a directory in a tree-like format
o cd : Change the current directory
o pushd , popd, dirs : Handle Linux directory stack.
o xdg-open : Open GUI

/amradelm

/amradelm 2
Opening The Terminal

/amradelm

/amradelm 3
The Terminal
• The terminal, also known as the command-line interface (CLI), is a text-based way to
interact with the Linux operating system.
• Unlike graphical user interfaces (GUIs), you type commands instead of clicking icons.
• There are several ways to open the Terminal.
1. Keyboard Shortcut : Press Ctrl + Alt + T
2. Application Menu : Click on Application -> System Tools -> Terminal
3. Right Click Context Menu : Right-Click on your mouse then select “Open Terminal”

(2) Application Menu

(3) Right Click Context Menu

/amradelm

/amradelm 4
The Terminal

• You should have a window similar to this.


• Colors may be different depending on your default settings.

The Terminal

/amradelm

/amradelm 5
Linux Command Format

• Before we start learning the different commands in Linux we need to learn some
notations.
• Commands in Linux follow this general format:
command_name [options] arguments
o Arguments : Provide input or targets for the command to act on.
o Options : Also called flags or switches. They are modifiers added to a command
to alter its behavior. They allow you to customize how a command works. They
start with a hyphen -
o Example : the command “cat [options] [arguments]” prints the contents cat without options
of a file
• It takes as an argument the file you want to print.
• It can take options such as “-n” to print line numbers
o The brackets “[ ]” around the word options indicate they are optional, meaning
you can omit them.
o Some commands also don’t require an argument to work. In that case the
command will be shown as :
command_name [options] [arguments]
cat with -n option

/amradelm

/amradelm 6
Navigation

/amradelm

/amradelm 7
Navigation

• Navigation means to move around the Linux directories, open them and see the contents inside.
• Directory Structure:
• Linux organizes files in a hierarchical tree starting from the root directory (/).
• The root directory is the main jumbo directory that includes all the Linux files and directories under it. Think of it as the “C:\” in
Windows
• We will discuss the Linux directory structure in detail in the next part.

/amradelm

/amradelm 8
pwd

/amradelm

/amradelm 9
Current Working Directory

• Current Working Directory: Is your "location" in the filesystem at any given time. In GUI, it’s the current opened folder/directory in the
window.
• We have several ways to know the current working directory :
• The Prompt: it shows the current working directory and other info such as the username and the hostname1.
• The tilda “~” symbol refers to the home directory /home/username. It’s similar to the Desktop directory in Windows.
• pwd : A command that prints the current working directory.

Current Directory
username hostname

pwd
Symbol to the home directory

The Prompt

/amradelm

[1] We will later learn how to customize the prompt to include the info we desire. /amradelm 10
ls

/amradelm

/amradelm 11
ls Human-readable Sizes

• We know where we are. Now we need to know where


we can go. To do that we will use the ls command.
• Usage : ls [options] [arguments]
o The ls command is used to list directory contents
(files and directories).
o Usually, directories and files are printed in ls (no options) ls –lh (long format + human readable)
different colors to distinguish between both.
• ls options: Hidden Files
o -l : Print content in long format showing more
details for each content
o -t : Sort by modification time (newest first).
o -r : Reverse the sorting order (e.g., oldest first with
-tr).
o -h : Print the sizes in human-readable format ls –l (long format)
(used with –l)
o -a : Show hidden files1
o -1 : Print contents one per line. ls –la (long format + hidden files)

/amradelm

[1] In Linux, hidden files are files starting with a dot (.) (e.g. .my_hidden_file) /amradelm 12
ls Long Format Information

Owner : The user who owns the


file or directory.
User Permissions : Shows who can: r (read)
w (write/edit) x (execute) the file. Group : The group (collection of users e.g. IT team)
Will be discussed in details later who owns the file or directory.

Type : d (directory) or – (file)

Size in Bytes : In case of directories, it shows the size


Last Modification Time
of the meta-data about files contained in that directory

/amradelm

/amradelm 13
Options vs Arguments

• So far we haven’t given ls an argument we only gave it options.


• When you don’t give ls an argument it lists the contents of the current working directory by default.
• You can give ls a path to a directory to list the contents of that directory
• You can give ls a path to a file. This is useful when combined with –l option to print detailed info about that file.

ls With Directory As An Argument

ls With File As An Argument

/amradelm

/amradelm 14
Absolute Path vs Relative Path

• Since we gave ls a path, it’s important to know the different types of paths:
• Absolute path:
o The path to a file or directory starting from the root directory “/”
o Example : /home/amr_adel/report.txt
• Relative path:
o The path to a file or directory starting from the current directory.
o Example : ./amr_adel/report.txt (Assuming the current working directory is /home)

Absolute Path Relative Path

Starting Point Root (/) Current directory (.)

Depends on current
Portability Works from anywhere
directory
Shorter (context-
Length Longer (explicit)
dependent)

/amradelm

[1] The symbol of the root directory is “/” while the symbol of the current directory is “.” (dot) /amradelm 15
tree

/amradelm

/amradelm 16
tree

• Tree prints the contents of a directory in a tree like format.


• It also shows the directory recursively (sub directories)1
• Usage : tree [options] [arguments]
• Options:
o -p : Print user permissions
o -t : Sort by modification time (newest first).
o -r : Reverse the sorting order (e.g., oldest first with -tr). tree -p

o -a : Show hidden files


o -d : Show directories only tree (no options)

o -L <N> : Limit the output to N levels.


Level 0

Level 1

Level 2
tree –L 2

/amradelm

[1] You can do the same with ls using –R option but it’s not readable compared to tree /amradelm 17
tree

• Options:
o -f : print paths relative to the current working dir
• Like ls you can give tree a relative or absolute path
• When no path is given, tree lists the contents of the
current working dir

tree (no options) tree -f

/amradelm

/amradelm 18
cd

/amradelm

/amradelm 19
Options vs Arguments

• We now know where we are and where we can go. Now it’s time to start moving.
• cd stands for change directory; from its name, it’s used to change the current working directory.
• Usage : cd [argument]
o The argument can be an absolute or relative path.
o cd : If you don’t provide a path, it goes to the home directory by default. cd == cd ~ == cd /home/amr_adel
o cd / : Go to the root directory
o You can go several directories down relative to the current dir: cd ./amr_adel/Documents
o cd ../ : Go to the parent directory (one dir up)
o cd ../../ : Go to the parent of the parent directory (two dirs up) cd Several Directories Down

o cd - : Switch back to the previous (not parent) directory


▪ Example: Suppose you are in /home/amr_adel/Documents and move to /var/log:
▪ If you type cd – you will return to /home/amr_adel/Documents. If you type cd – again you will return to /var/log
▪ This allow you to navigate back without needing to remember or type the full path.

cd -

/amradelm

/amradelm 20
Directory Stack
pushd, popd, dirs.

/amradelm

/amradelm 21
Stack : Last-In First-Out
• cd - switches only between the last two directories.
• It would be nice if we could leverage this feature into a more powerful
command(s).
• Directory stack commands “pushd, popd, dirs” allow you to jump back and
forth between different directories without typing the full paths.
• Let’s first learn what a stack is:
o It’s a linear data structure that follows the LIFO (Last-In, First-Out) principle.
o The last item added is the first one removed. Stack Operation

o Example : The image shows a stack operation


▪ The action to insert an item is called Push. It places the pushed item on
the top of the stack
▪ We push A, B, then C.
▪ The action to take an item from the stack is called pop. The popped item is
the top item in the stack
▪ Since C is the top item (last-in). It is the item that will get popped (first
out).

/amradelm

/amradelm 22
pushd - popd - dirs

• The Linux directory stack works in the same manner:


o pushd <dir>: "Push" the current working directory onto the stack and then cd <dir>1.
o popd: "Pop" the top directory from the stack and cd into it.
o dirs: Display the current contents of the directory stack.
o The cd command doesn’t affect the content of the stack.

Linux Directory Stack Operation

/amradelm

[1] Notice that the directory that gets pushed is the current working directory, not the <dir> arguments /amradelm 23
pushd - popd - dirs
• I found the best usage of the directory stack is to use it as a memory like this:
1. At the beginning of your work day push the different directories you are likely to cycle through during your work:
▪ push –n <path_to_project>1
▪ push –n <path_to_scratch_area>
[1]
▪ push –n <path_to_coworker_area> .. Etc
2. Whenever you want to go to a directory inside the stack:
o dirs -v : to print the directory stack2
o Copy the desired directory
3. cd <paste> [2]

[3]

Stack Operation (-n option)

[1] pushd –n option makes you store <path> in the directory stack instead of cd into it. The current working directory stays unchanged.
/amradelm

/amradelm 24
[2] dirs –v option prints the stack contents one per line which is easier to read.
xdg-open

/amradelm

/amradelm 25
xdg-open

• If at any point you want to switch from the CLI to the GUI you can use the command xdg-open
• Usage : xdg-open argument
• xdg-open /path/to/directory : This command will open the specified directory in the default GUI file explorer
• xdg-open . : Open the current working directory in the GUI explorer
• xdg-open /path/to/file : This command will open the specified file with the default application associated with its file type. For
example, a PDF file will open in the default PDF viewer, and a text file will open in the default text editor.
• xdg-open www.example.com : This command will open the specified URL in the default web browser.
• You can give the command multiple arguments to open them at once.

/amradelm

/amradelm 26
Conclusion
/amradelm

/amradelm 27
Conclusion

• We learned how to navigate Linux and learned the main commands used.
• We also learned the difference between a command option and an argument
• We also learned the difference between relative and absolute paths
• In the next part we will discuss the Linux directory structure and how it relates to EDA tools.

/amradelm

/amradelm 28
Thank You!

/amradelm

/amradelm 29

You might also like