Linux and ShellCommands

Linux and Shell Commands:
=====================

adduser           Add a new user                    
arch                  Print machine architecture                
awk                 Find and Replace text within file(s)              
bc                    An arbitrary precision calculator language                 
cal                    Display a calendar                  
cat                   Concatenate files and print on the standard output              
chdir                Change working directory                 
chgrp               Change the group ownership of files             
chkconfig        Tool for maintaining the /etc/rc[0-6].d directory hierarchy               
chmod             Change the access permissions of files and directories                    
chown             Change the user and group ownership of files                      
chroot              Change root directory           
cksum              Print CRC checksum and byte counts                      
clear                 Clear terminal screen             
cmp                 Compare two files                 
comm              Compare two sorted files line by line           
cp                    Copy one or more files to another location               
cron                 Daemon to execute scheduled commands                
crontab            Schedule a command to run at a later time               
csplit                Split a file into context-determined pieces               
cut                   Divide a file into several parts                       
date                 Display or change the date & time               
dc                    Desk Calculator                    
dd                    Data Dump - Convert and copy a file                      
df                    Display free disk space                     
diff                  Display the differences between two files               
diff3                Show differences among three files             
dir                    Briefly list directory contents           
dircolors          Colour setup for `ls'              
dirname           Convert a full pathname to just a path                      
du                    Estimate file space usage                  
echo                 Display message on screen                
ed                    A line-oriented text editor (edlin)                 
egrep               Search file(s) for lines that match an extended expression               
eject                 Eject CD-ROM                     
env                  Display, set, or remove environment variables                     
expand            Convert tabs to spaces                      
expr                 Evaluate expressions             
factor               Print prime factors                
false                 Do nothing, unsuccessfully               
fdformat          Low-level format a floppy disk                    
fdisk                Partition table manipulator for Linux           
fgrep                Search file(s) for lines that match a fixed string                   
find                 Search for files that meet a desired criteria              
fmt                  Reformat paragraph text                   
fold                 Wrap text to fit a specified width                
format             Format disks or tapes            
free                  Display memory usage                      
fsck                 Filesystem consistency check and repair                  
gawk               Find and Replace text within file(s)             
grep                 Search file(s) for lines that match a given pattern                
groups             Print group names a user is in           
gzip                 Compress or decompress named file(s)                    
head                Output the first part of file(s)           
hostname         Print or set system name                   
id                     Print user and group id's                   
info                  Help info                   
install               Copy files and set attributes              
join                  Join lines on a common field            
kill                   Stop a process from running             
less                  Display output one screen at a time              
ln                     Make links between files                  
locate               Find files                    
logname           Print current login name                    
lpc                   Line printer control program             
lpr                    Off line print             
lprm                 Remove jobs from the print queue                
ls                      List information about file(s)             
man                 Help manual              
mkdir               Create new folder(s)             
mkfifo             Make FIFOs (named pipes)              
mknod             Make block or character special files            
more                Display output one screen at a time              
mount              Mount a file system              
mv                   Move or rename files or directories               
nice                  Set the priority of a command or job            
nl                     Number lines and write files             
nohup              Run a command immune to hangups            
passwd            Modify a user password                   
paste                Merge lines of files               
pathchk           Check file name portability               
pr                     Convert text files for printing           
printcap           Printer capability database                
printenv           Print environment variables              
printf               Format and print data           
ps                     Process status            
pwd                 Print Working Directory                    
quota               Display disk usage and limits           
quotacheck      Scan a file system for disk usage                  
quotactl           Set disk quotas                       
ram                  ram disk device                     
rcp                   Copy files between two machines                
rm                    Remove files             
rmdir               Remove folder(s)                  
rpm                  Remote Package Manager                
rsync                Remote file copy (Synchronize file trees)                  
screen              Terminal window manager               
sdiff                Merge two files interactively            
sed                   Stream Editor            
select               Accept keyboard input                     
seq                   Print numeric sequences                    
shutdown        Shutdown or restart linux                 
sleep                Delay for a specified time                 
sort                  Sort text files            
split                 Split a file into fixed-size pieces                   
su                     Substitute user identity                     
sum                  Print a checksum for a file                
symlink            Make a new name for a file              
sync                 Synchronize data on disk with memory                   
tac                   Concatenate and write files in reverse                      
tail                   Output the last part of files               
tar                    Tape Archiver           
tee                   Redirect output to multiple files                   
test                  Evaluate a conditional expression                 
time                 Measure Program Resource Use                   
touch               Change file timestamps                     
top                   List processes running on the system            
traceroute        Trace Route to Host              
tr                      Translate, squeeze, and/or delete characters             
true                  Do nothing, successfully                   
tsort                 Topological sort                    
tty                    Print filename of terminal on stdin               
umount            Unmount a device                 
uname              Print system information                   
unexpand        Convert spaces to tabs                      
uniq                 Uniquify files            
units                Convert units from one scale to another                   
unshar              Unpack shell archive scripts              
useradd           Create new user account                   
usermod          Modify user account             
users                List users currently logged in            
uuencode         Encode a binary file               
uudecode        Decode a file created by uuencode              
vdir                  Verbosely list directory contents (`ls -l -b')               
watch              Execute/display a program periodically                    
wc                   Print byte, word, and line counts                  
whereis            Report all known instances of a command               
which              Locate a program file in the user's path                    
who                 Print all usernames currently logged in                     
whoami           Print the current user id and name (`id -un')             
xargs                Execute utility, passing constructed argument list(s)           
yes                   Print a string until interrupted 
=============================================================
/u01/prd/backupL0.sh

$ cat zipcodes.txt
(prints the entire contents of a file named "zipcodes.txt")

  awk      Find and Replace text, database sort/validate/index
  
    dd       Convert and copy a file, write disk headers, boot records

diff     Display the differences between two files

  diff3    Show differences among three files
  
    exec     Execute a command
  exit     Exit the shell
  
    free     Display memory usage
  
ftp      File Transfer Protocol
  
   ifconfig Configure a network interface
  ifdown   Stop a network interface 
  ifup     Start a network interface up
  
   iostat   Report CPU and i/o statistics
   
   less     Display output one screen at a time
   more     Display output one screen at a time
   
   netstat  Networking connections/stats
   
   passwd   Modify a user password
   
    shutdown Shutdown or restart linux
stat     Display file or file system status

tail     Output the last part of file
  tar      Store, list or extract files in an archive
  
   uptime   Show uptime
   
    vmstat   Report virtual memory statistics

who      Print all usernames currently logged in
  whoami   Print the current user id and name (`id -un')
  wget     Retrieve web pages or files via HTTP, HTTPS or FTP

If a file is too long to be viewed on one page, you can say:

$ more zipcodes.txt
(prints file one screenful at a time)

You can also use "grep" to print only those parts of a file you are interested in:

$ grep 10001 zipcodes.txt
(prints only those lines that have the character string "10001" in them)

Pipelines and Redirection
You can use a pipeline (symbolized by "|") to make the output of one command serve as the input to another command. This idea can be used to create a combination of commands to accomplish something no single command can do.

Enter this command:

$ echo "cherry apple peach"
cherry apple peach

Okay, let's say we want to sort these words alphabetically. There is a command "sort", but it sorts entire lines, not words, so we need to break this single line into individual lines, one line per word.

Step one: pipe the output of "echo" into a translation (tr) command that will replace spaces with linefeeds (represented by "\n"):

$ echo "cherry apple peach" | tr " " "\n"
cherry
apple
peach 

Success: each word appears on a separate line. Now we are ready to sort.

Step two: add the sort command:

$ echo "cherry apple peach" | tr " " "\n" | sort
apple
cherry
peach 

Let's try reversing the order of the sort:

$ echo "cherry apple peach" | tr " " "\n" | sort -r
peach
cherry
apple 


Normally the output from commands is printed on the screen. But using the symbol ">", you can redirect the output to a file:

$ date > RightNow.txt
$ cat RightNow.txt
Tue Dec 23 14:43:33 PST 2003

The above example used ">" to replace the content of any existing file having the name "RightNow.txt". To append new data to an existing file, use ">>" instead:

$ date >> RightNow.txt
$ cat RightNow.txt
Tue Dec 23 14:43:33 PST 2003
Tue Dec 23 14:46:10 PST 2003 

Remember: Use ">" to overwrite any existing file, use ">>" to append to any existing file. In both cases, if no file exists, one is created.

Many commands have inputs as well as outputs. The input defaults to the keyboard, the output defaults to the screen. 
To redirect the output to a file, use ">" or ">>" as shown above. 
To make the output of a command serve as the input of another command, use "|". 
To make the contents of a file serve as the input to a command, use "<":

if [ -e . ]
then
echo "Yes."
else
echo "No."
fi
              
              Run the test script:

$ ./myscript.sh
Yes.

We created a test (the part of the script between "[" and "]") which tested whether a particular 
element existed ("-e"). Because the symbol "." in this context means the current directory,
 the test succeeded. Try replacing the "." with something that is not present in the current directory, 
 example "xyz". See how the outcome changes.

It is important to realize that "[" is an alias for the command "test". The script could have been 
written as:


if test -e .
then
echo "Yes."
else
echo "No."
fi
              
              NOTE: Be sure to read the "test" man page to find out all the different



A couple of rules about logical operators used as branches: 
If you write "test && command", the command will only be executed if the test succeeds. 
If you write "test || command", the command will only be executed if the test fails.

Run these tests:

$ true && echo "Yes."
Yes.

$ false || echo "Yes."
Yes.   tests that are available:

Comments

Popular posts from this blog

Troubleshooting EBS login page issue in R12.2:

Oracle apps dba Interview Q&A's

Goldengate basics and Bounce