There are some commands which are used in LINUX operating system which are as follow:
- Clear Command:
The external clear command clears your terminal screen if possible.
$ clear and press (Enter)
The terminal screen is cleared and the shell prompt $ appears at the top of the screen. - Pwd Command:
The internal cd command changes your current working directory. cd lets you do the following:
- change working directory.
- change to last previous working directory.
- use a sting substitute in the current path to change to a similar directory path.
The general format of the command is:
$ chdir/cd-
$ cd [directory]
$ cd.. The present working directory is changed to previous working directory. - Mkdir Command:
The external mkdir command makes a new directory. You can pass multiple arguments to mkdir. Each argument is used by mkdir as the name of a new directory to create.
The general format of mkdir command is:
$ mkdir [-m mode] [-p] directory_lisht
Options:
-m mode:
Mode to use for new directories. This allow you to specify what mode all of new directories will have when they are created
-p:
Parent directory creator. If you specify a pathname to create a new directory and the parent directories do not exist, mkdir will create them as needed.
Note:
You have must have write permission fr the directory when you are creating new sub-directories. If no write permission is available, you will not be able to create a new directories.
Example: - To create a sub-directory called misc which has another sub-directory named misc1.
$ mkdir misc misc/misc1 - Rmdir Command:
The external rmdir command remove a directory. The directory must be empty.
rmdir is a safe way to perform directory removal than using rm -r command. It checks the directory for existence of files and sub-directories. If any exists, rmdir complaints and exits without removing the directory.
The general format of rmdir is:
$ rmdir [-ps] directory_list
Options:
-p
Removes empty directories specified in the directory path. Name of each directory is displayed on standard output as it is removed. Directories that are not removed are displayed on standard error.
-s:
Suppress any messages produced. Both standard output and standard error are suppressed.
Examples:- $ rmdir misc/misc1 misc
to check whether the directories misc and misc/misc1 are removed use the following command to list the directory.
$ Is -l
- $ rmdir misc/misc1 misc
- Cat Command:
The external command reads each file in the argument list and displays the data to the standard output. It only writes to the standard output. By using shell re-standard input. It only writes to the standard output. By using shell redirection capabilities cat can be used to combine multiple files into one large file that is why it is called concatenate. Some of the uses of cat command are as under:
- Display contents of ASCII files.
- Make a copy of a file.
- Combine multiple file into one file.
- Copy input from your keyboard to a file.
- Send output to a pipe used for multiple file input.
- Combine input from screen and a file into one output stream.
General format of the cat command is
cat [-] [-su] [-v] file_list.
Option:
-: Read from standard input, treated as one input file.
-s: Error messages for non-existent files are suppressed.
-v: Prints non-printing characters is visible form. Control characters. e.g., Control-X is printed as ^X.
-e: Print as $ sign to represent new-line character.
-t: Print a ^I (Control-I) in place of tabs.
file_list: One or more files in sequential order and write to standard output. If no argument is specified cat reads from standard input.
Example:- $ cat my-file. To display a file.
- $ cat my-list your-list his-list To display multiple files.
- $ cat original-file > his-list To copy a file.
- $ cat file1 file2 file3 > file 123 Combining multiple files.
- $ cat > new-file Creating a file from keyboard.
{ here you type whatever you like and at the end press Ctrl-D}
- Is Command:
Is command is used to display files and directories names. The format of Is command is:
$ Is [option] [file-names or wild cards]
Some of the essential option are:- a:
Lists all files. Including hidden files starting from "." - -d:
Displays data about directories. - -l:
Long list files and directories. - -t:
List file in order of last modification time. - -R:
Recursively lists file in all sub-directories. - -r:
Displays files in reverse alphabetical order of filenames. - -U:
Sort entries by the last access time. - -x:
Sort files by file extension in alphabetical order.
- a:
- My Command:
The external my command moves a file from an existing location to a new location. It is also used as the rename command to change the name of a file. It has three formats:
- Rename a file with a new directory name.
- Move one or more files to reside under a different directory.
- Rename a directory with a new directory name.
General format of the my command is:
$ my [-if] file-name new_file-name.
$ my [-if] file-name directory.
$ my [-if] old_directory new_directory
Option:-f: Force the move to occur. Response "Yes" is assumed and move is performed.
-i: Commands runs in interactive mode. If destination file already exist, my prompts you with the file-name followed by a question mark (?). If you respond with "Y" or "Yes", move is performed. Any other response will cause my to skip to next move.
Example:- Display the list of files in the current directory
$ Is -x
caller file1 file2 db letters
$ my file2 stuff
Now display the list of files
$ Is -x
caller file file1 db letters stuff - Display the list of files in the current directory
- CP Command:
The external CP command copies a file. It reads the contents of a file and creates a new file or overwrites an existing file. There are two basic formats of CP that allow you to:
- copy one file to another file.
- copy multiple files to a directory.
- copy input from your keyboard to a file.
- copy a file to your terminal.
General format of the cp command is:
$ cp [-ip] source_file dest_file
$ cp [-ipr] source_file_list dest
directory
$ cp [-ip] source_directory
dest_directory
First format copies one ordinary file to a new file. Second format will copy one or more files to a specific directory. Third format allow you to copy an entire directory structure to a new directory.
Option:- i:
Interactive confirmation is required. You are prompted if an existing file is overwritten. If "Y" or "Yes" is given in response, copy is performed otherwise not. - -p:
Preserve the characteristics of the source file. Copy the contents modification times and permission modes of the source file to the destination file. - -r:
Recursively copy and source directories. If a directory is given as the source file, then all of its files and sub-directories are copied. The destination must be a directory.
- $ cp letter letter.bak make a backup copy of file letter
- $ cp letter ../temp copy letter to temp working directory
- $ cp /dev/tty note copy input from keyboard to file note
- $ cp file1 copy file1 to file stuff
- $ cp calendar letters copy file calendar directory
- i:
- RM Command:
The external RM command removes (delete) files or directories.
The general format of the RM command is
$ rm [fi] file_list
$ rm [-fir] directory_list [file_list]
Option:- -f:
Forces the removal of all files listed. Does not check whether file is write-protected or not. Does not prompt for confirmation. If directory is write-protected, files are never removed. - -i:
Interactive file removal. Response is awaited. - -r:
Recursively removes files and directories. All files are removed from each directory. Each directory is then remove. If a file is write-protected, then rm prompts you for confirmation to remove the file.
- # rm stuff to remove a file named stuff
- $ rm-ri letters
letters calendar ?y
letter ?
press Return not to delete letter directory
- -f:
- More/Page Command:
The external more command allows you to view a file on your terminal.. It lets you view one screen of text at a time. The page command performs the same function as more but with a different screen control. The screen is cleared before each full screen of text is displayed.
The general format of the move command is:
$ more [-option] [+linenum] [file_list]
OR $ page [-option] [+linenum] [file_list]
Option:- -f:
Do not long lines. Court logical lines instead of screen lines. Normally more truncates lines longer than the screen width. - -s:
Squeeze out adjacent blank lines. Two or more blank lines are grouped together and are reduced to one blank line. This increase amount of text displayed on the screen. - -w:
Prompts and waits for any key to be pressed before exiting. By default more / page will exit without waiting when end-of-file reaches. - -rows:
Specifies the No. of rows (lines) to display on your terminal screen. - +linenum:
Begin display at line number linenum of the input. - file_list:
The list of files to be read by more.
- Type more/etc/passwd /etc/group /u/ts/my/login/file1 and press Return. First screen of /etc/passwd file appear.
- Press Speacebar, next screen of data is displayed. (If the data in the file has been finished, next file is started)
- Type 2:n to skip to /etc/group file. The output will like
.... skipping
.... skipping to file /ul/ts/mylongin/file1
---more---(Next file:/ul/ts/mylogin/file1) - To return to second file, type :p to skip backward to /etc/group file.
... skipping
... skipping of file /etc/group
---more---(Nextfile:/etc/group) - Press Spacebar to move forward on screen.
- Press Spacebar to move until (Next file: /ul/ts/mylogin/file1) appears
At the end, type 'q' to exit from more.
- -f:
- Grep Command:
Search files for lines matching a specified pattern and display the lines:
Syntax Grep [option] [pattern] files
Option:- -c:
Instead of displaying matching lines simply output a count of total number matching the expression. - -i:
Ignore case in both the pattern and file. - -L:
Instead of displaying each line simply display the names of each file that contains no matches for the pattern. - -n:
Prefixes each out put line its line number in the file. - -w:
Display only those lines with matches for the patterns that complete word. - -x:
Display only those lines with matches for the patterns that complete line.
- -c:
Create a Zip archive from one or more files and directories.
Syntax zip zipfilename file1 file2 file3
Option:- -f:
Recursively work with directories adding all files in the sub-directories to the archive. - -m:
Move files into the archive deleting them form original location. - -e:
Encrpt the archive after prompting for a password this password will be use in extracting.
- -f:
- Unzip Command:
Manipulate and extract ZIP archive
Syntax unzip [option] ziped filename
Option:- -f:
Extract only those files that are newer than already-existing version of the file. - -I:
Displays the contents of the archive without extraction.
- -f:
- Chmod Command:
Change the access permission of one or more files or directory
Syntax chmod [option] mode files
Option:- -r:
Recursive Recursively changes the permissions of all files in all sub-directories. - -v:
Verbose Displays the results of all permission changes. - -f:
Silent Suppress display of error messages when files permissions cannot be changed
Mode it is in the form [ugoa][+-=] [rwx]
u = user who owned the file
g = all members of the group that owns the file
o = anyone who is not the owner or in the owner group
a = all user
+ = specified modes should be add to already specified permission
- = specified modes should be remove from already specified permission
= = specified modes will replace existing permission
r = read permission
w = write permission
x = execute permission
Example
$ Chmod u+x a.bat will give execute permission to user on a.bat file
$ Chmod u-x a.bat will remove execute permission to user
$ Chmod a+x a.bat will give execute permission to all user
$ Chmod a=rx a.bat will give read and execute permission to all user and
remove existing permission
- -r:
- At Command:
Schedules commands to be executed at a specific time. User is prompted for the commands.
Syntax at [option] time- -f filename:
Read commands from the specified file rather than prompting for the commands.
example $at 2.30
rm*.Temp ctrl-d
specifying times
now = specifies the current time
today = specifies the today
tomorrow = specifies the next day
+ = specifies offsets in minutes hours days of weeks
now + 2 hours = 3 days from today
Job Control
Using Job Control, it is possible to use a single shell to execute and control multiple programs running simultaneously.
Normally, when you execute a command, it runs in the foreground. That is, the shell executes the command and prompt and the prompt doesn't return until the command is finished.
I.t. executing a command
$ find / -name'*.tmp' -print > findfile
This command searches the entire structure of Linux system for files with the .tmp extension and store the result in the findfile file. While executing this command you won't be able to run other commands while find is running.
To place a job in the in background is to add an ampersand(&) to the end of the command when you run it.
$ find / -name'*.tmp' -print&
Once you press enter to execute this command, you are immediately presented with a new command prompt; at the same time and you will be able to execute the next command same time
Thus you can execute multiple task an the same time
- -f filename:
- Job Command:
This command will list all jobs running
Syntax $ jobs- Running $ find / -name '*.tmp' -print > findfile &
- Running $ Is -IR / '*bmp' >dirlist &
- Fg Command:
This command bring the background job to foreground
Syntax fg Jobs no
Example:
$ fg 1
This will bring $ find / -name '*tmp' -print >findfile from background to foreground ie on screen. - Bg Command:
This command start the stopped job in the background
Syntax bg Jobs no
The foreground job first stopped by pressing Ctrl+Z and command prompt will be available. Where you can run the bg command to run the stopped command in the background.
Example:
Suppose you enter another command.
$ IS -IR / '*.bmp' >dirlist
This will Execute in the foreground then press Ctrl+Z. This will temporary stopped the Is job.
And give command prompt to see the all current job.
$ jobs- Running find / -name '*.tmp' -print>findfile &
- Stopped $ Is -IR / '*.bmp' >dirlist &
$ bg 2
To see the result
$ jobs- Running $ find / -name '*.tmp' -print >findfile &
- Running $ Is -IR / '*.bmp' >dirlist &
- Cal Command:
The external call command generates a simple calender and write it to the standard output. The default output for cal is current month. Using specific argument, a calendar for specific year or year and month can be created. Valid years are 1 to 9999. Valid months are 1 to 12.
The general format of the cal command is
Syntax $ cal [[month]year]
year: Produces calendar for given year
month: Produces calendar for specified month of given year
Example:
To create a calendar for September 2010, the command is given as:
$ cal 9 2010 - Echo Command:
Displays a line of text to your terminal. Some of the feature and use of echo are- Display string of text
- Display variables
- Display menu screen
Example:
$echo "my home directory is $home"
Result will be display a line of text
May home directory is alihomedir
Sending or eceiving messages from or to another uiser. - Write Command:
The external write command sends message you type on your terminal to another user's terminal. Write reads the standard input and writes to the specified user's terminal tty. The write commands used to communicate with the fellow users on an interactive basis. It is useful to send a brief message to someone immediately or to carry on conversations using terminals. The general format of the write command is:
$ write user_name [tty]
Option:- \user_name:
The name of a user who is currently logged in to the system. Use the who command to list who is on the system. - tty:
Specify which terminal tty to connect to if the same user is logged on more than once
- Create a file and type some message in it, then use the following command:
$ write alpha < tempmesg
Where alpha is the name of the user to whom the message is to send while tempmesg is file containing the text of the message. - Type the following command:
$ echo "How are you? I want to meet you in the library at 09:00" ! write alpha. The echo will send the message to write via a pipe. The message will appear on the screen of username alpha all at one time as shown below:
message from mylogin tty11 [date & time]
How are you? I want to meet you in the library at 09:00
- \user_name:
- Wall Command:
The external wall command performs a write to all users currently logged on to the system.
The general format of the wall command is
$ wall
The wall message precedes its message text with the following line:
Broadcast message from use_name
It is usually used by super user to warn all users of immediate problems. The most command warning is that the system is being shutdown within 60 seconds.
The super user can write to any user's terminal regardless of the permissions set by that user using mesg command. The wall command is commonly used by the super user. It can also be used by any user but may users do not need to send message to every one on the system.
Common formats are:
$ wall < mesgfile
OR $ cat mesgfile ! wall
Example:- $ wall
This is a broadcast message of the Linux Beginners Broadcasting Foundation. Please disregard this message and get back to your work immediately. Ctrl-D.
- $ wall
- Man Command:
The external man command display help about any command to your terminal screen.
The general syntax format of the man command is
$ man command
Example:
$ man cp
Will display help page of cp command. - Head Command:
The External head command will display the first 23 lines of the file on the screen.
The general format of the head command is
$ head file_name
Example:
$ head abc
Will display first 23 lines of abc file. - Tail Command:
The external tail command will display the last 23 lines of a file on screen.
The general format of the tail command is
$ tail file_list
Example:
$ tail abc
will display last 23 lines of abc file. - Mail Command:
The external mail command is an electronic post office. You can send, receive and store messages using mail command. There is a long list of options associated with mail command which can be used according to the requirement. The general format of mail command is
$ mail options
To read mail, use the following command
$ mail
All the messages stored in the mailbox can be displayed.
To send mail to another user of the system, the following command is used:
$ mail user_name
Example:- To send mail to a user named alpha
$ mail alpha and press Return. The following screen appears
Subject --------------- (type the subject of the message) (type the message) press Ctrl-d to end the message - To read mail, type
$ mail
The display will show mail version................ 01/29/99 type? for help
Type ? to display the commands to view, edit, delete or store the messages to file. aq
- To send mail to a user named alpha
- Shutdown Command:
the external Shutdown command will shutdown the system. The root user are allowed to use this command on server, specifying time, will broadcast the message to all connected users. This command be used according to the requirement. The general format of shutdown command is
Syntax $ shutdown option time [message]
Option:- -h:
Will halt after shutdown. - -r:
System will reboot after the shutdown or restart the system. - Time:
Time specified in minutes
$ shutdown -h 3 "please save your work, the system is shutdown in 3 minutes.
- -h: