0% found this document useful (0 votes)
103 views

Starting, Exiting, Reading and Writing Files in Emacs

Uploaded by

vrchand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Starting, Exiting, Reading and Writing Files in Emacs

Uploaded by

vrchand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Here are some of the most important commands that are used in emacs.

Starting, Exiting, Reading and Writing Files in emacs


Command Description

emacs myfile Start emacs and edit myfile

Ctl-x i Insert prompted for file at current position

Ctl-x s Write out the file keeping current name

Ctl-x Ctl-w Write out the file giving a new name when prompted

Ctl-x Ctl-s Write out all files currently being worked on and exit

Ctl-x Ctl-c Exit after being prompted if there any unwritten modified files

Changing Position in emacs


Command Description

arrow keys Use the arrow keys for up, down, left and right; or:

Ctl-n One line down

Ctl-p One line up

Ctl-f One character left

Ctl-b One character right

Ctl-a Move to beginning of line

Ctl-e Move to end of line

M-f Move to beginning of next word

M-b Move back to beginning of preceding word


Command Description

M-< Move to beginning of file

M-x goto-line n Move to line n

M-> Move to end of file

Ctl-v or PageDown Move forward one page

M-v or PageUp Move backward one page

Ctl-l Refresh and center screen

Searching for Text in emacs


Command Description

Ctl-s Search forward for prompted for pattern, or for next pattern

Ctl-r Search backwards for prompted for pattern, or for next pattern

Changing, Adding and Deleting Text in emacs


Command Description

Ctl-o Insert a blank line

Ctl-d Delete character at current position

Ctl-k Delete the rest of the current line

Ctl-_ or Ctl-x u Undo the previous operation

Ctl-space Mark the beginning of the selected region; the end will be at the cursor position

Ctl-w Yank (cut) the current marked region and put it in buffer

Ctl-y Paste at the current position the yanked line or lines from the buffer
Command Description

A shell is a command line interpreter which can constitute the user interface for terminal windows. It can also be used
as a mechanism to run scripts, even in non-interactive sessions without a terminal window, as if the commands were
being typed in.

For example, typing:

$ find . -name "*.c" -ls

at the command line accomplishes the same thing as running the following script:

#!/bin/bash

find . -name "*.c" -ls

The #!/bin/bash at the beginning of the script should be familiar to anyone who has developed any kind of script in
UNIX environments. Following the magic #! characters goes the name of whatever scripting language interpreter is
tasked with executing the following lines. Choices
include /usr/bin/perl, /bin/bash, /bin/csh, /usr/bin/python and /bin/sh.

Linux provides a wide choice of shells; exactly what is available to use is listed in /etc/shells; e.g. on one system we
get:
1

$ cat /etc/shells

/bin/sh

/bin/bash

/sbin/nologin

/bin/tcsh

/bin/csh

/bin/ksh

/bin/zsh

Most Linux users use the default bash shell, but those with long UNIX backgrounds with other shells may want to
override the default. It is worth reviewing the main choices in the historical order of introduction.

Any command shell can be invoked merely by typing its name at the command line. A user’s default shell can be
changed with the chsh utility.

We will concentrate on bash, which is generally the default shell under Linux.

Kinds of shells
 A login shell is one requiring a password (logging in)
 An interactive shell is one in which the standard input/output streams are connected to terminals
 A non-interactive shell is one in which the standard input/output streams may be connected to a process,
etc.
Initialization

Interactive shells

Login shells:

 if /etc/profile exists, source it
 if ~/.bash_profile exists, source it
 else if ~/.bash_login exists, source it
 else if ~/.profile exists, source it
 on exit, if ~/.bash_logout exists, source it

Non-login shells:

 if ~/.bashrc exists, source it

Non-interactive shells

Despite what the man page says, it seems to be the same as interactive shells.

Note that by default, most distributions include a system-wide file (usually /etc/bashrc) from the user’s ~/.bashrc.

Aliases permits custom definitions. Typing alias with no arguments gives the list of defined aliases. unalias gets rid
of an alias.

Some alias examples are shown below:

8
alias l=’ls -laF’

alias dir=’ls -latF’

alias rm=’rm -i’

alias mv=’mv -i’

alias cp=’cp -ipdv’

alias df=’df -T’

alias myyahoo=’firefox https://my.yahoo.com’

alias diffside=’diff --side-by-side --ignore-all-space’

Environment variables are not limited in length or number. Lots of applications use them, for instance, in order to set
default values for configuration options.

Examples include HOME, HOST, PATH, and can be set as in PATH: PATH=$HOME/bin:$PATH for example.

Note: Putting ./ in your path is a security risk; an unfriendly user might substitute an executable which could be quite
harmful. However, if you are on a single user system, you may want to violate this recommendation.

Type env (or export) to get a list of presently exported environment variables, set to get the complete set of
variables.

Some variables to set (use whatever values make sense for you!):

EDITOR=/usr/bin/emacs

CD_PATH=$HOME:/tmp

LS_COLORS="......"

PAGER=/usr/bin/less
HISTSIZE=1000

An environment variable must be exported to propagate its value to a child process. You can do either of the
following:

$ VAR=value ; export VAR

$ export VAR=value

You can also make one or more environment variables take effect for just one command:

$ LD_LIBRARY_PATH=$PWD DEBUG=3 ./foobar

The default command line prompt is $ for normal users and # for the root or superuser.

Customizing the command line prompt is as simple as modifying the value of the environment variable PS1. For
example, to set it to display the hostname, user and current directory:

2
$ PS1="\h:\u:\w>"

c7:coop:/tmp>

Besides the aesthetic value of having a prettier prompt than the default value, embedding more information in the
prompt can be quite useful. In the example given we have shown:

 The machine name - this is useful if you run command line windows on remote machines from your desktop;
you can always tell where you are, and this can avoid many errors.
 The user name - this is particularly important if you are running as a superuser (root) and can help you avoid
errors where you take what you think is a benign action and wind up crippling your system.
 The current directory - it is always important to know where you are. You certainly do not want to do
something like rm * in the wrong directory.

Here is a table with some of the possible special characters that can be embedded in the PS1 string:

Character Meaning Example Output

\t Time in HH:MM:SS 08:43:40

\d Date in ”Weekday Month Date” Fri Mar 12

\n Newline

\s Shell name bash

\w Current working directory /usr/local/bin

\W Basename of current working directory bin

\u User coop

\h Hostname c7

\# Command number (this session) 43

\! History number (in history file) 1057

Note you can embed any other string you like in the prompt.

A number of characters have a special meaning and cause certain actions to take place. If you want to print them
directly, you usually have to prefix them with a backslash (\) or enclose them in single quotes.

Redirection Special Characters


Character Usage

\#> Redirect output descriptor (Default # = 1, stdout)

< Redirect input descriptor

>> Append output

>& Redirect stdout and stderr (equivalent to .. > .. 2>&1)

Compound Commands Special Characters


Character Usage

| Piping

() Execute in a separate shell

&& AND list

|| OR list

; Separate commands

Expansion Special Characters


Character Usage

{} Lists

~ Usually means $HOME

$ Parameter substitution

‘ Back tick; used in expression evaluation (also $() syntax)

$(( )) Arithmetic substitution

[] Wildcard expressions, and conditionals


Character Usage

Escapes Special Characters


Character Usage

\ End of line, escape sequence

’’ Take exactly as is

"" Take as is, but do parameter expansion

Other Special Characters


Character Usage

& Redirection and putting task in background

# Used for comments

*? Used in wildcard expansion

! Used in history expansion

Note there are three different quoting mechanisms listed above:

 \ (as in \|; try echo | vs echo \|)


 single quotes: preserves literal value
 double quotes: same except for $, ‘, and \ .

Note you can get a literal quote character by using \’ or \".

Try:
1

$ echo $HOME

$ echo \$HOME

$ echo ’$HOME’

$ echo "$HOME"

File descriptors:

 0 = stdin
 1 = stdout
 2 = stderr

less < file same as less file or less 0< file

foo > file ; redirect stdout (same as foo 1> file)

foo 2> file ; redirect stderr

foo >> file ; append stdout to file

foo >& file or foo > file 2>&1;

sends stdout and stderr to a file, but foo >>& file does not work ; you have to do foo >> file 2>&1

Note that foo > file 2>&1 is not the same as foo 2>&1 > file; the order of arguments is important.

A nice non-portable trick you can use in Linux is to take advantage of the device nodes:
1

/dev/stdin

/dev/stdout

/dev/stderr

$ foo > /dev/stderr

Each step in a pipeline is a separate shell; i.e. there is a true pipeline. Be careful with redirection. Also |& does not
work.

cat nofile | grep string produces an error if nofile does not exist.

cat nofile | grep string 2>errs does not work.

cat nofile 2>&1 | grep string > errs does not work.

cat nofile 2>errors | grep string does work.

The tee utility can be very useful for saving output while still looking at the screen:
1

$ foobar | tee filename

$ foobar 2>&1 | tee filename

Each step in a pipeline is a separate shell; i.e. there is a true pipeline. Be careful with redirection. Also |& does not
work.

cat nofile | grep string produces an error if nofile does not exist.

cat nofile | grep string 2>errs does not work.

cat nofile 2>&1 | grep string > errs does not work.

cat nofile 2>errors | grep string does work.

The tee utility can be very useful for saving output while still looking at the screen:

$ foobar | tee filename

$ foobar 2>&1 | tee filename


There are two mechanisms for substituting the result of an operation into a command:

$ ls -l ‘which --skip-alias emacs‘

$ ls -l $(which --skip-alias emacs)

The second form permits nesting, while the first form does not. Note that the first form has “backticks” (‘) not
apostrophes.

Arithmetic expressions may be evaluated in two different ways, using the expr utility, or the $((..)) syntax:

For x=3:

Arithmetic Expression Evaluation Forms

Expression Gives

echo $x + 1 3+1
Expression Gives

echo $(expr $x + 1) 4

echo $((x+1)) 4

echo $(($x + 1 )) 4

echo $(expr $x+1) 3+1

The $((..)) syntax is more modern and preferred; expr is less efficient, as it invokes an external program and is
trickier to use.

Note that $var, $(cmd), ‘cmd‘, and $((...)) all expand inside double quotes.

Lab 1: Customizing the Prompt

Set the prompt to be:

1) current directory>
(i.e. /home/coop> )

PS1='\w''>' (OR)
PS1='`pwd`>' (BETTER)

2) machine name:user:current directory>


(i.e., p133:coop:/home/coop> )

PS1='\h:\u:\w>' (OR)
PS1='\h:\u:'`pwd`'>' (BETTER)
#!/bin/bash
#/* **************** LFD201:2018-05-21 s_11/lab_pipe.sh **************** */
#/*
# * The code herein is: Copyright the Linux Foundation, 2018
# *
# * This Copyright is retained for the purpose of protecting free
# * redistribution of source.
# *
# * URL: http://training.linuxfoundation.org
# * email: [email protected]
# *
# * This code is distributed under Version 2 of the GNU General Public
# * License, which you should have received with the source.
# *
# */
#!/bin/bash

# Lab: Redirection

# Try a command such as the following:

# $ ls /etc/passwd /etc/passwd_not
# where one file exists and the other does not.

# 1) Get the 'stdout' output of the command in one file and the
# 'stderr' output in another.

ls /etc/passwd /etc/passwd_not > stdout_out 2> stderr_out

echo stdout_out contains:


cat stdout_out

echo stderr_out contains:


cat stderr_out

# 2) Now get them both to go to the same file.

ls /etc/passwd /etc/passwd_not >& stdout_and_stderr_out


#
ls /etc/passwd /etc/passwd_not > stdout_and_stderr_out 2>&1

echo stdout_and_stderr_out contains:


cat stdout_and_stderr_out

# 3) Now get the 'stderr' output to go away to '/dev/null'

ls /etc/passwd /etc/passwd_not 2> /dev/null


echo was the output on the terminal

# 4) Now pipe the result of the 'ls' command into 'sort' and get the
# 'stderr' output into a separate file.

ls /etc/passwd /etc/passwd_not 2> stderr_out | sort > stdout_out

echo stdout_out now contains:


cat stdout_out

Lab 2: Redirection

Try a command such as the following:

$ ls /etc/passwd /etc/passwd_not

where one file exists and the other does not.

1) Get the 'stdout' output of the command in one file and the 'stderr'
output in another.

ls /etc/passwd ls /etc/passwd_not > stdout_out 2> stderr_out

2) Now get them both to go to the same file.

ls /etc/passwd /etc/passwd_not >& stdout_and_stderr_out (OR)


ls /etc/passwd /etc/passwd_not > stdout_and_stderr_out 2>&1
3) Now get the 'stderr' output to go away to '/dev/null'

ls /etc/passwd /etc/passwd_not 2> /dev/null

4) Now pipe the result of the 'ls' command into 'sort'


and get the 'stderr' output into a separate file.

ls /etc/passwd /etc/passwd_not 2> stderr_out | sort > stdout_out

An error has occurred, please try again later

Linux for Developers

Week 2

Shells, Bash, and the Command Line

Prev

Next


o

o
o


QUIZ • 10 MIN

Shells, Bash, and the Command Line


Submit your assignment

DUEApr 27, 12:29 PM IST

ATTEMPTS3 every 8 hours

Try again

Receive grade

TO PASS80% or higher

Grade

40%

View Feedback

We keep your highest score

Shells, Bash, and the Command Line


Graded Quiz • 10 min

Due Apr 27, 12:29 PM IST


Try again once you are ready

TO PASS 80% or higher

Try again
GRADE

40%

Shells, Bash, and the Command Line


LATEST SUBMISSION GRADE

40%
1.Question 1
Which of the following commands would add newbin, a directory in your home directory, to the PATH(Select all
answers that apply)?

PATH=$HOME/newbin:$PATH

Correct

This puts the newbin program at the beginning of the path.

$PATH=$PATH:$HOME/newbin

PATH=$HOME/$newbin:$PATH

PATH=$PATH:$HOME/newbin

Correct

This puts the newbin program at the end of the path.

1 / 1 point

2.Question 2
To make an environment variable (VAR) effective for only one command (foobar), you should do:

VAR=value ; ./foobar
export VAR=value ./foobar

VAR=value && ./foobar

VAR=value ./foobar

Incorrect

This will not work as intended ; try it!

0 / 1 point

3.Question 3
Which of the following expressions will give the correct mathematical result (7) for x = 10 (Select all answers that
apply)?

$ echo $x - 3

$ echo $(expr $x-3)

This should not be selected

This will not work as intended ; try it!

$ echo $(($x - 3 ))

Correct

This will work as intended ; try it!

$ echo $(expr $x - 3)

Correct

This will work as intended ; try it!


0 / 1 point

4.Question 4
Which commands will get both the normal and error outputs of prog into afile?

foo 2>&1 file

This should not be selected

This will not work as intended ; try it!

foo >& file

foo > file 2>&1

Correct

This will work as intended ; try it!

foo >> file

0 / 1 point

5.Question 5
Which of the following commands has the correct syntax for specifying an alias?

alias doitall="make clean; make all; evince output.pdf"

Correct

You can have blank spaces in an alias if you use single or double quotes.

alias doitall=make clean; make all; evince output.pdf


alias doitall= "make clean; make all; evince output.pdf"

1 / 1 point

An error has occurred, please try again later

Linux for Developers

Week 2

Shells, Bash, and the Command Line

Prev

Next


o

o
o


QUIZ • 10 MIN

Shells, Bash, and the Command Line


Submit your assignment

DUEApr 27, 12:29 PM IST

ATTEMPTS3 every 8 hours

Try again

Receive grade

TO PASS80% or higher

Grade

60%

View Feedback

We keep your highest score

Shells, Bash, and the Command Line


Graded Quiz • 10 min

Due Apr 27, 12:29 PM IST


Try again once you are ready

TO PASS 80% or higher

Try again

GRADE
60%

Shells, Bash, and the Command Line


LATEST SUBMISSION GRADE

60%
1.Question 1
Which of the following commands would add newbin, a directory in your home directory, to the PATH(Select all
answers that apply)?

PATH=$HOME/$newbin:$PATH

PATH=$HOME/newbin:$PATH

Correct

This puts the newbin program at the beginning of the path.

PATH=$PATH:$HOME/newbin

Correct

This puts the newbin program at the end of the path.

$PATH=$PATH:$HOME/newbin

1 / 1 point

2.Question 2
To make an environment variable (VAR) effective for only one command (foobar), you should do:

VAR=value ; ./foobar
export VAR=value ./foobar

VAR=value ./foobar

VAR=value && ./foobar

Incorrect

This will not work as intended ; try it!

0 / 1 point

3.Question 3
Which of the following expressions will give the correct mathematical result (7) for x = 10 (Select all answers that
apply)?

$ echo $x - 3

$ echo $(expr $x - 3)

Correct

This will work as intended ; try it!

$ echo $(($x - 3 ))

Correct

This will work as intended ; try it!

$ echo $(expr $x-3)

1 / 1 point

4.Question 4
Which commands will get both the normal and error outputs of prog into afile?
foo >> file

foo > file 2>&1

Correct

This will work as intended ; try it!

foo 2>&1 file

foo >& file

You didn’t select all the correct answers

0 / 1 point

5.Question 5
Which of the following commands has the correct syntax for specifying an alias?

alias doitall=make clean; make all; evince output.pdf

alias doitall="make clean; make all; evince output.pdf"

Correct

You can have blank spaces in an alias if you use single or double quotes.

alias doitall= "make clean; make all; evince output.pdf"

1 / 1 point
Here is a list of the main directories which should be present under /:

Main Directories
Director In
Purpose
y FHS?

/ Yes Primary directory of the entire filesystem hierarchy

/bin Yes Essential executable programs that must be available in single user mode

Files needed to boot the system, such as the kernel, initrd or initramfs images, and boot configuration files and
/boot Yes
bootloader programs

/etc Yes System-wide configuration files

/home Yes User home directories, including personal settings, files, etc.

/lib Yes Libraries required by executable binaries in /bin and /sbin

64-bit libraries required by executable binaries in /bin and /sbin, for systems which can run both 32-bit and
/lib64 No
64-bit programs

/media Yes Mount points for removable media such as CD’s, DVD’s, USB sticks etc.

/mnt Yes Temporarily mounted filesystems

/opt Yes Optional application software packages

Virtual pseudo-filesystem giving information about the system and processes running on it; can be used to
/proc Yes
alter system parameters

Virtual pseudo-filesystem giving information about the system and processes running on it; can be used to
/sys No
alter system parameters, is similar to a device tree and is part of the Unified Device Model

/root Yes Home directory for the root user

/sbin Yes Essential system binaries

/srv Yes Site-specific data served up by the system; seldom used

/tmp Yes Temporary files; on many distributions lost across a reboot and may be a ramdisk in memory
Director In
Purpose
y FHS?

/usr Yes Multi-user applications, utilities and data; theoretically read-only

/var Yes Variable data that changes during system operation

A system should be able to boot and go into single user, or recovery mode, with only
the /bin, /sbin, /etc, /lib and /root directories mounted, while the contents of the /boot directory are needed for the
system to boot in the first place.

Many of these directories (such as /etc and /lib) will generally have subdirectories associated either with specific
applications or sub-systems, with the exact layout differing somewhat by Linux distribution. Two of
them, /usr and /var, are relatively standardized and worth looking at.

Directories Under /usr


Directory Purpose

Non-essential binaries and scripts, not needed for single user mode; generally this means user applications not needed to
/usr/bin
start system

/
Header files used to compile applications
usr/include

/usr/lib Libraries for programs in /usr/bin and /usr/sbin

/usr/lib64 64-bit libraries for 64-bit programs in /usr/bin and /usr/sbin

/usr/sbin Non-essential system binaries, such as system daemons

/usr/share Shared data used by applications, generally architecture-independent

/usr/src Source code, usually for the Linux kernel

/usr/X11R6 X Window files; generally obsolete

/usr/local Local data and programs specific to the host; subdirectories include bin, sbin, lib, share, include, etc.

Directories Under /var


Directory Purpose

/var/ftp Used for ftp server base

/var/lib Persistent data modified by programs as they run

/var/lock Lock files used to control simultaneous access to resources

/var/log Log files

/var/mail User mailboxes

/var/run Information about the running system since the last boot

/var/spool Tasks spooled or waiting to be processed, such as print queues

/var/tmp Temporary files to be preserved across system reboot; sometimes linked to /tmp

/var/www Root for website hierarchies

The path is a critical aspect of your environment, and is encapsulated in the PATH environment variable. On an
RHEL 7 system for a user named student, we get:

$ echo $PATH

/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:\

/usr/local/sbin:/usr/sbin:/home/student/.local/bin:/home/student/bin

(Note we have had to split the path across across two lines in the output.)
When a user tries to run a program, the path is searched (from left to right) until an executable program or script is
found with that name. You can see what would be found with the which command, as in:

$ which --skip-alias emacs

/usr/bin/emacs

Note that if there was a /usr/local/bin/emacs, it would be executed instead, since it is earlier in the path.

It is easy to add directories to your path, as in:

$ MY_BIN_DIR=$HOME/my_bin_dir

$ export PATH=$MY_BIN_DIR:$PATH

$ export PATH=$PATH:$MY_BIN_DIR

with the first form prepending your new directory and the second appending it to the path.

Note that the current directory is noted by ./ and the directory up one level by ../.

The current directory is never placed in the path by default. Thus, if you want to run foobar in the current directory,
you must say:
1

$ ./foobar

for it to work.

You can save changes to your path by putting them in your shell initialization file, .bashrc in your home directory.

Another useful path variable is CDPATH which is searched when you change directories. For example:

5
$ cd bin

-bash: cd: usr: No such file or directory

$ export CDPATH=/usr:$CDPATH

$ cd bin

/usr/bin

Any path which begins with / is considered absolute because it specifies the exact filesystem location. Otherwise, it is
considered relative and it is implicitly assumed your current directory is prepended.

The ln program can be used to create hard links and (with the -s option) soft links, also known as symbolic links or
symlinks.

Suppose file1 already exists. A hard link to it is created with the command:

$ ln file1 file2

$ ls -li file1 file2

84 -rw-rw-r-- 2 coop coop 1551 Jun 16 16:28 file1

84 -rw-rw-r-- 2 coop coop 1551 Jun 16 16:28 file2

Note that two files now appear to exist. However, a closer inspection of the file listing shows that this is not quite true.

The -i option to ls prints out in the first column the inode number, which in UNIX filesystems is unique for each file
object. This field is the same for both of these files; what is really going on here is that it is only one file, but it has two
names. The 2 that appears later in the ls listing indicates that this inode has two links to it.

Let's consider another example:


1

$ ls -li /bin/g*zip

194339 -rwxr-xr-x 3 root root 62872 Jan 14 13:06 /bin/gunzip

194339 -rwxr-xr-x 3 root root 62872 Jan 14 13:06 /bin/gzip

which shows that gzip and gunzip are both only one program and the executable is only one file; whether it
compresses or decompresses files depends on which name it is invoked with, which is always available
as argv[0] when the program executes.

Hard links are very useful and they save space, but you have to be careful with their use, sometimes in subtle ways.
For one thing, if you remove either file1 or file2 in the above example, the inode object (and the remaining file name)
will remain, which is generally desirable.

However, if you edit one of the files, exactly what happens depends on your editor; most editors, including vi and
emacs, will retain the link by default, but it is possible that modifying one of the names may break the link and result
in the creation of two objects.

Symbolic (or soft) links are created with the -s option, as in:

$ ln -s file1 file2
$ ls -li file1 file2

84 -rw-rw-r-- 1 coop coop 1551 Jun 16 16:28 file1

85 lrwxrwxrwx 1 coop coop 5 Jun 16 16:43 file2 -> file1

Notice file2 no longer appears to be a regular file, and it clearly points to file1 and has a different inode number.

Symbolic links take no extra space on the filesystem (unless their names are very long), as they are stored directly in
the directory inode. They are extremely convenient, as they can easily be modified to point to different places.

Unlike hard links, soft links can point to objects even on different filesystems (or partitions), which may or not be
currently mounted or even exist. In the case where the link does not point to a currently mounted or existing object,
one obtains a dangling link.

The symlinks utility can be used to examine current symbolic links, as in:

c7:/usr/share/gdb/auto-load>symlinks -rv .

relative: /usr/share/gdb/auto-load/lib -> usr/lib

dangling: /usr/share/gdb/auto-load/sbin -> usr/sbin

relative: /usr/share/gdb/auto-load/lib64 -> usr/lib64

dangling: /usr/share/gdb/auto-load/bin -> usr/bin

easily be modified to point to different places.

Create a simple executable file with the name ls in your current directory, which we will assume to be /tmp:
1

$ cd /tmp

$ echo echo Hello, This is MY ls program > ls

$ chmod +x ls

You can run this directly by doing:

$ ./ls

but just typing ls will bring up the normal /bin/ls, which can be verified by typing which ls.

If you do:

$ export PATH=/tmp:$PATH

then typing ls will bring up your program no matter where you are sitting on the filesystem.

This is different than doing:


1

$ export PATH=./:$PATH

which puts the current directory first in the path, no matter where you are, or

$ export PATH=$CWD:$PATH

which will put the current working directory at this time in your future path.

Prepending your current directory to the path is generally a bad idea, as it makes trojan horses easy to implement.

Skip to Main Content


 Vedantham Ramachandran

Linux for Developers

Week 2

Filesystem Layout, Partitions, Paths, and Links


Prev

Next



o

o
o

QUIZ • 10 MIN

Filesystem Layout, Partitions, Paths, and Links


Submit your assignment

DUEApr 27, 12:29 PM IST

ATTEMPTS3 every 8 hours

Try again

Receive grade

TO PASS80% or higher

Grade

20%

View Feedback

We keep your highest score

Filesystem Layout, Partitions, Paths, and Links


Graded Quiz • 10 min

Due Apr 27, 12:29 PM IST


Try again once you are ready

TO PASS 80% or higher

Try again

GRADE
20%

Filesystem Layout, Partitions, Paths, and Links


LATEST SUBMISSION GRADE

20%
1.Question 1
Which of the following pseudo-directories are empty when the system is not running (Select all answers that apply)?

/etc

/dev

Correct

/dev contains only pseudofiles created in memory after system start.

/boot

This should not be selected

/boot is a permanent directory held in storage on disk.

/proc

Correct

/proc contains only pseudofiles created in memory after system start.

/sys

0 / 1 point

2.Question 2
Which of the following statements describes the best practice?
The current directory should be appended to the path

The current directory should be prepended to the path

The current directory should not be placed in the path

Incorrect

0 / 1 point

3.Question 3
If file does not exist, which command will produce an error?

ln file file2

ln -s file file2

Incorrect

You can have a "dangling" soft link

0 / 1 point

4.Question 4
Which command will list the partition information on the first hard disk and then exit?

fdisk -l hd1

fdisk -l /dev/sda

fdisk /dev/sda
Correct

This will give a report and return to the command line.

1 / 1 point

5.Question 5
Which directory trees usually have frequently changing data, and would not be desirable on a partition that is more
static? Select all answers that apply.

/usr

This should not be selected

/usr should change only when software is modified or installed.

/home

/var

Correct

/var is designed for variable, volatile data.

/bin

This should not be selected

/bin is designed for rarely-changing system utilities.

/tmp

Correct

/tmp is designed for temporary data.

0 / 1 point

You might also like