Home » Unix command and scripts » basic unix commands pdf

basic unix commands pdf

We have touched upon many unix commands before in the previous article. Here are some more commands with downloadable basic unix commands pdf

 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

Examples

(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 the directory app and all its subdirectories files to the “/u000” directory

mv –r oracle/app /u000

(4) moves the file to another name in a different directory

mv f1.txt oracle/f2.txt

file, head, tail & alias commands

file – determine file type
Syntax: file <file_name>

Example

$ file workfile 
workfile: ascii text

head – display first few lines of files
Syntax: head –n <file_name>

Example

$ head -10 workfile 
11111
22222
23333

tail – displays the last part of a file
Syntax: tail –n <file_name>
Other Option: -f
Example

$ 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 name for a command – an alias – is very easy.
Assigning an alias is done with the command:
alias name definition
unalias name
Example

alias del='rm -I'

How to get the History of the 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

See also  How to check physical RAM ,swap space on Unix

Example

$ 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

cut command displays selected columns or fields from each line of a file.
cut -clist [ file_list ]
cut -flist [ -dchar ] [ -s ] [ file_list ]
options:
-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.
For example,
-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’ ‘

Examples

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 – 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.

See also  How to Setup ssh passwordless login using SSH keygen between two servers

Options

basic unix commands pdf

Examples

(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 Command

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/

env command

To see value of all environment variables.

env


To set an environment variable:
In ksh or sh
“export VARIABLENAME=value”

Example
export ORACLE_SID=TECH


In csh “setenv VARIABLENAME value”

Example
setenv ORACLE_SID TECH

See value of an environment variable
echo $VARIABLENAME 

Example 
echo $ORACLE_SID

I hope you like these useful Practical Unix commands pdf. Please do provide feedback to improve

Here is the list of articles which contain more Unix command tips and tricks
awk command
sed command in unix
Find command
vi editor
https://en.wikipedia.org/wiki/Linux
See also  What is crontab in Linux

Basic Unix Command
Basic Unix Command
Basic_unix_command.pdf
131.5 KiB
1860 Downloads
Details

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top