Thursday

Zipping Files

Command Options Description
1. gzip gzip etl_code
eg:etl_code.gz
 
  gunzip etl_code.gz
eg: etl_code
 
  zip file*sql
eg: file.zip
 
  unzip file.zip
eg:file*sql
 

   
2. tar   create backup of files recursively.
  -cvf
eg :tar -cvf /home/gagan/sqlbackup ./*.sql
 
  - x
eg:tar-xcvf /home/gagan/sqlbackup ./*.sql
files are restored using -x option.
 
 

3. Cut
-c <column start and no>

eg : cut -c -5,6-12 test file
column (by specifying position). C stands for column cut.
  -f <field start and end no>

eg:cut -f 1,5 test file
field (default deliminator tab). F stands for field cut.
  '-d -f <field start and end no>

eg: cut -d "|" -f 1,5 test file | new file
Cut the field b/w 1 and 5 and piped the output to new file.
     
4. sort sort test file By default the sorting starts with first character of each line. Priority1.space, tabs 2. numerals 3.uppercase letters 4. Lower case letters.
  -t
eg : sort -t "|" +2 test file
Sorting starts from 3rd field skipping 2nd field, overring the default.delimiter to distinguish b/w start and end of field.
  -r
eg : sort -t \| -r +2 test file
Reverse sort starting with 3rd field.
  eg : sort -t \|  +2r test file The above command can be written in another way.
  -o
eg : sort -o abc.txt abc_sort.txt
save sorted data in file.
  eg : sort -t "|" +1 -2 +3 <> Sorting based on different field as in case of order by clause.Sorting starts with 2nd field then with 4th field, -2 indicate to stop the sorting after 2nd field and resume it with 3rd field.
  -n
eg : sort -n <>
Numeric sort.
  -u
eg : sort -u <>
Unique sort.
     
5.paste -d

eg:paste -d "|" <> <>
deliminator.

   
6.tr eg : tr '|\' '~-' <test.txt translate all | with ~ and \ with - .
  eg : tr '[a-z]' '[A-Z] <test.txt translate to upper case.
  -d
eg : tr -d '|' test.txt
delete all occurrence of | .
 
 
7.uniq   Unique require sorted file as input.
-u

eg : cut -d "|" -f3 <>|sort|uniq -u
remove duplicate.
  -d

eg: cut -d "|" -f3 <>|sort|uniq -d
select only dup records.
  -c

eg : cut -d "|" -f3|sort|uniq -c
duplicate  count.
     
8.Changing time stamp   touch mon date hrs mins <file>.
ls -lt time of last modification touch -m 01290430 <file>.
ls -lu time of last access touch -a 01290415 <file>.
   
9.Change Date date 09181754  
     
10.wall wall -g dba "hello" to selectively send msg to dba group.
     
11.shutdown shutdown -g2 power down after 2 mins.
  shutdown -y -g0 immediate shutdown.
  shutdown -y -g0 -i6 shutdown and reboot (init level 6).
  shutdown 17:30 shutdown at 17:30.
  shutdown -r now shutdown immediate and reboot.
     
12. du   Disk usage.
  du /home/expimp/create_db tree output for each directory inside.
  du -s //home/expimp/create_db summary.
     
13.find find <loc> <option> <pattern> <action> find in root dir abc in emp.lst file
  '-mtime = mod time
eg: find . -mtime -2 -print
find file modi in less then 2 days.
  'atime = access time
eg: find . -atime +365 -print
find the file not accessed in last 1 year.
  ! –newer
eg: find / -name "*.pl" ! -newer last_backup -print
file modi before last_backup.
  -size.
eg: find . -size +2048 -print
files greater then x blocks.
  -a (and) -o (OR)
eg: find . \( -name "*.sh" -o -name "*.lst" \) -print
double quotes necessary.
  -exec
eg: find . -atime +180 -ok rm -f {} \;
remove the files which are not modi for last 20 days
  -ok
eg: find . -atime +180 -ok rm -f {} \;
before removing prompt for confirmation.
  xargs
eg: find . -mtime +20 | xargs rm -f
remove all file rm will be executed only once.
  xargs -n -p –t
eg:find . -mtime +20 | xargs -n20 -p -t rm -f
remove at max 20 files in batch and in interactive mode.
  -type
eg: find / -name log -type f -print
f for file and d for directory.
  -prune
eg: find . -name *.log -prune exe –print.
don't descend exe directory.

No comments :

Post a Comment

Recent Comments