lab02.working with the command line
TRANSCRIPT
-
7/28/2019 Lab02.Working With the Command Line
1/9
Working With The Command Line
Linux 101
-
7/28/2019 Lab02.Working With the Command Line
2/9
Manual pageshttp://linuxmanpages.com
man man
man uses the less pager
Space one page forward
Esc + V one page backward
/ search
Q quit
Manual sections
1 Excutable programs
2 System calls
3 Library calls
4 Device files
5 File formats6 Games
7 Miscellaneous
8 System administration commands
9 Kernel routines
man passwdman 5 passwd
passwd command
section 1
/etc/passwd file
section 5
-
7/28/2019 Lab02.Working With the Command Line
3/9
Create / Modify
Locate
View
Copy
Move
Rename
Archive
Compress
Delete
Linux treats almost everything as a file
regular files, directories, devices, sockets, pipes
touch, vi, nano, mkdir
less, ls
cp, dd
mv
tar, cpio
gzip, gunzip,
bzip2
rm, rmdir find, locate
Basic file management
$ dd if=/dev/sda of=mbrsave bs=512 count=1
Create a backup copy of the MBR
-
7/28/2019 Lab02.Working With the Command Line
4/9
General notions
Linux is case sensitive
Filename.txt filename.txt Special filenames
. current directory
.. parent directoryFilenames can contain any character.
Filenames can be 255 characters long.
Wildcards
* zero or more characters
? only one character
[] character set
Wildcard expansion = file globbing
Filenames should never contain
wildcards: * ? \
quotations:
path separator: /
$ cd /usr/bin
$ pwd
$ cd .$ pwd
$ cd ..
$ pwd
filesystem dependent
$ touch fileone filetwo
$ touch file*
$ rm file*
A wildcard stands in place of a group of characters
Replacing an wildcard with chars to obtain
file names in the current directory
-
7/28/2019 Lab02.Working With the Command Line
5/9
Shell implementations
bash bsh tcsh csh ksh zsh
Bourne Again Shell
Bourne Shell
C Shell Korn Shell Z Shell
/bin/sh symbolic link to the default shell
Linux shell
Internal commands
echo
exec
time
exit
logout
cd
cd ~
change directory
pwd print working directory
clear clear screen
replaces the shell
set
env export
ls
most common
In linux
$ ls l /bin/sh
$ ls
l /bin/*sh
some can also be external commands
-
7/28/2019 Lab02.Working With the Command Line
6/9
Linux shell
Command Completion TAB
Command History
Ctrl + P
Ctrl + N
UpArrow
DownArrow
Ctrl + R reverse search
Ctrl + S forward search
Ctrl + G terminate search
History Search
~/.bash_history
history display all historyhistory c clear history
Bash configuration: /etc/profile ~/.bash_profile
Line editing
a command line in the shell
Ctrl+KDelCtrl+X; Bkspdelete
move Ctrl+ECtrl+Amove by one wordCtrl+Left Ctrl+Right
$ less ~/.bash_history
-
7/28/2019 Lab02.Working With the Command Line
7/9
read a variable
$ echo $HOSTNAME
$ env
displays all environment variables
set a variable$ export HOSTNAME=lpic.credis.ro
set local variableexport to the environment
$ HOSTNAME=lpic.credis.ro
$ export HOSTNAME
When retrieving the value of a variable precede
the variable name with a '$' character
Common environment variables:
USER/USERNAME - Username of current user
SHELL - Path to the current command shell
PWD - Present Working Directory HOSTNAME - TCP/IP name of the computer
HOME - Home directory of current user
PATH - List of directories where executables are found
PS1 - Default prompt in bash
DISPLAY - The display used by X (:0.0)
EDITOR - The default text editor
SHELLENV
CHILD
SHELL
ENV
launchcopy
$ env
Launch a shell with a
modified environment
Environment variablesmeans of passing named data
-
7/28/2019 Lab02.Working With the Command Line
8/9
Streams, pipes & redirection
programstdin stdout
stderr
Standard Input Standard Output
Standard Error
< >>
2> 2>>
&>
here-is document
Discard errors $ command 2> /dev/null
tee [options] [files] Writes input to stdout and files-a, --append
program1 | program2
pipe
send output of program1 to input of program2
append
$ cat Some simple text
!
-
7/28/2019 Lab02.Working With the Command Line
9/9
Exercises
1. An administrator runs a program and he wants to log the errors into the error.log file
but also display them in the shell. What command could he use?
2. Consider the following command:
$ touch data01 data02 data11 data12 data13
What are the commands (use different wildcards) for the following tasks:
Delete data01 and data02
Delete data11 and data13 Delete all data files
3. One installs some programs in the /opt/progs directory. What could be done such
that these programs can be executed without specifying the entire path? (Write a
command).
4. Write a command that you could use to create a backup of the systems configuration
files.