UNIX TIPS

Notes taken from daily job. These are the most commonly used when i'm with unix shell.
I know these things are not in the order and etc.. I just maintained the order i explored these options 
Please fell free to feedback if any issues

1) Is there a way where we can get some feedback once a command is executed in shell. Like 1/0 ..etc ??
UNIX>cd vij_test_dir
vij_test_dir: No such file or directory.
UNIX> echo $?
1
UNIX> mkdir vij_test_dir
UNIX>cd vij_test_dir
UNIX>echo $?
0
UNIX>cd vijay_test
after every command try : echo $?
if 0 ==> success
if nonzero ==> failed

2) How to copy from once machine to another machine without logging in?
UNIX> scp user_name@unix0420:/tmp/user_name/fmly_latest_local_gdsgen/  ./
UNIX> scp fmci201356.fm.intel.com:/tmp/user_name/a.ot ./
##this will be more faster (if we have data in specific machine/or use scp based on a specific login in which we already have a session running)

3) How to monitor the end of log file always (file which is getting a log dump from a run which is in progress)
  UNIX> tailf <FILE_NAME>

4) How to check for any syntax errors in a perl script ?
UNIX> perl -c <program_file>

5) Cron job : to run any job automated or overnight job fires ?
Cron jobs are machine specific, If we create a cron job on say machine "abc123" : then we should log into to "abc123" machine (ssh abc123) and then udpate as required.
Having said that you won’t be able to see your own cron jobs of machine abc123 without doing "ssh" to abc123 machine.
UNIX> crontab -e
Syntax:
0 8 * * 1-5 <file_which_has_list_of_commands>
This is like execute the script at 8am sharp (8am 0 min  1-5 means five days a week)
Eg:
UNIX> crontab -e
0 8 * * 1-5 <file_which_has_list_of_commands>
Save and exit ==> this will run the script on five days at 8am forever

6) How to monitor stale data (in GB) by a specific user ?
stodstatus storage-users --fields "User,Path,Usage/1024,Age180/1024" "User=='user_name'&&Age180>'10'"

7) copy command ?
How to copy real content instead of symbolic links while performing copy operations on a database which has links ?
  UNIX> cp -rHL <directory_name> .
UNIX> cp - u  --> will only copy files that don't exist, or are newer than their existing counterparts, in the destination directory.

8) One-Line Technique for Mailing a File's Contents ?
If you have a file called apple.txt and you want to mail its contents as a mail message to nobody@december.com with the subject line "unix-asg1,"
you can do this at the Unix prompt like this:
mail -s "unix-asg1" nobody@december.com < apple.txt
This is very useful if you are a Unix shell and you don't want to enter your mail program.
Note: this may not work on all Unix systems. If this doesn't work, follow this example to mail a file's contents.
A One-Line Technique for a Mailing a Short Message
You can use the echo command to send a short text message in one line. 
Say you want to send the message "City Hall 1pm" to nobody@december.com with the subject line "meeting today" by email. 
You can do it at the Unix prompt like this:
echo "City Hall 1pm" | mail -s "meeting today" nobody@december.com

9) How to cutout first column or till first : comes and prints the rest to std out ?
cut -f 1 -d ":" –complement

10) To keep a banner like below in unix use "banner" command and arguments following:
UNIX> banner malli
#     #     #     #        #        ### 
##   ##    # #    #        #         #  
# # # #   #   #   #        #         #  
#  #  #  #     #  #        #         #  
#     #  #######  #        #         #  
#     #  #     #  #        #         #  
#     #  #     #  #######  #######  ### 

11) Copy all but except one directory  ?
UNIX> cd source_path
UNIX> cp -rv `ls -A source_path | grep -vE "directory to be excluded | source_path"`  destination_path
eg: source_path --> /tmp/amallika/delete
    destination_path -->  /tmp/amallika/temp
    cp -rv `ls -A /tmp/amallika/delete | grep -vE "dbs|/tmp/amallika/delete"` /tmp/amallika/temp

12) To use date command inside echo: (nested commands)
UNIX> echo `date`
`date` will just return the output of the date command. However, it removes extra space characters at places where there are more than one consecutive space characters in the output.
In "`date`", the double quotes are weak quotes, so they will expand variables (try "$PWD") and perform command substitution.
In '`date`', the single quotes are stronger quotes, so they will not allow expansion of variables or command substitution within them.
Example :
UNIX> echo '$PWD'
$PWD
UNIX> echo "$PWD"
/tmp/amallika/delete

13) CTRL + L ==> clears the screen (same as clear)

14) wc command ?
wc has options to only show character (-c), word (-w), or line (-l) counts.
Example of a file user_name:
UNIX> wc user_name
648   5190 132507 user_name
UNIX> wc -l user_name
648 user_name
UNIX> wc -c user_name
132507 user_name
UNIX> wc -w user_name
5190 user_name

15) AWK command ? 
Awk is one of the most powerful tools in Unix used for processing the rows and columns in a file. 
Awk has built in string functions and associative arrays.
Awk supports most of the operators, conditional blocks, and loops available in C language.
One of the good things is that you can convert Awk scripts into Perl scripts using a2p utility. 
The awk variable $1 contains the first field in a record, $2 the second, $3 the third, etc. $0 contains all fields.
To print second last and last field respectively: $(NF-1)and $(NF). NF signifies the number of fields
Eg: awk 'BEGIN {start_action} {action} END {stop_action}' filename
  Here the actions in the begin block are performed before processing the file and the actions in the end block are performed after processing the file. The rest of the actions are performed while processing the file.
  UNIX> awk '{print $1}' file_name > amr
This will print only 1st column of the file into the amr file
This will print 3rd and 6th columns only  :  
UNIX> awk ‘{print $3,$6}’ file_in > file_out

##in awk use  below options format
conditions { actions }
##use a following sample to illustrate the above command
UNIX> awk '$1 ~ /[0-9]/ {print $0}' test
asdfdsafdsa(123)432-1421(432)412-34321vasdf
kjhkjh(123)432-143214asdf
## if there is a string with "arjun:malli" in the second column of a file "test.rpt"
UNIX> awk '{print $2}' test.rpt |  awk -F :  '{print $1'
This will give output as arjun

FS or -F is a field separator option of AWK that can be used to filter based on specific fields.. Like in the above example using :
To sum contents in column using awk:
UNIX> awk '{sum += $1} END {print sum}' delete
3830
To print even lines from a file
UNIX> awk 'NR % 2 ' file_name


16) top command ?
# Print  system usage and top resources hogs
UNIX> top
Then use "z" to toggle the coloring of this result

17) ZIP related ?
"gzip" or "gzip -r"  ==> compresses
"gunzip" "gunzip -r" ==> decompresses.
(gunzip is the same as gzip -d)
Examples: 
UNIX> ls logs
a.log b.log
UNIX> gzip logs
gzip: logs is a directory -- ignored
UNIX> gzip -r logs
UNIX> gunzip logs/
gzip: logs/ is a directory -- ignored
UNIX> gunzip -r logs/

18) We can create a function in .cshrc file to do the repetitive tasks !!
i) Like to change the file to executable and also to add a comment in that file
##add the below lines in .cshrc file
function  func_add_cmnt_chgrp {
sed -i  '1s/^/#!\/usr\/bin\/perl\n\n/' $1
chmod  +x $1
chgrp -R impr_group *
}

19) \ operator ?
It can be used as a command extension into next line in UNIX awk/sed etc.. commands.
Also \ can be used in tcl as command extension into next line.

20) cat and tac !! ??
UNIX> cat test.log
--> contents are printed on prompt in regular order (first line to last line)
UNIX> tac test.log
--> contents are printed on prompt in reverse order (last line to first line) 
--> page through a log file in reverse to avoid guessing number of lines to tail
21) dos file format to unix file format ? if there any file format issues once you copied it from windows environment ?
UNIX> dos2unix file_name
To remove ^M  kind of dummy char when a file is exported from windows to unix

22) process status command options (ps ) ?? 
PS [process status] :
To see every process on the system using standard syntax:
  ps -e
  ps -ef
  ps -eF
  ps -ely
To see every process on the system using BSD syntax:
  ps ax
  ps axu
To print a process tree:
  ps -ejH
  ps axjf
To get info about threads:
  ps -eLf
  ps axms
To get security info:
  ps -eo euser,ruser,suser,fuser,f,comm,label
  ps axZ
  ps -eM
To see every process running as root (real & effective ID) in user format:
  ps -U root -u root u
To see every process with a user-defined format:
  ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
  ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
  ps -eopid,tt,user,fname,tmout,f,wchan
Print only the process IDs of syslogd:
  ps -C syslogd -o pid=
Print only the name of PID 42:
  ps -p 42 -o comm=
commands to identify the particular tool and kill/manage
 ps -elf | grep user_name | grep gena
 ps -elf | grep user_name | grep w
 ps -elf | grep user_name

23) g and Esc+P @ UNIX SHELL will give the recent history of commands that start with g

24) SED (stream line editor ) ?
##This will delete the lines whick are having(corresponding) abc in the clk.tcl file
sed –i ‘/abc/d’ clk.tcl
## This will delete every 2nd line starting from 2ndline##
sed '2~2d' temp2 > temp3
## this will delete the 3rd line from the file temp2
sed 3d temp2
###Remove the interval between lines 7 and 9:
sed '7,9d' filename.txt
####Remove the line containing the string "awk":
sed '/awk/d' filename.txt
###Remove the last line:
sed '$d' filename.txt
###Remove all empty lines:
sed '/^$/d' filename.txt      
sed '/./!d' filename.txt
###Remove the line matching by a regular expression (by eliminating one containing digital characters, at least 1 digit, located at the end of the line):
sed '/[0-9/][0-9]*$/d' filename.txt
  Some more SED  examples :
• With and Without -n option:
UNIX> ls -l | sed -e '/^d/ p'
total 184
-rwxr-x--- 1 user_name coe73 91636 2015-04-17 14:07 test.tcl
drwxr-x--- 8 user_name coe73 12288 2015-06-03 23:21 lane_new_fp_expt
drwxr-x--- 8 user_name coe73 12288 2015-06-03 23:21 lane_new_fp_expt
-rwxr-x--- 1 user_name coe73    28 2015-06-21 20:27 sed.in
-rwxr-x--- 1 user_name coe73   864 2015-06-19 22:11 xaa
UNIX> ls -l | sed -n -e '/^d/ p'
drwxr-x--- 8 user_name coe73 12288 2015-06-03 23:21 lane_new_fp_expt
By default sed will print all lines to stdout if we use -e. But if you want to see specific lines that were matched using the
regexp use -n.
Other SED examples:
UNIX> sed -e '/pattern/ command' file_name
Command can be s (search & replace), d (Delete), p (print) , i(insert) & a (append)
Ex :
To delete all lines in a file that are starting with #
UNIX> sed -e '/^#/ d' file_name ;
Make of use SED/AWK extensively when the files are big. Since opening vim/another editor and doing that is bit difficult/time consuming
To delete 1 to 100 lines in a file
UNIX> sed -e '1,100 d' file_name
To delete 11  to  end of file (EOF)
UNIX> sed -e '11,$ d' file_name
Capitalize all vowels in a file:
UNIX> sed 'y/aeiou/AEIOU/' somefile

Example of cat and sed :
UNIX> cat 1
freeze ing life yaar:wq
hello hello
hello :wq
bolo i am vccsus_1p05
UNIX> sed -e 's/hello/malli/' 1
freeze ing life yaar:wq
malli hello
malli :wq
bolo i am vccsus_1p05
UNIX> sed -e 's/hello/malli/g' 1
freeze ing life yaar:wq
malli malli
malli :wq
bolo i am vccsus_1p05
==> -e will just gives us -echo output on the screen and we can redirect this to a new file.
But if you want to modify the file "1" on the fly (like overwriting) then you should use -I (inplace option of sed)
UNIX> sed -i 's/hello/malli/' 1
UNIX> cat 1
freeze ing life yaar:wq
malli hello
malli :wq
bolo i am vccsus_1p05
##to replace a 10 digit number in the telephone notation format:
##that is to replace 9986535417 as (998)653-5417
UNIX> sed -i 's/\([0-9]\{3\}\)\([0-9]\{3\}\)\([0-9]\{4\}\)/(\1)\2-\3/g' test
##to trim leading edge white space using sed
UNIX> sed -i 's/^[ \t]*//g' test
##to trim trailing whitespaces in a file
UNIX> sed -i 's/[ \t]*$//g' test
## to trim both leading and trailing whitespaces using single line sed command
UNIX> sed -i 's/^[ \t]*//g;s/[ \t]*$//g' test
We can use tow reg exp in '' of sed using ; this operator
##how to add a comment in another file from unix using sed.
##1 ==> first line of the file
UNIX> cat test
aiasdfdsafdsamalliasdf
asdfdsafdsa(123)432-1421(432)412-34321vasdf
kjhkjh(123)432-143214asdf
UNIX> sed '1s/^/\#\# this is comment \#\#\n/' test
## this is comment ##
aiasdfdsafdsamalliasdf
asdfdsafdsa(123)432-1421(432)412-34321vasdf
kjhkjh(123)432-143214asdf
##to delete all blank lines
UNIX> sed -i '/^$/ d' test
##to delete all lines containing malli in a file called test
UNIX> sed -i '/malli/ d' test
##to delete lines starting with ##
UNIX> sed -i '/^##/ d' test
##to delete first two lines in a file
UNIX> sed -i '1,2 d ' test
--> Change the third 'apple' in each record to 'orange': sed 's/apple/orange/3' somefile


25) How to open pdf in unix ?
UNIX> xpdf file_name

26) How to open a png or an image file ?
UNIX> display file_name


27) How to untar a file ? 
UNIX> tar –zxvf filename.tar.gz:
-z : Uncompress the resulting archive with gzip command.
-x : Extract to disk from the archive.
-v : Produce verbose output i.e. show progress and file names while extracting files.
-f data.tar.gz : Read the archive from the specified file called data.tar.gz.

28) How to display a folder size ? 
UNIX>du -sk folder/file_name
Esc+b to go to one word back in the terminal
Esc+f to go one word forward
To see the memory occupied per user
UNIX> du -skH *

24) kill,fg & bg commands :
UNIX> kill jobID
UNIX> kill %% ; # To kill the the most recent from the many Jobs that are running under the hood
UNIX> jobs   ; # This lists out current active process in the terminal
UNIX> fg [1] or fg %1 ; # To resume/ go to the job1 (fore ground --> fg)
UNIX> bg ; # To run job in background (bg) 
UNIX> bg %jobid
UNIX> kill %jobid
UNIX> kill -9 %jobid ; ##use -9 if a job refuses to be killed

25) "diff" command in UNIX ??
To compare files line by line and it can compare even the directories too
UNIX> diff -ri FILE1 FILE2
diff has got lot of options…
UNIX> diff file1 file 2  ; #to do simple file diff
Go through the list of options that diff has got in the below table..
UNIX> diff file_1 file_2
UNIX> diff -qr DIR_1 DIR_2
EXAMPLS :
UNIX> diff -qr  SD4_RTL1P0_WW15P2_v1p16 SD4_RTL1P0_WW16P5_v1p17
Only in SD4_RTL1P0_WW15P2_v1p16: testfamilyewtop.syn_final.upf
Files SD4_RTL1P0_WW15P2_v1p16/testfamilyewtop.syn_final.vg and SD4_RTL1P0_WW16P5_v1p17/testfamilyewtop.syn_final.vg differ
Only in SD4_RTL1P0_WW16P5_v1p17: testfamilyewtop_DC_OUTPUT.upf


26) !$ use in UNIX ??
UNIX> ls amr/test.txt
UNIX> gvim !$
(will open the test.txt file in the gvim editor)
UNIX> ls amr/
UNIX> gvim !$
(will open the a new file with name amr in the gvim editor)

27) du command ??
UNIX>  du –sk folder name  ### this will give the amount of memory occupied by the folder

28) Is there a way to change vnc resolution ?
"xrandr" command does that
UNIX> xrandr -s 1920x1200; #number changes based on lap configuration

29) Interactive editor and navigator ?
UNIX> j ; #It opens a windows based look for your work area

30) Office program in unix ?
UNIX> soffice a.csv &

31) To know which is the host machine that you are using currently (like SLES-10 or SLES-11)
UNIX>  cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 3

32) lscpu  ??
It gathers CPU architecture information form /proc/cpuinfon in human-read-able format:
UNIX> lscpu
Sample outputs:
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    4
CPU socket(s):         2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 15
Stepping:              7
CPU MHz:               1866.669
BogoMIPS:              3732.83
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0-7

33) If you are facing a problem of copy/paste not working between linux and windows through VNC,
you can run below command in linux terminal. It will work fine.  Command to be run on linux terminal is: 
UNIX> vncconfig –nowin&.

34) In reg exp : Paentheses have the side effect of capturing, setting \1 to the stuff matched by the first set of parentheses, \2 to the second, etc.
 gzip -c large.log | ssh user@hostwithbigdisk 'cat > /dir/large.log.gz' # Compress and ssh transfer a log that has filled a filesystem.
zcat large.log.gz | awk '{print $0 | "gzip -v9c > large.log-"$1"_"$2".gz"}' # Breakup compressed log by syslog date and recompress. #awksome

35) To find the memory used by me in unix :
UNIX> df -kh ~user_name
Filesystem            Size  Used Avail Use% Mounted on
innfs031:/vol/vol6/ba_ctg_home01/user_name
                      50G   46G  4.8G  91% /nfs/iind/home/user_name
UNIX> df -kh . -P
Filesystem            Size  Used Avail Use% Mounted on
incfs02n03b-14:/mg_disk1652  501G  436G   65G  88% <disk_name>
36) Diff b/w the directories and finding only the differences :
UNIX> diff -r -q OLD_DIR NEW_DIR | grep differ | grep -v "verif/" ; #to find diff and with verif directory names

37) To get absolute directory name with ls, enter in the terminal's command shell:
UNIX> ls -ld $PWD/*
Also use this :
UNIX> ls -tlr <dir_name>/*.upf
-rwxr-x--- 1 mn1 coe73   4875 Sep  9 11:16 <dir_name>/master.upf
-rwxr-x--- 1 mn1 coe73   4797 Sep  9 11:16 <dir_name>/slave6.upf
ls -t to get only list(no time stampings etc..)

38) string replacement in unix ?
1. Replacing one string with another in all files in the current directory:
These are for cases where you know that the directory contains only files and that you want to process all files.
If that is not the case, use the approaches in 2.
a. Non recursive, files in this directory only:
UNIX> sed -i 's/foo/bar/' *
UNIX> perl -i -pe 's/foo/bar/' *
b. Recursive, files in this and all subdirectories
UNIX> find . -type f -print0 | xargs -0 -exec sed -i 's/old/new/g'
c. try exploring "rename" command

39) Creating a soft link to the files ?
UNIX> ln -s <FILE_NAME>  soft_link

40) Echo :
Your shell is interpreting the quotes, both ' and ", before they even get to echo. I generally just put double quotes around my argument to echo even if they're unnecessary; for example:
$ echo "Hello world"
Hello world
So in your first example, if you want to include literal quote marks in your output, they either need to be escaped:
$ echo \'Helloworld\'
'Hello world'
Or they need to be used within a quoted argument already (but it can't be the same kind of quote, or you'll need to escape it anyway):
$ echo "'Hello world'"
'Hello world'
$ echo '"Hello world"'
"Hello world"

41) sort ??
--> Sort based on column : UNIX> sort -k2  -n FILE

42) ls command options ?
UNIX> ls
bye  hai  help
To find out which of the items are files and which are directories, we can specify the -F option to ls
UNIX> ls -F
bye  hai  help/

UNIX> ls
bye  hai  help

1 file per line
UNIX> ls -1
bye
hai
help

43) head and tail commands ?
To print first few lines of a file to stdout
UNIX> head file_name
To print first 5 lines of a file to stdout
UNIX> head -5 file_name
To print last few lines of a file to stdout
UNIX> tail file_name
To print last 5 lines of a file to stdout
UNIX> tail -5 file_name

44) File redirect operators:
">" symbol is used to redirect the stdout to a file
">>" to append to an already existing file
"<" symbol is used to read a file content
UNIX > sort < in_file > out_file
and
UNIX > sort in_file > out_file
Both of the above commands are same

45) username of the host ?
UNIX> whoami
user_name

46) To find who is on system with you:
UNIX> who
user_name pts/21       2015-04-27 10:18
user_name pts/22       2015-04-28 16:23
sdayyaga pts/23       2015-04-01 10:29
guptaabx pts/24       2015-05-19 15:55

47) To know one line man detail of a command use "whatis"
UNIX> whatis wc
wc (1)               - print the number of newlines, words, and bytes in files
wc (1p)              - word, line, and byte or character count

48) To give ar/w permissions to all :
chmod a+rw file_name
To remove r/w/x permissions for others and group
chmod go-rwx file_name
One can also  "chmod 777 file_name " or "chmod go+rwx file_name" to give every permissions to everyone else

49) To check your current quota and how much of it you have used ??
UNIX> quota -v

50) df (disk fragmentation) : 
To find out how much space left on the current disk(file server) use
UNIX> df .
Filesystem           1K-blocks      Used Available Use% Mounted on
infs5576b:/vol16/mg_disk1573
                    314572800 247701504  66871296  79% /nfs/iind/disks/mg_disk1573
To get the details in readable format use -kh to the above command
UNIX> df -kh .
Filesystem            Size  Used Avail Use% Mounted on
infs5576b:/vol16/mg_disk1573
                     300G  237G   64G  79% /nfs/iind/disks/mg_disk1573
51) du(disk usage):
To get the number of KB used by each subdirectory. Very useful to find out who or which file is occupying more disk space
-s means display summary
-kh  or -h ===> to get human readable format
UNIX> du -skh *
304K    SD4_RTL1P0_WW15P2_v1p16
304K    SD4_RTL1P0_WW16P5_v1p17
79G     SD4_RTL1P0_WW18P2_v1p18
52) How to read file content when the file is in zipped format ?
This will scroll the whole text so fast if the file content is huge
UNIX> zcat file_name.gz
If want to read page by page slowly .. Use | less
UNIX> zcat file_name.gz | less

53) To report all files in a directory use "file *". This will give you the file format for each file in that directory
UNIX> pwd
/nfs/iind/home/user_name
UNIX> file *
CDS.log.cdslck:         ASCII text
Desktop:                directory
procs.tcl:          ASCII English text
alias_dc_icc.tcl:       ASCII English text, with CRLF line terminators
del_dsslog.sh:          Bourne-Again shell script text

54) history command ?
UNIX> set history=1000
UNIX> echo $history
1000
UNIX> !! (recall last command)
UNIX>!-3 (recall 3rd most recent command)
UNIX>!5 (recall 5th command in the list)
UNIX>!grep (recall last command starting with grep)

55) find command ? 
To search for all files with extensions .txt starting from the current directory and through all the subdirectories , then printing the name of the file to the screen
UNIX> find .-name "*.txt" -print
To find all files over 1MB size and display the result as a long listing , type:
UNIX> find .-size +1M ls
find * -type f -name "*.sp"
##to find the all .sp files recursively
UNIX> find . –name filename ##normal find command

56) date ?? 
--> To print out current date
UNIX> date
Sun May 31 20:16:21 IST 2015
UNIX> cal month year
UNIX> cal 5 2015
     May 2015
Su Mo Tu We Th Fr Sa
               1  2
3  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

57)  who, finger are  UNIX commands to know who are all logged into my computing machine

58) calculator ??
UNIX>xcalc & ;
##make use of this for calculating purpose…don’t go to windows every other time to use calc.. (also try expr in SNPS tools too )

59) Getting bored..??? 
Try UNIX > xfig & ;  
or 
UNIX> xpaint &;
#will open up a drawing program

60) You can actually try using sometime gnuplot to plot the graphs etc.. 
UNIX> gnuplot &

61) logout / exit ?
UNIX > logout ; 
UNIX> exit ; ##to quit a UNIX shell

62) tar command ?? 
Unix tar command line options
In this section of UNIX tar command tutorial we will see some useful options of tar command in Linux and we will use this options on our example to understand usage of this option along-with tar command.
c -- create, for creating tar file
v -- verbose, display name of files including,excluding from tar command
f -- following, used to point name of tar file to be created. it actually tells tar command that name of the file is "next" letter just after options.
x -- extract, for extracting files from tar file.
t -- for viewing content of tar file
z -- zip, tells tar command that create tar file using gzip.
j –- another compressing option tells tar command to use bzip2 for compression
r -- update or add file or directory in already existed .tar file
wildcards -- to specify patters in unix tar command
##to create a .tar for a directory abc/
UNIX> tar -cvf abc.tar abc/
##to create a .tar.gz for a directory abc/ (more compressed than .tar)
UNIX> tar -cvzf abc.tar abc/
##to unzip/de compress the folder abc.tar.gz
UNIX> tar -xvf abc.tar.gz

63) How to update my password ?
UNIX>passwd ; ##to change the password

64) "comm" command ??
UNIX > comm FILE_1 FILE_2
This will print output in 3 columns
1st ==> which are only in FILE_1
2nd column ==> which are only in FILE_2
3rd column ==> which are in both files
##we can suppress the unwanted columns by specifying them in the command line as in below examples
Examples:
##to see only the things common to both files (i.e column 3)
UNIX> comm -12 FILE_1 FILE_2
##to see the list which only present in FILE_1
UNIX> comm -23 FILE_1 FILE_2
##to see the list which only present in FILE_2
UNIX> comm -13 FILE_1 FILE_2

65) regexp in unix ?
\s matches white space, i.e. space, tab, newline, etc. Example: /foot\s+ball/ matches 'foot ball' but not 'football'.
\W matches any non-word character, anything \w doesn't match.
* means zero or more, + means one or more, ? means zero or one.
Parentheses and | denote options. Example: /(red|green|blue) truck/ matches 'red truck' or 'green truck' or 'blue truck'.
Parentheses have the side effect of capturing, setting \1 to the stuff matched by the first set of parentheses, \2 to the second, etc.
You can include comments inside a regex with (?# ... ). For example, /the\s+(?# One or more spaces)end


I will keep adding as and when i come across more useful daily tips

4 comments:

  1. Thank for sharing the knowledge! Keep going!

    ReplyDelete
  2. Thank you. This is very helpful ! Keep sharing

    ReplyDelete
  3. Your information is amazing. If you want to know that how to zip a directory in Unix then
    visit this link for more information;

    how to zip a directory in Unix

    ReplyDelete