Linux Com Ds
Linux Com Ds
cal Command
to see calender for any specific month or a complete year
usage: cal [month] [year]
eg: cal sep 2010
date prints the date and time
date +"%D %H: %M: %S"
09/14/10 14: 19: 43
Options:
d The
date of the month (131)
y The
last two digits of the year
H,M,S Hour
Minute and second respectively
D the
date in mm/dd/yy
echo: Print message on the terminal
usage: echo <message>
eg: echo "Welcome to the workshop"
o/p: Welcome to the workshop
passwd allows
you to change your password
man displays the documentation for a command
usage: man <command name>
eg: man mkdir
Shell Metacharacters
Metacharacters These
are special characters that are recognised by the shell.
* matches
0 or more characters.
eg: ls *.c
? matches
Appends
standard output to a file.
eg: echo Hello Again >> hello.txt
< Takes
standard input from a file
| This
is pipe character. Sends the output of first command as
input for the
second command.
File System Commands
mkdir make directory
usage: mkdir <dirname>
eg: mkdir p
path/test/test1
p
>
name
Removes directories and files within the directories
recursively.
File Handling Commands
cat used
to display the contents of a small file on terminal
usage: cat <file name>
cat when supplied with more than one file will concatenate
the files without
any header information
more and less commands are used to view large files
one page at a time
usage: more <file name>
usage: less <file name>
wc command is used to count lines, words and
characters, depending on the
option used.
usage: wc [options] [file name]
You can just print number of lines, number of words or
number of charcters
by using following options:
l
: Number of lines
w
: Number of words
c
: Number of characters
Filters
Filters are commands which accept data from standard
input, manupulate it
and write the results to standard output.
Head displays
the lines at the top of the file
when
used without any option it will display first 10 lines of the
file
usage: head filename
n
>
print the first N lines instead of the first 10
tail displays
the lines at the end of the file. By default it will display last
10
lines of the file
usage: tail filename
With f
option you can cut the feilds delemited by some character
eg: cut d:
f2
/etc/passwd
d
option is used to specify the delimiter and f
option used to specify the
feild number
paste command will paste the contents of the file side
by side
eg: paste a.txt b.txt
Ordering a file
sort reorders
lines in the file
whitespaces first, then numerals, uppercase and finally
lowercase
you can sort the file based on a field by using t
and k
option.
Eg: sort t"
"k
2 students.txt
sorts the file based on the second field using the delimiter
as space
r
>reverses the result
grep '[FG]oo' *
grep '[09][
09][
09]'
*
grep '^fred' /etc/passwd
sed
sed editor
for filtering and transforming text
i
>
edit the files in place
sed i
'1,10d' hello.txt
deleted the first 10 lines from hello.txt
sed i
2i hai hello.txt
Inserts the text hai in the second line
sed i
'/hello/d' hello.txt
Deleted the line containing the pattern hello.
sed 's/hello/world/' hello.txt
Replaces the first occurrence of hello on each line to
world.
sed 's/hello/world/g' hello.txt
Linux Commands
pwd print
working directory
will show you the full path to the directory you are currently
in.
shred overwrite
a file to hide its contents
The result is that your file is so thoroughly deleted it is very
unlikely to ever be
retrieved again.
ln s
test symlink
Creates a symbolic link named symlink that points to the
file test
free Displays
the amount of used and free system memory
w show who is logged on and what they are doing
usage: w
who show
who is logged in
usage: who
who b
>
last system boot time
"FILETOFIND"
exec
rm rf
{} \;
lspci a
utility for displaying information about PCI buses in the
system and devices connected to them.
v
displays a detailed information.
lsusb a utility for displaying information about USB
buses in the
system and the devices connected to them.
v
displays a detailed information.
lshw list
the hardware
hwinfo probs for the hardware
cat /proc/cpuinfo gives information about cpu
cat /proc/meminfo gives
information about memory
ps command
ps (i.e., process status) command is used to provide
information about the
currently running processes, including their process
identification numbers
(PIDs).
ps lists all the processes
usage: ps aux
Task Automation
Cron is the name of program that enables linux users
to execute commands
or scripts (groups of commands) automatically at a
specified time/date.
You can setup setup commands or scripts, which will
repeatedly run at a set
time.
The cron service (daemon) runs in the background and
constantly checks the
/etc/crontab file, /etc/cron.*/ directories.
It also checks the /var/spool/cron/ directory.
To edit the crontab file, type the following command at
the Linux shell
prompt:
crontab e
Syntax of crontab (Field Description)
m h dom mon dow /path/to/command arg1 arg2
where
m: Minute (059)
h: Hours (023)
dom: Date (031)
mon: Month (012
[12 == December])
dow: week days(07
[0 or 7 sunday])
/path/to/command Script
or command name to schedule
If you wished to have a script named /root/backup.sh run
every day at 3am,
your crontab entry would look like as follows:
0 3 * * * /root/backup.sh
Execute every minute
* * * * * /bin/script.sh
This script is being executed every minute.
Execute every Friday 1AM
To schedule the script to run at 1AM every Friday, we
would need the following
cronjob:
0 1 * * 5 /bin/execute/this/script.sh
The script is now being executed when the system clock
hits:
1. minute: 0
2. of hour: 1
3. of day of month: * (every day of month)
4. of month: * (every month)
5. and weekday: 5 (=Friday)
D (uppercase)
Replacing Characters
To replace one character with another:
1. Move the cursor to the character to be replaced.
2. Type r
3. Type the replacement character.
The new character will appear, and you will still be in
command mode.
Replacing Words
To replace one word with another, move to the start of the
incorrect word and
type
cw
You are now in insert mode and may type the
replacement. The new text does
not need to be the same length as the original. Press
<Esc> to get back to
command mode. To replace three words, type
3cw
Replacing Lines
To change text from the cursor position to the end of the
line:
1. Type C (uppercase).
2. Type the replacement text.
3. Press <Esc>.
Moving around in a file
H to top line of screen
M to middle line of screen
L to last line of screen