Chip Designer S Code Linux CLI Part 1 1741015219
Chip Designer S Code Linux CLI Part 1 1741015219
LINUX
Command Line
TCL PYTHON REGEX
&
Scripting
/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”
/amradelm
/amradelm 4
The Terminal
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
/amradelm
[1] In Linux, hidden files are files starting with a dot (.) (e.g. .my_hidden_file) /amradelm 12
ls Long Format Information
/amradelm
/amradelm 13
Options vs Arguments
/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)
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
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
/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
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
/amradelm
/amradelm 22
pushd - popd - dirs
/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]
[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