Home » Unix command and scripts » Unix Script Tutorial : basic unix command

Unix Script Tutorial : basic unix command

The Unix command has the following common pattern

command_name options argument(s)

Here we are trying to give some of the basic unix command  in Unix

basic unix command

Information Related

man It is used to see the manual of the various command.It helps in selecting the correct options to get the desirable output. Just need to give man command
finger Getting information about a local and remote users. Sometimes you may want to know what all user are currently logged into the unix system then this will help
passwd Changing your password for the user. If you are logged in ,then enter passwd,it will change the password for the current user. From root login you can change password for any user by using passwd
who Finding out who is logged on
which find the source directory of the executable being used
uname print name of current system. On Solaris uname -X will give the cpu and various other informations
uptime Time since the last reboot

File listing and directory manipulation command

ls List contents of Directory(s)
Syntax: ls options
OPTIONS
The following options are supported:-a Lists all entries, including those that begin with a dot (.), which are normally not listed.
-d If an argument is a directory, lists only its name (not its contents); often used with -l to get the
status of a directory.
-n The same as -l, except that the owner’s UID and group’s GID numbers are printed, rather than the associated character strings.
-r Reverses the order of sort to get reverse alphabetic or oldest first as appropriate.
-R Recursively lists subdirectories encountered.-t Sorts by time stamp (latest first) instead of by name. The default is the last modification time.
-h Give the file size in Giga bytes
mkdir Creates directory(s) or directory structure
Syntax:- mkdir
Options: m & p
Option p checks if the directory already exists,then leave it without issuing any error.If it does not exists,it will create it
rm, rmdir remove directory entries
-r Recursively remove directories and subdirectories.
-i Interactive. With this option, rm prompts for confir-
mation before removing any files.
-f Remove all files (whether write-protected or not) in a
directory without prompting the userExample
rm -f * Remove all files in the working directory. rm will not prompt you for any reason before deleting them
rm -i * Attempt to remove every file in the working directory, but prompt before each file to confirm.
cd : Changes current working directory to the directory specifedSyntax:- cd dirname [ cd without any arguments will changes current working directory to home directory]
pwd Prints full path name of the current working directory
cp Options:
-i Interactive. cp will prompt for confirmation whenever the copy would overwrite an existing target.
-r Recursive. cp will copy the directory and all its files, including any subdirectories and their files to target.
-p Preserve. cp duplicates not only the contents of source_file, but also preserves the owner and group id, permissions modes, modification and access time.
mv move files(s) /dir(s)
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:
mv –i x1 x2
[moves x1 to x2, if x2 exists prompts for confirmation.]
mv *lst dst_directory.
[ moves all files like lst to dst_directory.]
See also  How to check physical RAM ,swap space on Unix

I hope you like these useful basic unix command with example

Leave a Comment

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

Scroll to Top