Sei sulla pagina 1di 9

Linux 101

Working With The Command Line

Manual pages
http://linuxmanpages.com

man <command> man <section> <command> man uses the less pager Manual sections

Space Esc + V / Q

one page forward one page backward search quit

1 2 3 4 5 6 7 8 9

Excutable programs System calls Library calls Device files File formats Games Miscellaneous System administration commands Kernel routines

passwd command section 1 man passwd man 5 passwd /etc/passwd file section 5

Basic file management


Linux treats almost everything as a file regular files, directories, devices, sockets, pipes

touch, vi, nano, mkdir


Create / Modify

rm, rmdir

Delete

Locate

find, locate

gzip, gunzip, bzip2

Compress

View

less, ls

tar, cpio

Archive Move Rename

Copy

cp, dd

mv

Create a backup copy of the MBR


$ dd if=/dev/sda of=mbrsave bs=512 count=1

General notions
Linux is case sensitive Filename.txt <> filename.txt Filenames can contain any character. Filenames can be 255 characters long. filesystem dependent Special filenames . current directory .. parent directory
$ $ $ $ $ $ cd /usr/bin pwd cd . pwd cd .. pwd

Filenames should never contain wildcards: * ? \ quotations: $ touch fileone filetwo path separator: / $ touch file*
$ rm file*

A wildcard stands in place of a group of characters Wildcards Wildcard expansion = file globbing * zero or more characters ? only one character Replacing an wildcard with chars to obtain [] character set file names in the current directory

Linux shell
Shell implementations Bourne Again Shell
bash bsh most common Bourne Shell In linux tcsh C Shell csh Korn Shell ksh Z Shell zsh

/bin/sh symbolic link to the default shell

$ ls l /bin/sh $ ls l /bin/*sh

some can also be external commands Internal commands


ls echo <string> env set export cd <directory> change directory cd ~ pwd print working directory

replaces the shell exec <program>

time <command> exit logout

clear clear screen

Linux shell
Command Completion TAB
$ less ~/.bash_history

~/.bash_history
Command History History Search

UpArrow
DownArrow history history c Line editing

Ctrl + P
Ctrl + N display all history clear history

Ctrl + R reverse search Ctrl + S forward search Ctrl + G terminate search

move
delete

Ctrl+A

Ctrl+E

a command line in the shell


Ctrl+X; Bksp

move by one word Ctrl+Left Ctrl+Right

Del

Ctrl+K

Bash configuration: /etc/profile ~/.bash_profile

Environment variables
means of passing named data set a variable
$ export HOSTNAME=lpic.credis.ro $ HOSTNAME=lpic.credis.ro $ export HOSTNAME When retrieving the value of a variable precede the variable name with a '$' character

read a variable
$ echo $HOSTNAME $ env

set local variable export to the environment


Launch a shell with a modified environment ENV
$ env
copy launch

displays all environment variables

SHELL

ENV

CHILD SHELL

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

Streams, pipes & redirection


$ cat <<! Some simple text !

here-is document < << Standard Input stdin

append
<> program

Standard Output stdout


stderr Standard Error

>

>>

&> 2> 2>>

Discard errors

$ command 2> /dev/null

tee [options] [files] -a, --append

Writes input to stdout and files

send output of program1 to input of program2


program1 | program2

pipe

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.

Potrebbero piacerti anche