basic_linux_commands
basic_linux_commands
Brief introduction
Linux is loosely used to refer to the UNIX-like operating systems where Linux kernel is used.
In 1984, Richard Stallman started GNU project (a recursively defined acronym for “GNU’s Not UNIX”) to develop an entire,
freely available, UNIX-like system,consisting of a kernel and all associated software packages, and encouraged others
to join. Linus Torvalds developed a basic kernel that allowed him to compile and run various GNU programs.
Torvalds made Linux available under the GNU GPL.
(Software licensed under the GPL must be made available in source code form, and must be freely redistributed under the terms of the GPL. Modifications to
GPL-licensed software are freely permitted, but any distribution of such modified software must also be under the terms of the GPL. If the modified software
is distributed in executable form, the author must also allow any recipients the option of obtaining the modified source for no more than the cost of
distribution.)
Linux kernel version numbering scheme with each release numbered x.y.z: x representing a major version, y a minor
version within that major version, and z a revision of the minor version (minor improvements and bug fixes).
Linux distributions - In the very early days of Linux, the user was required to assemble all of this software, create a
file system, and correctly place and configure all of the software on that file system. This demanded considerable time
and expertise. As a result, a market opened for Linux distributors, who created packages (distributions) to automate
most of the installation process, creating a file system and installing the kernel and other required software.
Some of the noncommercial distribution are Debian , SUSE, Red Hat, Ubuntu etc.
(www.distrowatch.com)
Once you are logged in, the it may displays some information about the system .
The command prompt (left side of blinking cursor) may appears as a dollar sign ($) . Currently you are in your (user)
home directory( we call this directory as UHD).
To finish lab session -type exit or logout at command prompt. (or Ctrl+D). Don’t use mouse to close your session.
A shell is a special-purpose program that reads commands typed by a user and execute appropriate programs in
response to those commands. It is also known as a command interpreter. Commands are gateway to OS. Here only
Bash shell is covered.
(other shell are Bourne shell(sh), C shell(csh), tc shell(tcsh), Z shell (zsh), k shell etc).
When you type a wrong command name, shell gives error message(shell looks for a file(program) given in command-line and if
shell couldn't find it , error message is displayed). If you do not provide complete (required) parameters or have written wrong
parameters with the command, the system displays the Usage of the command or error message.
Many commands uses switches (-) to indicate options, that extends optional features of the command.
More than one switches can be given with single -. There should be space between command , hyphen and parameters.
Help is available for commands. You can use info or man command. Its format is-
man command-name
info command-name
(Press q to come out from man or info, and back to shell.)
File naming- any combination of alphanumeric except <, >, |, `, “, ’,; ,/ . Names are case sensitive, objectnames can
be up to 255 characters long. (Valid character sets are-: ., [ , ] , ?/*, - , _ , a-z, A-Z, 0-9 )
first character of name if starts with “ . ” It means a hidden file(or directory) (The hidden objects will be displayed by ls -a ).
You can use wild card (* for many characters , ? For one character and [abc] or [a-z] for given character set only ) in filename when listing.
ls my* ;
ls *6* ;
ls ??test* ; ls my*6 ; for file name mytestfile68
If file name has a space then it is accessed using “ ” .For example “my file”
File organization based on nested directory structure.
main directory is called root . Its symbol is / ;subdirectories names are separated by /
following are the some of the subdirectories in root(/) in Linux -
bin boot dev etc home lib media mnt opt proc root run sbin tmp usr var
Important subdirectories in file structure of a Linux OS-
/bin – essential command binaries- files needed to boot and run time (common programme)
/sbin- essential system binaries used in system administration (root user)
/boot – files related to boot loader (kernel )
/etc – system configuration files
/dev – files related to peripheral devices
/home- user's home directory is one of the subdirectory of home
/lib – shared libraries files
/mnt – mount point of temporary partition or removable storage
/opt - Option installed programs
/proc- contains kernel and process information files (processor pseudo files)
/root – home directory of root (super user)
/tmp – temporary files of programmes
/usr – files and programmes used by system and all users
/var- files whose contents varies as the system runs (changing files)
/usr/doc- documents
/usr/bin- more shared programmes
/usr/lib - Specialize library files
/usr/man – online manual
/usr/src- kernel source code
/usr/include- header files of c programmes
/var/log - log files of the system
/dev/null - Null device
/dev/tty - Current display device
/home/ug20os/sxxxx - your home directory folder in the lab server
Path-name can be absolute or relative. Absolute(complete) path starts from root (/) to upto destination file/subdirectory.
In relative path starts either with ../ (to refer parent of current directory) or with child subdirectory-name
(subdirectory in current directory) upto destination file/subdirectory . (relative path never starts with /)
format of commands-
command [option] [source] [destination]
(source / destination objects can be given with absolute/relative path)
When files of a directory is displayed with ls -l command ,it gives information about files/folders
first field is access right to that file/folder-
d rwxrwxrwx or - rwxrwxrwx or l rwxrwxrwx or p rwxrwxrwx
the first character in above indicates whether it a subdirectory or a file or some special file , if first character is - it is a
normal file , if d it is subdirectory else other special files , remaining nine characters give the rights of the file
r right to read(read or copy); w right to write(edit); x right to execute(if file is programme)
each of three rights are for owner (creator,user) , owner's group and others (left most is owner)
if any of these nine field is “– ” it indicates that right is not available to that individual (owner, group, other)
directory has different meaning for access rights-
r list the files in directory; w modify/delete/create files/directories in directory; x enter into the directory
copy /remove file or directory (to include subfolders use -r option ) (along the path of the objects)
format of cp , rm ,mv -
cp source destination
rm source
mv source destination (it also works like rename)
in mv source / destination can be same(action is rename) or different directory(action is move)
compress / archieve
tar -tvzf mytarball.tgz : show table of contents(t)of gzipped(z) tarball with filename(f) mytarball.tgz
tar -xzf tarball.tgz :untar (extract x) contents of gzipped(z) tarball tarball.tgz
tar -cz mydir –f mytarball.tgz :create(c) a tarball mytarball.tgz from directory mydir
gzip filen : compress the file filen using GNUzip (-v,)
gunzip filen.gz : unzip the file filen.gz(compress with GNUzip)
zcat : displays the compressed file as it were compressed