0% found this document useful (0 votes)
14 views24 pages

Linux Comands

Uploaded by

praveensrikar143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views24 pages

Linux Comands

Uploaded by

praveensrikar143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

I.

T Work shop (ES1105) Page No: ______

Experiment 4: Linux Operating System Commands

GENERAL COMMAND SYNTAX


The commands in Linux have the following syntax://{ $command options arguments }

Linux Basic Commands:


1. pwd
“pwd” command prints the absolute path to current working directory.
{ $pwd
/home/Raghu }

2. cal
Displays the calendar of the current month.
{ $cal
July 2012
Su Mo Tu We Th Fr Sa
1234567
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 }
‘cal ’ will display calendar for the specified month and year.
{ $cal 08 1991
August 1991
Su Mo Tu We Th Fr Sa
123
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31 }

3. clear
This command clears the screen.

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

4. echo
This command will echo whatever provide it.
{ $ echo "linoxide.com"
linoxide.com }
The ‘echo’ command is used to display the values of a variable. One such variable is ‘HOME’. To check
the value of a variable precede the variable with a $ sign.
{ $ echo $HOME/home/Raghu }

5. date
Displays current time and date.
{ $ date
Fri Jul 6 01:07:09 IST 2012 }
If interested only in time, can use 'date +%T' (in hh:mm:ss):
{ $ date +%T
01:13:14 }

6. tty
Displays current terminal.
{ $tty
/dev/pts/0 }

7. whoami
This command reveals the user who is currently logged in.
{ $whoami
Raghu }

8. id
This command prints user and groups (UID and GID) of the current user.
{ $ id
uid=1000(raghu) gid=1000(raghu)
groups=1000(raghu),4(adm),20(dialout),24(cdrom),46(plugdev),112(lpadmin),120(admin),122(sambas
hare) }
By default, information about the current user is displayed. If another username is provided as an
argument, information about that user will be printed:
{ $ id root
uid=0(root) gid=0(root) groups=0(root) }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

BASIC HELP COMMANDS


1. help
With almost every command, ‘--help’ option shows usage summary for that command.
{ $ date --help
Usage: date [OPTION]... [+FORMAT] or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date. }

2. whatis
This command gives a one line description about the command. It can be used as a quick reference for
any command.
{$ whatis date
date (1) - print or set the system date and time }
{ $whatiswhatis
whatis (1) - display manual page descriptions }

3. man
‘--help’ option and ‘whatis’ command do not provide thorough information about the command. For more
detailed information, Linux provides man pages and info pages. To see a command's manual page, man
command is used.
{ $ man date }
The man pages are properly documented pages. They have following sections:
NAME: The name and one line description of the command.
SYNOPSIS: The command syntax.
DESCRIPTION: Detailed description about what a command does.
OPTIONS: A list and description of all of the command's options.
EXAMPLES: Examples of command usage.
FILES: Any file associated with the command.
AUTHOR: Author of the man page
REPORTING BUGS: Link of website or mail-id where can report any bug.
SEE ALSO: Any commands related to the command, for further reference.
With -k option, a search through man pages can be performed. This searches for a pattern in the name and
short description of a man page.
{ $ man -k gzip
gzip (1) - compress or expand files
lz (1) - gunzips and shows a listing of a gzip'dtar'd archive
tgz (1) - makes a gzip'd tar archive
uz (1) - gunzips and extracts a gzip'dtar'd archive
zforce (1) - force a '.gz' extension on all gzipfiles }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

4. info
Info documents are sometimes more elaborate than the man pages. But for some commands, info pages are
just the same as man pages. These are like web pages. Internal links are present within the info pages. These
links are called nodes. Info pages can be navigated from one page to another through these nodes.
{ $ info date }
Linux Filesystem commands

BASIC FILESYSTEM COMMANDS


1. Change Directories
{ $ cd [path-to-directory] }
Change the current working directory to the directory provided as argument. If no argument is given to
‘cd’, it changes the directory to the user's home directory. The directory path can be an absolute path or
relative to current directory. The absolute path always starts with /. The current directory can be checked
with ‘pwd’ command (remember?)
{ $pwd
/home/raghu
$ cd /usr/share/
$ pwd
/usr/share
$ cd doc
$ pwd
/usr/share/doc }
In the first ‘cd’ command, absolute path (/usr/share) is used, and with second command, relative path
(doc) is used.

2. Listing File And Directories


{ $ ls [files-or-directories] }
List files and/or directories. If no argument is given, the contents of current directory are shown.
{ $ ls
example file1.txt file2.txt file3.txt }
If a directory is given as an argument, files and directories in that directory are shown.
{ $ ls /usr
bin games include lib lib64 local sbin share src }
‘ls -l’ displays a long listing of the files.
{ $ ls -l
total 4
drwxr-xr-x 2 raghuraghu 4096 2012-07-06 12:52 example

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

-rw-r--r-- 1 raghuraghu 0 2012-07-06 12:52 file1.txt


-rw-r--r-- 1 raghuraghu 0 2012-07-06 12:52 file2.txt
-rw-r--r-- 1 raghuraghu 0 2012-07-06 12:52 file3.txt }
In this long listing, the first character is 'd' or '-'. It distinguishes between file types. The entries with a '-'
(dash) are regular files, and ones with 'd' are directories. The next 9 characters are permissions ('rwxr-xr-x'
in first listing). The number following the permissions is the link count. Link count follows user and group
owner. In the above example, the file owner is 'raghu' and group owner is 'raghu' as well. Next is the size
of the file. And then time stamp before the name of file (or directory).
By default, hidden files or directories are not shown, to see hidden files as well, -a option is used. Hidden
files in Linux start with a period sign (.). Any file that starts with a period is hidden. So, to hide a file, just
need to rename it (and put a period before it).
{ $ ls -la odesk
total 16
drwxr-xr-x 4 raghuraghu 4096 2012-07-06 13:46 .
drwxr-xr-x 11 raghuraghu 4096 2012-07-06 13:15 ..
drwxr-xr-x 2 raghuraghu 4096 2012-07-06 12:52 example
-rw-r--r-- 1 raghuraghu 0 2012-07-06 12:52 file1.txt
-rw-r--r-- 1 raghuraghu 0 2012-07-06 12:52 file2.txt
-rw-r--r-- 1 raghuraghu 0 2012-07-06 12:52 file3.txt
drwxr-xr-x 2 raghuraghu 4096 2012-07-06 13:46 .hiddendir
-rw-r--r-- 1 raghuraghu 0 2012-07-06 13:46 .hiddenfile1.txt
-rw-r--r-- 1 raghuraghu 0 2012-07-06 13:46 .hiddenfile2.txt }
If want to see the properties of a directory instead of the files contained in it, use -d (with -l) option:
{ $ ls -ldodesk/
drwxr-xr-x 4 raghuraghu 4096 2012-07-06 13:46 odesk/ }

DATE AND TIME COMMAND WITH EXAMPLES


date command is used to display the system date and time. date command is also used to set date and time
of the system. By default the date command displays the date in the time zone on which unix/linux operating
system is configured. must be the super-user (root) to change the date and time.
Syntax:
{ date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] }
Options with Examples
1. date (no option) : With no options, the date command displays the current date and time, including
the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the
time zone name, and the year.

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Command:
{ $date
Output:
Tue Oct 10 22:55:01 PDT 2017 }
Note : Here unix system is configured in pacific daylight time.

2. -u option:Displays the time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal Time ) time


zone.
Command:
{ $date -u
Output :
Wed Oct 11 06:11:31 UTC 2017 }

3. –date or -d option: Displays the given date string in the format of date. But this will not affect the
system’s actual date and time value.Rather it uses the date and time given in the form of string.
Syntax:
{ $date --date=" string " }
Command:
{ $date --date="2/02/2010"
$date --date="Feb 2 2010" }
Output:
{ Tue Feb 2 00:00:00 PST 2010
Tue Feb 2 00:00:00 PST 2010 }

4. Using –date option for displaying past dates: Date and time of 2 years ago.
Command:
{ $date --date="2 year ago" }
Output:
{ Sat Oct 10 23:42:15 PDT 2015 }
*Date and time of 5 seconds ago.
Command:
{ $date --date="5 sec ago" }
Output:
{ Tue Oct 10 23:45:02 PDT 2017 }
*Date and time of previous day.
Command:
{ $date --date="yesterday" }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Output:
{ Mon Oct 9 23:48:00 PDT 2017 }
*Date and time of 2 months ago.
Command:
{ $date --date="2 month ago" }
Output:
{ Thu Aug 10 23:54:51 PDT 2017 }
*Date and time of 10 days ago.
Command:
{ $date --date="10 day ago" }
Output: { Sat Sep 30 23:56:55 PDT 2017 }

5. Using –date option for displaying future date: Date and time of upcoming particular week
day.
Command:
{ $date --date="next tue" }
Output:
{ Tue Oct 17 00:00:00 PDT 2017 }
*Date and time after two days.
Command:
{ $date --date="2 day" }
Output:
{ Fri Oct 13 00:05:52 PDT 2017 }
*Date and time of next day.
Command:
{ $date --date="tomorrow" }
Output:
{ Thu Oct 12 00:08:47 PDT 2017 }
*Date and time after 1 year on the current day.
Command:
{ $date --date="1 year" }
Output:
{ Thu Oct 11 00:11:38 PDT 2018 }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

6. -s or –set option: To set the system date and time -s or –set option is used.
Syntax:
{ $date --set="date to be set" }
Command:
{ $date }
Output:
{ Wed Oct 11 15:23:26 PDT 2017 }
Command:
{ $date --set="Tue Nov 13 15:23:34 PDT 2018"
$date }
Output:
{ Tue Nov 13 15:23:34 PDT 2018 }

7. –file or -f option: This is used to display the date string present at each line of file in the date and
time format.This option is similar to –date option but the only difference is that in –date we can only
give one date string but in a file we can give multiple date strings at each line.
Syntax:
{ $date --file=file.txt
$cat >>datefile
Sep 23 2018
Nov 03 2019 }
Command:
{ $date --file=datefile
Output:
Sun Sep 23 00:00:00 PDT 2018
Sun Nov 3 00:00:00 PDT 2019 }

8. -r option: This is used to display the last modified timestamp of a datefile .


Syntax:
{ $date -r file.txt }
We can modify the timestamp of a datefile by using touch command.
{ $touch datefile }
{ $date
Wed Oct 11 15:54:18 PDT 2017
//this is the current date and time
$touch datefile

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

//The timestamp of datefile is changed using touch command.


This was done few seconds after the above date command’s output.
{ $date
Wed Oct 11 15:56:23 PDT 2017
//display last modified time of datefile }

9. List of Format specifiers used with date command:


{ %D: Display date as mm/dd/yy.
%d: Display the day of the month (01 to 31).
%a: Displays the abbreviated name for weekdays (Sun to Sat).
%A: Displays full weekdays (Sunday to Saturday).
%h: Displays abbreviated month name (Jan to Dec).
%b: Displays abbreviated month name (Jan to Dec).
%B: Displays full month name(January to December).
%m: Displays the month of year (01 to 12).
%y: Displays last two digits of the year(00 to 99).
%Y: Display four-digit year.
%T: Display the time in 24 hour format as HH:MM:SS.
%H: Display the hour.
%M: Display the minute.
%S: Display the seconds. }

Syntax:
{ $date +%[format-option] }
Examples:
Command:
{ $date "+%D" }
Output:
{ 10/11/17 }
Command:
{ $date "+%D %T" }
Output:
{ 10/11/17 16:13:27 }
Command:
{ $date "+%Y-%m-%d" }
Output:
{ 2017-10-11 }
Command:
{ $date "+%Y/%m/%d" }
Output:
{ 2017/10/11 }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Command:
{ $date "+%A %B %d %T %y" }
Output:
{ Thursday October 07:54:29 17 }

BASIC FILTERS AND TEXT PROCESSING


1. awk
Awk is a remarkable pattern scanning and processing language, it can be used to build useful filters in
Linux. can start using it by reading through our Awk series Part 1 to Part 13.
Additionally, also read through the awk man page for more info and usage options:
{ $ man awk }

2. sed
sed is a powerful stream editor for filtering and transforming text. We’ve already written a two useful
articles on sed, that can go through it here:
How to use GNU ‘sed’ Command to Create, Edit, and Manipulate files in Linux
15 Useful ‘sed’ Command Tips and Tricks for Daily Linux System Administration Tasks
The sed man page has added control options and instructions:
{ $ man sed }
3. grep, egrep, fgrep, rgrep
These filters output lines matching a given pattern. They read lines from a file or standard input, and print
all matching lines by default to standard output.
Note: The main program is grep, the variations are simply the same as using specific grep options as
below (and they are still being used for backward compatibility):
{ $egrep = grep -E
$ fgrep = grep -F
$ rgrep = grep -r }
Below are some basic grep commands:
{ tecmint@TecMint ~ $ grep "aaronkilik" /etc/passwd
aaronkilik:x:1001:1001::/home/aaronkilik:
tecmint@TecMint ~ $ cat /etc/passwd | grep "aronkilik"
aaronkilik:x:1001:1001::/home/aaronkilik: }

4. head
head is used to display the first parts of a file, it outputs the first 10 lines by default. can use the -n num
flag to specify the number of lines to be displayed:
{ tecmint@TecMint ~ $ head /var/log/auth.log

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session closed for user root
Jan 2 10:51:34 TecMintsudo: tecmint : TTY=unknown ; PWD=/home/tecmint ; USER=root ;
COMMAND=/usr/lib/linuxmint/mintUpdate/checkAPT.py
Jan 2 10:51:34 TecMintsudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 2 10:51:39 TecMintsudo: pam_unix(sudo:session): session closed for user root
Jan 2 10:55:01 TecMint CRON[4099]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 10:55:01 TecMint CRON[4099]: pam_unix(cron:session): session closed for user root
Jan 2 11:05:01 TecMint CRON[4138]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 11:05:01 TecMint CRON[4138]: pam_unix(cron:session): session closed for user root
Jan 2 11:09:01 TecMint CRON[4146]: pam_unix(cron:session): session opened for user root by (uid=0)
}
{ tecmint@TecMint ~ $ head -n 5 /var/log/auth.log
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 2 10:45:01 TecMint CRON[3383]: pam_unix(cron:session): session closed for user root
Jan 2 10:51:34 TecMintsudo: tecmint : TTY=unknown ; PWD=/home/tecmint ; USER=root ;
COMMAND=/usr/lib/linuxmint/mintUpdate/checkAPT.py
Jan 2 10:51:34 TecMintsudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 2 10:51:39 TecMintsudo: pam_unix(sudo:session): session closed for user root }
5. tail :tail outputs the last parts (10 lines by default) of a file. Use the -n num switch to specify the
number of lines to be displayed.
The command below will output the last 5 lines of the specified file:
{ tecmint@TecMint ~ $ tail -n 5 /var/log/auth.log
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on :: port 22.
Jan 6 13:01:27 TecMintsshd[1269]: Received SIGHUP; restarting.
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on :: port 22. }
The following command will enable monitor changes in the specified file:
{ tecmint@TecMint ~ $ tail -f /var/log/auth.log
Jan 6 12:58:01 TecMintsshd[1269]: Server listening on :: port 22.
Jan 6 12:58:11 TecMintsshd[1269]: Received SIGHUP; restarting.
Jan 6 12:58:12 TecMintsshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 12:58:12 TecMintsshd[1269]: Server listening on :: port 22.
Jan 6 13:01:27 TecMintsshd[1269]: Received SIGHUP; restarting.
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on 0.0.0.0 port 22.

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Jan 6 13:01:27 TecMintsshd[1269]: Server listening on :: port 22.


Jan 6 13:01:27 TecMintsshd[1269]: Received SIGHUP; restarting.
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on 0.0.0.0 port 22.
Jan 6 13:01:27 TecMintsshd[1269]: Server listening on :: port 22. }
Read through the tail man page for a complete list of usage options and instructions:
{ $ man tail }

6. sort
sort is used to sort lines of a text file or from standard input.
Below is the content of a file named domains.list:
{ tecmint@TecMint ~ $ cat domains.list
tecmint.com
tecmint.com
news.tecmint.com
news.tecmint.com
linuxsay.com
linuxsay.com
windowsmint.com
windowsmint.com }
run a simple sort command to sort the file content like so:
{ tecmint@TecMint ~ $ sort domains.list
linuxsay.com
linuxsay.com
news.tecmint.com
news.tecmint.com
tecmint.com
tecmint.com
windowsmint.com
windowsmint.com }

7. uniq
uniq command is used to report or omit repeated lines, it filters lines from standard input and writes the
outcome to standard output.
After running sort on an input stream, can remove repeated lines with uniq as in the example below.
To indicate the number of occurrences of a line, use the -c option and ignore differences in case
{ tecmint@TecMint ~ $ cat domains.list

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

tecmint.com
tecmint.com
news.tecmint.com
news.tecmint.com
linuxsay.com
linuxsay.com
windowsmint.com }
tecmint@TecMint ~ $ sort domains.list | uniq -c
2 linuxsay.com
2 news.tecmint.com
2 tecmint.com
1 windowsmint.com e comparing by including the -i option: }
8. fmt
fmt simple optimal text formatter, it reformats paragraphs in specified file and prints results to the
standard output.
The following is the content extracted from the file domain-list.txt:
1.tecmint.com 2.news.tecmint.com 3.linuxsay.com 4.windowsmint.com
To reformat the above content to a standard list, run the following command with -w switch is used to
define the maximum line width:
{ tecmint@TecMint ~ $ cat domain-list.txt
1.tecmint.com 2.news.tecmint.com 3.linuxsay.com 4.windowsmint.com
tecmint@TecMint ~ $ fmt -w 1 domain-list.txt
1.tecmint.com
2.news.tecmint.com
3.linuxsay.com
4.windowsmint.com }

9. pr
pr command converts text files or standard input for printing. For instance on Debian systems, list all
installed packages as follows:
{ $dpkg -l }
To organize the list in pages and columns ready for printing, issue the following command.
{ tecmint@TecMint ~ $ dpkg -l | pr --columns 3 -l 20
2017-01-06 13:19 Page 1
Desired=Unknown/Install ii adduser ii apg
| Status=Not/Inst/Conf- ii adwaita-icon-theme ii app-install-data

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

|/ Err?=(none)/Reinst-r ii adwaita-icon-theme- ii apparmor


||/ Name ii alsa-base ii apt
+++-=================== ii alsa-utils ii apt-clone
ii accountsservice ii anacron ii apt-transport-https
ii acl ii apache2 ii apt-utils
ii acpi-support ii apache2-bin ii apt-xapian-index
ii acpid ii apache2-data ii aptdaemon
ii add-apt-key ii apache2-utils ii aptdaemon-data
2017-01-06 13:19 Page 2
ii aptitude ii avahi-daemon ii bind9-host
ii aptitude-common ii avahi-utils ii binfmt-support
ii apturl ii aview ii binutils
ii apturl-common ii banshee ii bison
ii archdetect-deb ii baobab ii blt
ii aspell ii base-files ii blueberry
ii aspell-en ii base-passwd ii bluetooth
ii at-spi2-core ii bash ii bluez
ii attr ii bash-completion ii bluez-cups
ii avahi-autoipd ii bc ii bluez-obexd
.....}The flags used here are:
--column defines number of columns created in the output.
-l specifies page length (default is 66 lines).

10. tr
This tool translates or deletes characters from standard input and writes results to standard output.
The syntax for using tr is as follows:
{ $ tr options set1 set2 }
Take a look at the examples below, in the first command, set1( [:upper:] ) represents the case of input
characters (all upper case).
Then set2([:lower:]) represents the case in which the resultant characters will be. It’s same thing in the
second example and the escape sequence \n means print output on a new line:
{ tecmint@TecMint ~ $ echo "WWW.TECMINT.COM" | tr [:upper:] [:lower:]
www.tecmint.com
tecmint@TecMint ~ $ echo "news.tecmint.com" | tr [:lower:] [:upper:]

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

11. more
more command is a useful file perusal filter created basically for certificate viewing. It shows file content
in a page like format, where users can press [Enter] to view more information.
can use it to view large files like so:
{ tecmint@TecMint ~ $ dmesg | more
[ 0.000000] Initializing cgroupsubsyscpuset
[ 0.000000] Initializing cgroupsubsyscpu
[ 0.000000] Initializing cgroupsubsyscpuacct
[ 0.000000] Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 20160413 (Ubuntu
5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 (Ubuntu 4.4.0-21.37-generic
4.4.6)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.4.0-21-generic root=UUID=bb29dda3-
bdaa-4b39-86cf-4a6dc9634a1b ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x01: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x02: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x04: 'AVX registers'
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[ 0.000000] x86/fpu: Using 'eager' FPU context switches.
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d3ff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009d400-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000a56affff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000a56b0000-0x00000000a5eaffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000a5eb0000-0x00000000aaabefff] usable
--More--NEWS.TECMINT.COM } }

12. less
less is the opposite of more command above but it offers extra features and it’s a little faster with large
files.
Use it in the same way as more:
{ tecmint@TecMint ~ $ dmesg | less

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

[ 0.000000] Initializing cgroupsubsyscpuset


[ 0.000000] Initializing cgroupsubsyscpu
[ 0.000000] Initializing cgroupsubsyscpuacct
[ 0.000000] Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 20160413 (Ubuntu
5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 (Ubuntu 4.4.0-21.37-generic
4.4.6)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.4.0-21-generic root=UUID=bb29dda3-
bdaa-4b39-86cf-4a6dc9634a1b ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x01: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x02: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x04: 'AVX registers'
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[ 0.000000] x86/fpu: Using 'eager' FPU context switches.
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d3ff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009d400-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000a56affff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000a56b0000-0x00000000a5eaffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000a5eb0000-0x00000000aaabefff] usable
:}
BASIC FILE COMPRESSION COMMANDS
Both Linux and UNIX include various commands for Compressing and decompresses (read as expand
compressed file). To compress files can use gzip, bzip2 and zip commands. To expand compressed file
(decompresses) can use and gzip -d, bunzip2 (bzip2 -d), unzip commands.
Compressing files

Syntax Description Example(s)


Gzip compress the size of the gzip mydata.doc
Gzip {Filename}
given files using Lempel-Ziv
coding (LZ77). Whenever gzip *.jpg
possible, each file is replaced
ls –l
by one with the extension .gz.

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

bzip2 {filename} bzip2 compresses files using bzip2 mydata.doc


the Burrows-Wheeler block
bzip2 *.jpg
sorting text compression
algorithm, and Huffman ls –l
coding. Compression is
generally considerably better
than that achieved by bzip
command (LZ77/LZ78-
based compressors).
Whenever possible, each file
is replaced by one with the
extension .bz2.
zip {.zip-filename} zip is a compression and file zip mydata.zip mydata.doc
{filename-to-compress} packaging utility for
zip data.zip *.doc
Unix/Linux. Each file is
stored in single .zip {.zip- ls –l
filename} file with the
extension .zip.
tar -zcvf {.tgz-file} {files} The GNU tar is archiving tar -zcvf data.tgz *.doc
utility but it can be use to
tar -jcvf{.tbz2-file} {files} tar -zcvf pics.tar.gz *.jpg
compressing large file(s).
*.png
GNU tar supports both
archive compressing through tar -jcvfdata.tbz2 *.doc
gzip and bzip2. If have
more than 2 files then it is ls –l
recommended to use tar
instead of gzip or bzip2.
-z: use gzip compress
-j: use bzip2 compress

Decompressing files

Syntax Description Example(s)


gzip -d {.gz file} Decompressed a file that is gzip -d mydata.doc.gz
created using gzip
gunzip {.gz file} gunzip mydata.doc.gz
command. File is restored to
their original form using this
command.
bzip2 -d {.bz2-file} Decompressed a file that is bzip2 -d mydata.doc.bz2
created using bzip2
bunzip2 {.bz2-file} gunzip mydata.doc.bz2
command. File is restored to
their original form using this
command.
unzip {.zip file} Extract compressed files in a unzip file.zip
ZIP archive.
unzip data.zip resume.doc

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

tar -zxvf {.tgz-file} Untar or decompressed a tar -zxvf data.tgz


file(s) that is created using
tar -jxvf{.tbz2-file} tar -zxvf pics.tar.gz *.jpg
tar compressing through
gzip and bzip2 filter tar -jxvfdata.tbz2

List the contents of an archive/compressed file: Some time just wanted to look at files inside
an archive or compressed file. Then all of the above command supports file list option.

Syntax Description Example(s)


gzip -l {.gz file} List files from a GZIP gzip -l mydata.doc.gz
archive
unzip -l {.zip file} List files from a ZIP archive unzip -l mydata.zip

tar -ztvf{.tar.gz} List files from a TAR tar -ztvf pics.tar.gz


archive
tar -jtvf{.tbz2} tar -jtvfdata.tbz2

MISCELLANEOUS: apt-get command with Examples


apt-get is a command-line tool which helps in handling packages in Linux. Its main task is to retrieve the
information and packages from the authenticated sources for installation, upgrade and removal of packages
along with their dependencies. Here APT stands for the Advanced Packaging Tool.
Syntax:
{ apt-get [options] command
or
apt-get [options] install|remove pkg1 [pkg2 ...]
or
apt-get [options] source pkg1 [pkg2 ...] }
update : This command is used to synchronize the package index files from their sources again. need to
perform an update before upgrade or dist-upgrade.
{ apt-get update }
upgrade : This command is used to install the latest versions of the packages currently installed on the
user’s system from the sources enumerated in /etc/apt/sources.list. The installed packages which have new
packages available are retrieved and installed. need to perform an update before the upgrade, so that apt-
get knows that new versions of packages are available.
{ apt-get upgrade }
dselect-upgrade : This is used alongwith the Debian packaging tool, dselect. It follows the changes made
by dselect to the Status field of available packages, and performs any actions necessary to realize that state.
{ apt-get dselect-upgrade }
dist-upgrade : This command performs the function of upgrade, and also handles changing dependencies
with new versions of packages. If necessary, the apt-get command will try to upgrade important packages
at the expense of less important ones. It may also remove some packages in this process.
{ apt-get dist-upgrade }
Sir C. R. Reddy College of Engineering Dept. of Information Technology
I.T Work shop (ES1105) Page No: ______

install : This command is used to install or upgrade packages. It is followed by one or more package names
the user wishes to install. All the dependencies of the desired packages will also be retrieved and installed.
The user can also select the desired version by following the package name with an ‘equals’ and the desired
version number. Also, the user can select a specific distribution by following the package name with a
forward slash and the version or the archive name (e.g. ‘stable’, ‘testing’ or ‘unstable’). Both of these
version selection methods have the potential to downgrade the packages, so must be used with care.
{ apt-get install [...PACKAGES] }
remove : This is similar to install, with the difference being that it removes the packages instead of
installing. It does not remove any configuration files created by the package.
{ apt-get remove [...PACKAGES] }
purge :This command removes the packages, and also removes any configuration files related to the
packages.
{ apt-get purge [...PACKAGES] }
check : This command is used to update the package cache and checks for broken dependencies.
{ apt-get check }
download : This command is used to download the given binary package in the current directory.
{ apt-get download [...PACKAGES] }
clean : This command is used to clear out the local repository of retrieved package files. It removes
everything but not the lock file from /var/cache/apt/archives/partial/ and /var/cache/apt/archives/.
{ apt-get clean }
autoremove : Sometimes the packages which are automatically installed to satisfy the dependencies of
other packages, are no longer needed then autoremove command is used to remove these kind of packages.
{ apt-get autoremove }
Options:
–no-install-recommends : By passing this option, the user lets apt-get know not to consider recommended
packages as a dependency to install.
{ apt-get --no-install-recommends [...COMMAND] }
–install-suggests : By passing this option, the user lets apt-get know that it should consider suggested
packages as dependencies to install.
{ apt-get --install-suggests [...COMMAND] }
-d or –download-only : By passing this option, the user specifies that apt-get should only retrieve the
packages, and not unpack or install them.
{ apt-get -d [...COMMAND] }
-f or –fix-broken : By passing this option, the user specifies that apt-get should attempt to correct the
system with broken dependencies in place.
{ apt-get -f [...COMMAND] }
-m or –ignore-missing or –fix-missing : By passing this option, the user specifies that apt-get should
ignore the missing packages ( packages that cannot be retrieved or fail the integrity check ) and handle the
result.
{ apt-get -m [...COMMAND] }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

–no-download : By passing this command, the user disables downloading for apt-get. It means that it
should only use the .debs it has already downloaded.
{ apt-get [...COMMAND] }
-q or –quiet : When this option is specified, apt-get produces output which is suitable for logging.
{ apt-get [...COMMAND] }
-s or –simulate or –just-print or –dry-run or –recon or –no-act : This option specifies that no action
should be taken, and perform a simulation of events that would occur based on the current system, but do
not change the system.
{ apt-get -s [...COMMAND] }
-y or –yes or –assume-yes : During the execution of apt-get command, it may sometimes prompt the user
for a yes/no. With this option, it is specified that it should assume ‘yes’ for all prompts, and should run
without any interaction.
{ apt-get -y [...COMMAND] }
–assume-no :With this option, apt-get assumes ‘no’ for all prompts.
{ apt-get --assume-no [...COMMAND] }
–no-show-upgraded : With this option, apt-get will not show the list of all packages that are to be
upgraded.
{ apt-get --no-show-upgraded [...COMMAND] }
-V or –verbose-versions : With this option, apt-get will show full versions for upgraded and installed
packages.
{ apt-get -V [...COMMAND] }
–show-progress : With this option, apt-get will show user-friendly progress in the terminal window when
the packages are being installed, removed or upgraded.
{ apt-get --show-progress [...COMMAND] }
-b or –compile or –build : With this option, apt-get will compile/build the source packages it downloads.
{ apt-get -b [...COMMAND] }
–no-upgrade : With this option, apt-get prevents the packages from being upgraded if they are already
installed.
{ apt-get --no-upgrade [...COMMAND] }
–only-upgrade : With this option, apt-get will only upgrade the packages which are already installed, and
not install new packages.
{ apt-get --only-upgrade [...COMMAND] }
–reinstall : With this option, apt-get reinstalls the packages that are already installed, at their latest versions.
{ apt-get --reinstall [...COMMAND] }
–auto-remove or –autoremove : When using apt-get with install or remove command, this option acts like
running the autoremove command.
{ apt-get install/remove --autoremove [...PACKAGES] }
-h or –help : With this option, apt-get displays a short usage summary.
{ apt-get -h }

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Output:

-v or –version : With this option, apt-get displays it’s current version number.
{ apt-get [...COMMAND] }

Output:

Vi editor
The VI editor is the most popular and classic text editor in the Linux family. Below, are some reasons
which make it a widely used editor –
• It is available in almost all Linux Distributions
• It works the same across different platforms and Distributions
Sir C. R. Reddy College of Engineering Dept. of Information Technology
I.T Work shop (ES1105) Page No: ______

• It is user-friendly. Hence, millions of Linux users love it and use it for their editing needs
• Nowadays, there are advanced versions of the vi editor available, and the most popular one is VIM
which is Vi Improved. Some of the other ones are Elvis, Nvi, Nano, and Vile. It is wise to learn vi
because it is feature-rich and offers endless possibilities to edit a file.
• To work on VI editor, need to understand its operation modes. They can be divided into two main
parts.

Command mode
• The vi editor opens in this mode, and it only understands commands
• In this mode, can, move the cursor and cut, copy, paste the text
• This mode also saves the changes have made to the file
• Commands are case sensitive. should use the right letter case.

Insert mode
• This mode is for inserting text in the file.
• can switch to the Insert mode from the command mode by pressing 'i' on the keyboard.
• Once are in Insert mode, any key would be taken as an input for the file on which are currently
working.
• To return to the command mode and save the changes have made need to press the Esc key.

Starting the vi editor


To launch the VI Editor -Open the Terminal (CLI) and type
{ vi<filename_NEW> or <filename_EXISTING> }
&If specify an existing file, then the editor would open it for to edit. Else, can create a new file.

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Creating a new file

Vi editor opens in the command


mode

Press “I” to enter the insert mode

Add content

Press esc to enter command


mode. prees

Check the content of file

Sir C. R. Reddy College of Engineering Dept. of Information Technology


I.T Work shop (ES1105) Page No: ______

Vi editor commands:
Note: Should be in the "command mode" to execute these commands. VI editor is case-sensitive type the
commands in the right letter-case.
Keystrokes Action
i Insert at cursor (goes into insert mode)
a Write after cursor (goes into insert mode)
A Write at the end of line (goes into insert mode)
ESC Terminate insert mode
u Undo last change
U Undo all changes to the entire line
o Open a new line (goes into insert mode)
dd Delete line
3dd Delete 3 lines.
D Delete contents of line after the cursor
C Delete contents of a line after the cursor and insert new text. Press
ESC key to end insertion.
dw Delete word
4dw Delete 4 words
CW Change word
X Delete character at the cursor
r Replace character
R Overwrite characters from cursor onward
s Substitute one character under cursor continue to insert
S Substitute entire line and begin to insert at the beginning of the line
~ Change case of individual character
Make sure press the right command otherwise will end up making undesirable changes to the file. Also
enter the insert mode by pressing a, A, o, as required.
Moving within a file: need to be in the command mode to move within a file. The default keys for
navigation are mentioned below else; also use the arrow keys on the keyboard.
keystroke Use
Shift+zz Save the file and quit
:w Save the file but keep it open
:q Quit without saving
:wq Save the file and quit

Sir C. R. Reddy College of Engineering Dept. of Information Technology

You might also like