We have touched upon many unix command before in previous article.Here are some more command with downloadable basic unix commands pdf
mv – move files(s) /dirs
Options: - -f mv will move the file(s) without prompting even if it is writing over an existing target. -i mv will prompt for confirmation whenever the move would overwrite an existing target
(1) moves f1.txt to f2.txt, if f2.txt exists prompts for confirmation
mv –i f1.txt f2.txt
(2) moves file1 to 3 to dest_directory.
mv file1 file2 file3 dest_directory.
(3) moves directory app and all its sub directories files to /u000 directory
mv –r oracle/app /u000
(4) moves directory app and all its sub directories files to /u000 directory
mv f1.txt oracle/f2.txt
file, head, tail & alias commands
file – determine file type
Syntax: file <file_name>
$ file workfile workfile: ascii text
head – display first few lines of files
Syntax: head –n <file_name>
$ head -10 workfile 11111 22222 23333
tail – displays the last part of a file
Syntax: tail –n <file_name>
Other Option: -f
$ tail -f check_password_oracle.log User "oracle" does not exist.
Defining command aliases:
Remembering the name of a command and how it is used can be difficult. Assigning your own name for a command – an alias – is very easy.
Assigning an alias is done with the command:
alias name definition
alias del='rm -I'
How to get History of last commands
Using the command history
Each time that you enter a command it is added to a command history list. You can reuse commands from this list
$ history 1 cd /tmp 2 ls 3 file workfile 4 file ext.1.out 5 ls -lrtt check_password_expire_.log 6 file check_password_expire_.log 7 head -10 check_password_expire.log 8 tail -f check_password_expire_oracle_grid.log 9 history
cut command displays selected columns or fields from each line of a file.
cut -clist [ file_list ]
cut -flist [ -dchar ] [ -s ] [ file_list ]
-clist Display (cut) columns, specified in list, from the input data. No spaces are allowed within the list.
Multiple values must be comma (,) separated. The list defines the exact columns to display.
-c1,4,7 notation displays columns 1, 4, and 7 of the input.
-c1-10,50 format would display columns 1 through 10 and 50 through end-of-line.
Example $ cut -c2 file.txt a b c It display the second character grep '^Subject:' read-messages | cut -c10-80 It displays the character from 10-80
-flist Display (cut) fields, specified in list, from the input data.
No spaces are allowed within the list. Multiple values must be comma (,) separated. The list defines the exact field to display.
For example, -f1,4,7 would display fields 1, 4, and 7. The -f2,4-6,8 would display fields 2, 4, 5, 6, and 8.
dchar The character char is used as the field delimiter. The default delimiter is a tab character. To use a character that has special meaning to the shell, you must quote the character so the shell does not interpret it.
For example, to use a single space as a delimiter, type -d’ ‘
cat file1.txt | cut -f1,2 -d":" cut -f -3,5,7-9 -d ' ' infile1 > outfile1 ls –l | cut –f5 –d” “ grep "/bin/bash" /etc/passwd | cut -d':' -f1,6 root:/root tech:/home/tech
sort – sort command sorts data.If multiple input files are given, the data from each file is merged during the sort. You use the sort command to sort data alphabetically or numerically, in ascending or descending order. You can sort based on entire lines, fields, or character columns. You can merge files using sort and remove duplicate lines with it.
(1)sorts f1.txt and stores result in o.txt
sort -r f1.txt -o o.txt
(2)sorts, in reverse order, the contents of f1.txt and f2.txt, placing the output in outfile and using the second character of the second field as the sort key
sort -r -o outfile -k 2.2,2.2 f1.txt f2.txt
(3)same result as was with –k option.
sort -r -o outfile +1.1 -1.2 f1 infile2
(4)sorts the contents of infile with the second field as the sort key
sort +1 -2 infile
(5) Either of the following commands sorts the contents of infile1 and infile2 using the second non-blank character of the second field as the sort key
sort -k 2.2b,2.2b infile1 infile2 or sort +1.1b -1.2b infile1 infile2
(6)Either of the following commands prints the passwd file sorted by the numeric user ID (the third colon-separated field):
sort -t : -k 3,3n /etc/passwd or sort -t : +2 -3n /etc/passwd
who [options] to see who is logged in to the computer.
who -T Shows the IP address of each connection
who -r Shows when the computer was last rebooted, run-level.
$ who -r . run-level 2 Jun 8 00:23 2 0 S you have mail in /usr/spool/mail/
To see value of all environment variables.
To set an environment variable:
In ksh or sh
In csh “setenv VARIABLENAME value”
setenv ORACLE_SID TECH
See value of an environment variable
I hope you like these useful Practical Unix commands pdf. Please do provide the feedback to improveHere is the list of articles which contain more Unix command tips and tricks
sed command in unix
|Date:||November 11, 2016|
Leave a Reply