UNIX is open
source software that was originally created by Ken Thompson at Bell Labs way
back in 1969. As time goes by, it has been developed in to a variety of distros also known as unix flavours.
Some of the flavours that were derived by volunteers remain free while others
are not. Linux is a known free unix derivative that has gone far enough which
made it as an alternative to proprietary operating systems and now being widely
use in several industries.
I’ve listed here10
basic UNIX commands that will help you get started in your venture of playing
around the UNIX world. These commands are applicable in Linux, Solaris & other
distros.
Suggestion:
To know more about
the commands, access the manual page by typing man
<command> on the command prompt.
Example:
1. sudo
This is to execute a command as another user.
SYNOPSIS
sudo -V | -h | -l | -L | -v | -k | -K | -s |
[ -H ] [-P ] [-S ] [ -b ] | [ -p prompt ] [ -c class|- ]
[ -aauth_type ] [ -u username|#uid ] command
DESCRIPTION
sudo allows a
permitted user to execute a command as the superuser or another user, as specified in the sudoers file.
The real and effective uid and gid are set to match those of the target user as
specified in the passwd file (the group vector is also initialized when the
target user is not root). By default, sudo requires
that users authenticate themselves with a password (NOTE: by default this is the user's password, not the root
password). Once a user has been authenticated, a timestamp is updated and the
user may then use sudo without a password for a short period of time (5 minutes unless overridden in sudoers).
EXAMPLES
Command
|
Explanation
|
Sudo –u root –i
|
To switch to root user
|
Sudo -l
|
To see what sudo permissions the user has
|
2. mkdir
Make directory
SYNOPSIS
DESCRIPTION
Create
the DIRECTORY(ies), if they do not already exist.
EXAMPLES
Command
|
Explanation
|
Mkdir scripts
|
To create directory named scripts
|
Mkdir /tmp/files
|
To create folder under
tmp directory
|
3. cd
Change working
directory
SYNOPSIS
/usr/bin/cd [directory]
DESCRIPTION
The /usr/bin/cd utility changes the
current directory in the context of the cd utility only. This is in contrast to
the version built into the shell. /usr/bin/cd has no effect on
The invoking
process but can be used to determine whether or not a given directory can be
set as the current directory.
EXAMPLES
Command
|
Explanation
|
Cd scripts
|
To open script
directory you’ve created in #2
|
4. pwd
- return working
directory name
SYNOPSIS
/usr/bin/pwd
DESCRIPTION
The pwd utility writes an absolute path
name of the current working directory to standard output.
EXAMPLE
Command
|
Explanation
|
Pwd
|
To your current working directory.
|
5. Vi
Screen-oriented
(visual) display editor based on ex
SYNOPSIS
vi [ -| -s ] [-l]
[-L] [-R] [ -r [ filename ] ] [-S] [-t tag] [-v] [-V] [-x] [-w] [-n ] [-C]
[+command | -c command ] filename
EXAMPLE
Command
|
Explanation
|
vi myfile.txt
|
To create or edit a text file
|
:q!
|
To quit without saving
|
:wq!
|
To save and quit the file
|
To know more about vi editor - http://www.cs.rit.edu/~cslab/vi.html
6. ls
list contents of
directory
SYNOPSIS
ls
[options] file
DESCRIPTION
For each file that is a directory, ls list
the contents of the directory. For each
file that is an ordinary file, ls repeats its name and any other information
requested. The output is sorted
alphabetically by default. When no argument is given, the current directory (.)
is listed. When several arguments
are given, the arguments are
first sorted appropriately, but file arguments appear before directories.
EXAMPLE
Command
|
Explanation
|
Ls -lrts
|
To long list files inside your current working
directory.
|
Ls -la
|
To long list hidden files.
|
7. chmod
Change the
permissions mode of a file.
SYNOPSIS
chmod [option] file
DESCRIPTION
The chmod utility changes or assigns the permissions
of a file.
U= user/owner
G =group
O = others
A = all users
|
R = read = 4
W = write = 2
X = execute = 1
|
EXAMPLE
Command
|
Explanation
|
Chmod 777 myfile.txt
|
To change permission of myfile.txt into readable
writable & executable for all users.
|
Chmod o+x myfile.txt
|
To change grant other users with execute permission.
|
- remove directory
entries
SYNOPSIS
rm [options] file
DESCRIPTION
The rm utility
removes the directory entry specified by each file argument. If a file has no write permission and the standard
input is a terminal, the full set of
permissions (in octal) for the file are printed followed by a
question mark. This is a prompt for confirmation. If the answer begins with y (for yes), the file is deleted,
otherwise the file remains.
EXAMPLE
Command
|
Explanation
|
Rm myfile.txt
|
To delete/remove myfile.txt
|
9. find
find files
SYNOPSIS
find [-H |
-L] path... expression
DESCRIPTION
The find utility recursively descends the directory
hierar- chy for each path seeking files that match a Boolean expres-sion
written in the primaries given below.
find is able
to descend to
arbitrary depths in
a file hierarchy and does not fail due to path length limitations (unless
a path operand specified by the application
exceeds PATH_MAX requirements).
EXAMPLE
Command
|
Explanation
|
Find /scripts ‘myfile.txt’
|
To find myfile.txt
inside /scripts directory.
|
Find . –type f –name ‘myfile.txt’
|
To find myfile.txt
into current working directory.
|
10. mv
move (rename) files
SYNOPSIS
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
Rename SOURCE to DEST, or move SOURCE(s)
to DIRECTORY.
EXAMPLE
Command
|
Explanation
|
Mv myfile.txt
hisfile.txt
|
Rename myfile.txt
to hisfile.txt
|
Mv /scripts/myfile.txt /tmp/
|
To move myfile.txt from scripts directory to tmp
directory.
|
Next post will be about troubleshooting of common unix issues.
Please share your unix related experiences as well. J