0% found this document useful (0 votes)
6 views5 pages

basic_linux_commands

The document provides a comprehensive overview of working in a Linux environment, including its history, key commands, file structure, and user interface. It explains the significance of the Linux kernel, the GNU project, and the various Linux distributions available. Additionally, it details essential shell commands, file management, and system navigation techniques necessary for effective command-line usage.

Uploaded by

wovigej190
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6 views5 pages

basic_linux_commands

The document provides a comprehensive overview of working in a Linux environment, including its history, key commands, file structure, and user interface. It explains the significance of the Linux kernel, the GNU project, and the various Linux distributions available. Additionally, it details essential shell commands, file management, and system navigation techniques necessary for effective command-line usage.

Uploaded by

wovigej190
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

Working in LINUX environment

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.)

Another free UNIX is BSD (Berkeley Distribution System) system.

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)

Starting Lab session


(Lab is based on command line interface- you have to execute commands in terminal mode only. Do not use mouse as it is
NOT GUI)
(Click putty programme ( putty.exe (32bit) from putty.org ) on your window based desktop .
Enter server IP address and press open button). Login-id , password and server IP address will be provided to you.
A Terminal window opens-
login <- enter your login name (case sensitive)
password <- enter password (case sensitive) , nothing will be display(during password entry) ,
if wrong entry press enter. The login message will appear. When password is matched, you will be
connected to server. ($ will appear as prompt, shell is ready to take your command)
Welcome screen appears.
(From Linux based machine ,start term (terminal programme) and write following -
ssh <loginid-at-remote-server>@<remote-server-ip-address>
enter password
)

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).

The eight most important shell commands in UNIX are:


ls lists the contents (files and subdirectories) names in given path. (can use dir also)
cat displays the contents of a file(s)
cp copies file(s) or directory
mv renames and/or moves file(s) or directory
rm deletes file(s) or directory
chmod grants and revokes access to files/directories
mkdir creates subdirectories
rmdir removes empty subdirectories

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 tells the location of a file or sub-directory in the file system.


A directory is a special file which contains name of filenames and other directories (called subdirectories)in that
directory and meta-information of these files/directories. Reference to file/directory is called link. Every directory or
subdirectory contains at least two entries: . , reference to itself , and .. is a link to its parent directory ,parent of
current directory (above to current directory in the hierarchy in file structure).

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 /)

Some Linux commands

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

cd command is used to change current directory to specified directory


with chmod command access right can be modified as per permission.
The rights of a file can be changed by chmod [ugoa] +/-rwx filename or directory name
u owner ; g group ; o others; a all + add – delete rwx file rights
chown is used to change owner and/or group of a file or directory
chown root.g3 filename ; change the owner and group to root and g3 respectively
Simple text file can be created with cat command.

Type “cat > filename ” at prompt


(system is ready to get characters from keyboard)
type your text
in last line first column press Ctrl+D
file is created and saved by given name.
using ls (or cat) command file can be listed (or contents of the file displayed) respectively.
large file can be displayed on screen one screenful at a time using pipe (symbol is |) to command more

cat filename | more


Press the space bar (or Enter key) and another screenful(next line) appears, if you want to quit, type "q" instead of pressing the space bar.

pwd gives the absolute path of present working directory


If you are at other than your home directory use cd ~ to return to your home directory (tilde)
current directory is identified as . and its parent directory as ..
When you refer to a file without its directory location, UNIX assumes that it's located in the current 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)

tree - gives the nested directory structure.


kill- terminate a process (by id)
killall- terminate all processes (by name)
uname -a gives all information of the OS
date – display time and date
cd - change directory to given path (absolute or relative), use ~ for home, .. for parent folder
ls -List the contents of current or any directory (give absolute or relative path)
(-a, -A, -l, -R,-r,-d,-t,-i -F,-X)
mkdir - make directory in current or at any directory (give absolute or relative path) (-p)
rmdir - remove directory in current or at any directory (give absolute or relative path)
mv - move file/directory to destination (rename is source/destination is same) (-b,-f,-i,-u)
cp - copy file/directory to destination (-b,-i,-p,-r)
rm - remove file/directory to destination (-i,-f,-r)
cat - joins two or more files or display files
cat file1 file2 file3 > file4 :(concatenate > or >> append) files in given order
find -locate a file/directory based on expression
echo - display on screen/file . echo a test sentence > filename : puts “a test sentence” in filename
echo a test sentence >> filename : appends a test sentence in filename
which commnand-name : shows the full path of the command-name (whereis cmd shows all relevant entries)
touch filename- creates (up date time of existing) filename
ln – links existing filename to symbolicname: hard link (or softlink with option -s) : creates soft/hard link of a file
du - list size of files in pwd and its subdirectories (-a)
free - list memory usage, free space
ps - list process in system (-a,-m,-u,-e,-l,-f , -)
grep -(general regular expression print) : displays line containing expression in or more files
head - display first ten lines of a file (-n)
tail - display last ten lines of a file (-n)
sort - sorts a file in order (ASCII) by lines
uniq - display by skipping adjacent duplicate lines
diff - compare two files (file1 file2) and displays a list of differences between them.
(It display the line to be added (a), deleted (d) or changed (c) with line number of file1 then file2; uses
< for file1 and > for file2 (add , delete or change to make identical files))
split - Split a file into pieces
join - Joins two tabular files
file - gives type of file
sum - Compute checksum of files
history - display past commands (past command can be access using up arrow key)
more - displays the file file-n one page at a time (press space for next)
less - similar but more powerful than “more” command
sort - sort and/or merge files (sort the lines of a file, o option output file and m merge files)
(-r,-f,-i,-n,-c,-m,-u,-o) +column-number as sort rule (multi pass sort in one command )
clear - clear screen
man – manual that displays the contents of a system command
passwd - change user password
exit - exit the current shell (logout or ctrl+d )

redirection symbols < , > , >>


Redirect input; >
Redirect output; >>
Concatenate output to file; |
cmd1 | cmd2 : output of cmd1 to cmd2
cmd1 > filename : output of cmd1 to file name (existing filename overwritten)
cmd1 >> filename : output of cmd1 to file name (existing filename appended with)
filename < cmd1 : input for cmd1 from filename

Wildcard for character(s)


* and ?
Wildcard for single character
[charset] Wildcard for character in charset eg: f[a-d]* or p[!n-z]??.txt
[^charset ] Wildcard for not the characters in the charset
[!charset ] Wildcard for not the characters in the charset

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

CTRL C terminates running command


CTRL Z suspends program execution

compilation of source programme-


gcc - GNU C compiler
g++ - GNU C++ compiler

You might also like