Anda di halaman 1dari 36

GDB (GNU debugger),

chmod and PATH


Debug
 Mistakes by the programs are bugs
 Debug is a formal process to poke into the code
for investigation (semantic most of the time)
 No need to wobble around the entire code but
simply set the breakpoints/watch points
Jargon buster
 Breakpoints – way to stop the program at line
by line basis for investigation
 Watchpoints – program stops when a certain
variable changes its value
 gcc factorial.c -o factorial is to rename the
executeable to factorial instead of a.out
 gcc -g factorial.c -o factorial (to enable gdb)
 gdb works with executable file, not the text file
Example

Type q to quit
r run the program
Break 12 set breakpoint at line 12 (say)
Break +2 set breakpoint after 2 lines wrt current loc
watch x set watch for variable x (say)
info break List breakpoint numbers.
info locals shows local variables
info watchpoints List breakpoints
info registers shows register values
delete delete all breakpoints
n next line but not enter into the function
s next line while entering into the function
bt backtrace shows which function you are in
l list or show code
(if you hit enter) will pickup the previous command
p variable print the value of variable
p x=2 set the value of variable x = 2 let us say
make filename recompile the file without exit GDB prompt
k kill the debugger
q quit gdb
Need help? Type this...

help List gdb command topics.


help command Command description.
References
 https://www.youtube.com/watch?v=sCtY--xRUyI
 http://www.yolinux.com/TUTORIALS/GDB-
Commands.html
Linux File Permissions
•In Ubuntu / Linux everything is a file, so everything will
have permissions also.
•File permissions define which user or system accounts
have permissions to read, write, and execute specific
files.
•These read, write, and execute permissions are defined
for:
•User the user that owns the file
•Group users in the files group
•Other every other user
How Read, Write, And Execute Permissions Are Represented
•File permissions are identified through file mode bits. These bits
represent what actions can be carried out by specific user
accounts.

•For example, if you run the command ls -l to list the files in the
current directory, you'll see something similar to this at the
beginning of each line in the results:
-rwxrwxrwx

•The repeated rwx sequences represent the notion


of read (r), write (w), and execute (x) permissions
for user, group, and other (in that order).
File types
The possible file types you may see are depicted by
preceding the permissions by one of these:
- = Regular File
d = Directory
l = Symbolic Link
b = Block Special Device
c = Character Device
s = Unix Socket (local domain socket)
p = Named Pipe
Chmod – change mode of a file

Every file has 3 types of users and permissions:

Users: Owner, Group and Others (u,g,o)

Permission: Read Write Execute (RWX)


How to visualis: ls -l
Changing File Permissions - Chmod
The chmod command is used to change the various permission
bits of a file or directory.
The command takes the general form:
chmod MODE file
There are two ways to represent the MODE:
1. Using symbolic modes (letters to indicate the categories and
permission)
2. Using numeric modes (An octal (base 8) number that
represents the mode)
Using the "numeric modes" way of setting these permissions is
shorter than the symbolic method, but not as flexible because you
can't build on top of existing permissions which is possible
when using "symbolic modes".
Using Symbolic Modes With Chmod
Example
Using Numeric Modes With Chmod
Default values and umask
Umask example
1) chmod u+x hello.c
2)add Execute permission to the owner
of the file.
3) chmod g+x,o+x hello.c
4) chmod o-x hello.c
5)removing permission
6) chmod a+x hello.c
7)making changes for ALL
8) chmod - - reference=hello.c bye.c
 make permission for two files/dir the

same
PATH variable in LINUX
Environment variable
• An environment variable is a named object
that contains data used by one or more
applications.
• In simple terms, it is a variable with a name
and a value.
• The value of an environmental variable can for
example be the location of all executable files
in the file system, the default editor that
should be used, or the system locale settings
Contd..
• Environmental variables are a class of variables
that tell the shell how to behave as the user works
at the command line (i.e., in a text-only mode) or
with shell scripts (i.e., short programs written in a
shell programming language).
• A shell is a program that provides the traditional,
text-only user interface for Unix-like operating
systems; its primary function is to read commands
that are typed in at the command line and
then execute (i.e., run) them.
PATH
• PATH is an environmental variable in Linux and
other Unix-like operating systems that tells
the shell which directories to search for executable
files (i.e., ready-to-run programs) in response
to commands issued by a user.
• A user's PATH consists of a series of colon-separated
absolute paths that are stored in plain text files.
• Each user on a system can have a different PATH
variable.
• When an operating system is installed, one default
PATH variable is created for the root (i.e.,
administrative) account and another default is created
that will be applied to all ordinary user accounts as
they are added to the system
path
• path(in small letters) is a file's or directory's
address on a file system (i.e., the hierarchy of
directories and files that is used to
organize information stored on a computer).
• A relative path is an address relative to the current
directory (i.e., the directory in which a user is
currently working).
• An absolute path (also called a full path) is an
address relative to the root directory(i.e., the
directory at the very top of the filesystem and
which contains all other directories and files).
List all environmental variables
• A list of all the current environmental variables
and their values for the current user, including
all the directories in the PATH variable, can be
seen by running the env command
env
Display PATH
• As there can be considerable output, it can be
convenient to modify this command so that it
displays just the PATH environmental variable
and its value
env | grep PATH
• Another way to view the contents of just PATH
alone is by using the echo command with
$PATH as an argument:
echo $PATH
Changing PATH
• PATH variables can be changed easily.
• They can be changed just for the current login session,
or they can be changed permanently
• It is a simple matter to add a directory to a user's PATH
variable .It can be accomplished for the current
session by using the following command, in
which directory is the full path of the directory to be
entered:
PATH="directory:$PATH"
• For example, to add the directory /usr/sbin, the
following would be used:
PATH="/usr/sbin:$PATH"
export command
• An alternative is to employ
the export command, which is used to change
aspects of the environment. Thus, the above
absolute path could be added with the
following two commands in sequence
PATH=$PATH:/usr/sbin
export PATH
• or its single-line equivalent
export PATH=$PATH:/usr/sbin
Adding PATH permanently
• An addition to a user's PATH variable can be
made permanent by adding it to that
user's .bash_profile file. .bash_profile is
a hidden file in each user's home directory.
• Hiden files can be listed by: ls-a option
Run a program/script
• It is sometimes desired to run a script or program
which has been installed in a user's home directory or
some other location that is not in the user's default
search path.
• Such script or program can, of course, be run by typing
in its absolute path.
• But an often more convenient alternative when the
script or program is in the current directory is to
merely precede the command name with a dot slash.
• The dot is used in paths to represent the current
directory and the slash is used as a directory separator
and to separate directory names from file names
– E.g. ./a.out
PATH in windos
• Windows 7
• From the desktop, right click the Computer icon.
• Choose Properties from the context menu.
• Click the Advanced system settings link.
• Click Environment Variables. In the section System
Variables, find the PATH environment variable and select it.
Click Edit. If the PATH environment variable does not exist,
click New.
• In the Edit System Variable (or New System Variable)
window, specify the value of the PATH environment variable.
Click OK. Close all remaining windows by clicking OK.
• Reopen Command prompt window, and run your java code.
echo $PATH

ECHO means repeat, $ means repeat the


value of the variable PATH rather than its
name.
References
1)http://www.yourownlinux.com/2013/09/chmod-
basics-of-filesdirectories.html
2)http://www.linfo.org/path_env_var.html
3)http://www.tutonics.com/2012/12/linux-file-
permissions-chmod-umask.html

Anda mungkin juga menyukai