Professional Documents
Culture Documents
If the use is in
/usr/X11/bin/xeyes
3: GNU and Unix Commands
3.1: Working on the Command Line … contd
Shell Variables
• The shell variables are similar to variables used in any
computing language.
Initialize a variable Variable-name=value
• Example
Reference a variable $Variable-name
• Meta characters
Type Meaning
< Input
> Output
$ Sign used for variable
| Pipe, used for piping
3: GNU and Unix Commands
3.1: Working on the Command Line … contd
Wildcards
• Linux provides text bases help system known as man, shor for manual
e.g: $man man –to learn about man page itself
3: GNU and Unix Commands
3.1: Working on the Command Line … contd
Man pages
3: GNU and Unix Commands
3.1: Working on the Command Line … contd
man pages … contd.
Example:
$man 5 passwd Returns information on passwd file format
3: GNU and Unix Commands
3.1: Working on the Command Line … contd
whatis database
• The whatis database stores the NAME section of all
manpages on the system.
• This is updated regularly through a daily cron.
Syntax:
whatis <string>
3: GNU and Unix Commands
3.1: Working on the Command Line … contd
whatis database
• One can also use the man command to query the whatis database,
$man –k <string> Syntax, for querying whatis database
uname command
• Prints information relating to the kernel version, machine name,
processor type and node name
searched
Search the readme.txt, and after
manipulation store the result in
ReadMe.txt
3: GNU and Unix Commands
3.2: Perform basic file management
Key knowledge areas:
• Copy, move and remove files and directories individually.
• Copy multiple files and directories recursively.
• Remove files and directories recursively.
• Use simple and advanced wildcard specifications in commands.
• Using find to locate and act on files based on type, size, or time.
• Usage of tar, cpio and dd.
3: GNU and Unix Commands
3.2: Perform basic file management
Moving around file system
•
3: GNU and Unix Commands
3.2: Perform basic file management
Moving around file system: Absolute Path Names
• The linux file system is organised in a tree structure
• The top level directory of the tree is called the root directory and is
named '/‘
• A file or directory can be referenced using an absolute pathname
– Starts with a '/‘
– Traces a path from the root of the tree to the file
– Uses '/' (forward slash) to separate components of the pathname
• Examples:
/etc/at.deny
/home/dilbert/travel
/home/tux/reports/quality
3: GNU and Unix Commands
3.2: Perform basic file management
Moving around file system: Relative Path Names
• Pathnames not beginning with '/' are relative to the current directory
• Examples (assuming /home/tux is the current directory):
reports
code/main.c
• Every directory has a special entry named '..' which references the
parent directory
– The directory immediately above it in the tree
• Use relative pathnames beginning with '..' to move outside the current
directory
• Examples (assuming /home/tux/code is the current directory):
../reports/July_Conf
../../dilbert/travel/paris
3: GNU and Unix Commands
3.2: Perform basic file management
Moving around file system:
pwd: Gives your actual position as an absolute path.
cd: The 'change directory' command
ls: List the contents of a directory.
• The command can take several parameters the most common of
which are:
-l – use the long listing format,
-a – list all files and directories including hidden files and directories,
-h – show file sizes in human readable format, ie. Formatted for easy
reading
-d – list directories only and does not list their contents.
3: GNU and Unix Commands
3.2: Perform basic file management
find
find <DIRECTORY> <CRITERIA> [-exec <COMMAND> {} \;]
• The DIRECTORY argument tells find where to start searching and CRITERIA can be a
combination of serial selection criteria, including the name of a file or directory we
are looking for.
• a specific operation can be performed on each file found. For example to delete the
file, or change the permission. The find tool has the built-in option –exec which
allows you to do that.
Removing directories:
• To remove a directory use either rmdir or rm -r. rmdir will only remove empty
directories. Specify -f to force the deletion of files on which you do not have write
permission.
3: GNU and Unix Commands
3.2: Perform basic file management
Handling directories
Copying files
cp
Syntax:
cp [options] file1 file2
cp [options] files directory
It is important to notice that cp file1 file2 makes a new copy of file1 and
leaves file1 unchanged. You can also copy several files to a directory,
using a list or wildcards. The following table lists the most used options.
3: GNU and Unix Commands
3.2: Perform basic file management
Handling directories
Copying files
3: GNU and Unix Commands
3.2: Perform basic file management
Handling directories
Moving files
mv
Syntax:
mv [options] oldname newname
mv [options] source destination
• Renames/Moves a file or directory
touch
Another way of creating or modifying a file is to use touch.
Syntax: touch {options} file(s)
dd
This command copies a file with a changeable I/O block size. It can also be used
to perform conversions
Main options are if= (input file) of= (output file) conv= (conversion)
• The conversion switch can be: lcase ucase ascii
3: GNU and Unix Commands
3.2: Perform basic file management
File Archiving and Compression
• Linux has several utilities for compressing and archiving files. Some of
these tools have their origins in tape archiving and backup solutions
and the parameters and names reflect this.
tar
• The tar (tape archive) command is used to archive directories and
optionally compress the archive.
-c : create
-v: verbose mode
-j : compress with bzip compression
if –z: it means gzip
-f: name of the file, in this case, backup.tar.bz
ls : lists files
| : is a pipe,
cpio –ov >backup.cpio – creates the
archive
3: GNU and Unix Commands
3.2: Perform basic file management
File Archiving and Compression
cpio … contd
• This will extract the cpio archive to the current directory. One of the
tricky things to remember with cpio is its parameters.
• With cpio, - o is for creating and -i is for extraction
Where,
-i : is for extract
-v : is verbose mode,
3: GNU and Unix Commands
3.2: Perform basic file management
File Archiving and Compression
gzip/gunzip
• gzip is used to compress files using Lempel-Ziv coding.
• By default gzip creates an output file with the same name as the input
file but with the extension .gz added.
• Notice the [1]+ symbol above. The integer is the process' job number, which it can be
referred to as.
• The '+' sign indicates the last modified process.
• A '-' sign would indicate the second last modified process. One can start a process in
the background by appending a & to the command.
3: GNU and Unix Commands
103.5 Create, Monitor and Kill Processes
Listing jobs
• The jobs utility lists all running processes started from the current shell.
• The job number, the job's state (running/stopped), as well as the two last
modified processes, will be listed.
• One can also stop processes without knowing the process' PID using
killall.
killall
Syntax
killall SIGNAL process_NAME
3: GNU and Unix Commands
103.6 Modify Process Execution Priorities
Process Priority
The nice command
• When a process is started by a user it has a default priority, or nice number
of 0.
• Nice numbers (NI) alter the CPU priority and are used to balance the CPU
load in a multiuser environment.
• Nice numbers range from 19 [lowest] to -20 [highest].
• Only root can decrease the nice number of a process. Since all processes
start with a default nice
• number of zero as a consequence negative nice numbers can only be set by
root!
• To modify a process' priority that is already running use renice. To set a
process' priority use nice.
• To modify a process' priority that is already running use renice. To set a
process' priority use nice
3: GNU and Unix Commands
103.6 Modify Process Execution Priorities
Process Priority
The nice command … contd
• This is the editing and navigation mode. Commands are often just a
letter. For example use j to jump
• to the next line.
3: GNU and Unix Commands
103.8 Using vi
Modes
• In order to perform complex operations such as copy/paste, vi can
operate in different modes.
1.Command mode
2.Last Line Mode (or Column Mode)
3.Insert Mode
• This is the editing and navigation mode. Commands are often just a
letter. For example use j to jump
• to the next line.