Linux ‘Locate’ Command Explained

The locate command is often the simplest and quickest way to find the locations of files and directories on Linux and other Unix-like operating systems.

The basic syntax for locate is:

locate [options] name(s)

When used without any options, locate displays every absolute pathname for which the user has access permission that contains any of the names of files and/or directories that are provided to it as arguments (i.e., input data).

The absolute pathname, also referred to as the absolute path or the full path, is the hierarchy of directories from the root directory to the designated file or directory. The root directory is the directory at the very top of the filesystem (i.e., hierarchy of files) that contains all other directories and files on the system and which is designated by a forward slash ( / ). It is important that the absolute pathname is returned both because it tells the exact locations on the system and because it makes it possible to indicate the locations of files or directories that have the same name but different absolute paths.

Thus, for example, the following would list the absolute paths of all files named file1 and all directories named dir1 for which the user had access permission:

locate file1 dir1

It would also list any other absolute pathnames that contained these strings (i.e., sequences of characters), for example /home/john/file123 or /usr/local/mydir1/index.html.

The specificity of locate can be increased by using it together with wildcards or other regular expressions. Wildcards are characters that can be used to substitute for any other character or characters. For example, the star character ( * ) is a wildcard that can represent any single character or any string containing any number of characters. Regular expressions are a string that describes or matches a set of strings, according to certain syntax rules. For example, the following command uses the star wildcard to display all files on the system that have the .png filename extension:

locate “*.png”

The -q option is used to suppress error messages, such as those that might be returned in the event that the user does not have permission to access designated files or directories. Thus, the following would suppress any error messages in the above example:

locate “*.png” -q

It is often the case that a large number of results will be returned for any query. The -n option followed by an integer limits the results to a specific number. For example, the following command would display only 15 results in a search for files that have an .html extension:

locate -n 15 “*.html”

An alternative is to use a pipe (represented by the vertical bar character) to redirect the output of locate from the display screen to a pager such as more or less, which presents only one screenful of output at a time, for example,

locate “*.html” | less

The -i option performs a case-insensitive search. That is, it will return any results that match the arguments regardless of whether individual letters are lower case or upper case. For example, the following would return all files with the extension .html, .HTML, or some combination thereof:

locate -i “*.HtmL”

On some systems, such as Red Hat, the program slocate is installed by default instead of locate, and entering the locate command activates a script (i.e., a short program) that causes slocate to be launched. slocate provides a secure way to index and quickly search for files on a system by storing file permissions and ownership data so that users will not see files for which they do not have access.

The -V option can be used to show which version of locate is used, including whether it is locate or slocate. Another way to determine whether slocate is being used is to see if an absolute pathname such as /usr/bin/slocate is returned when the following command is issued:

locate locate

locate and slocate actually search a built-in database, named locate.db or slocate.db, respectively, rather than the entire hard disk drive itself, in order to provide a much shorter searching time. This database is automatically updated on a regular basis by cron, a small program that runs in the background, performing various tasks at regularly scheduled intervals. The updating is performed each night if the computer is on continuously.

Because the database is not updated immediately, recently created files and directories might not show up when searching for them with locate or slocate. Fortunately, however, it is a simple matter to update the database manually, although it might take a few minutes. Manual updating can be accomplished by logging in as the root user (i.e., administrative user), such as by using the su (i.e., substitute user) command, and then issuing the following command:

updatedb

The same thing can be accomplished by the root user by using locate with its -u (i.e., update) option, i.e.,

locate -u

For the curious, the database is located at /var/lib/slocate/slocate.db on some systems, such as Red Hat. Its exact location on any particular system can be found by the root user (because ordinary users will not have access permission on most systems) with the locate command as follows:

locate locate.db

The database is a binary file (i.e., a non-text file). However, for the really curious user who has root permission, the human-readable portion of its contents can be viewed by first using the strings command to extract all the plain text and by then piping the output to less for displaying one screenful at a time as follows:

strings /var/lib/slocate/slocate.db | less

If it is desired to perform a more sophisticated search, including searching by attributes other than name (e.g., by size, creation date or location), the find command should be used.

Courtesy – Linfo

Linux ‘Du’ Command Explained

The du Command – shows the sizes of directories and files.

The du (i.e., disk usage) command reports the sizes of directory trees inclusive of all of their contents and the sizes of individual files. This makes it useful for tracking down space hogs, i.e., directories and files that consume large or excessive amounts of space on a hard disk drive (HDD) or other storage media.

A directory tree is a hierarchy of directories that consists of a single directory, called the parent directory or top level directory, and all levels of its subdirectories (i.e., directories within a directory). Any directory can be regarded as being the start of its own directory tree, at least if it contains subdirectories. Thus, a typical computer contains a large number of directory trees.

du is commonly employed by system administrators as a supplement to automated monitoring and notification programs that help prevent key directories and partitions (i.e., logically independent sections of a HDD) from becoming full. Full, or even nearly full, directories and partitions can cause a system to slow down, prevent users from logging in and even result in a system crash. Although visually identifying heavy consumers of disk space can be practical if there are relatively few users on a system, it is clearly not efficient for large systems with hundreds or thousands of users.

A minor limitation of du is the fact that the sizes of directories and files it reports are approximations, not exact numbers, and there is frequently a small discrepancy between these sizes and the sizes reported by other commands. However, this rarely detracts from its usefulness.

Also, du can only be used to estimate space consumption for directories and files for which the user has reading permission. Thus, an ordinary user would generally not be able to use du to determine space consumption for files or directories belonging to other users, including those belonging to the root account (i.e., the system administrator). However, as du is used mainly by system administrators, this is usually not a problem.

Syntax

The basic syntax for du is:

du [options] [directories and/or files]

The items in the square brackets are optional. When used with no options or arguments (i.e., names of directories or files), du lists the names and space consumption of each of the directories (including all levels of subdirectories) in the directory tree that begins with the current directory (i.e., the directory in which the user is currently working). The space consumption of any directory consists of the space occupied by all of the files in it and all of its subdirectories at all levels inclusive of all of the files in them. A final line at the end of the report gives the total space consumption for the directory tree.

du can provide information about any directory trees or files on the system whose names are given as arguments. For example, the following will report the names and sizes for each directory in the directory tree that begins with a directory named directory2 that resides in a directory named directory1, which, in turn, is located in the current directory:

du directory1/directory2

Likewise, the following will report the sizes of the two files named file1 and file2 that are located in the /sbin directory (which contains executable programs):

du /sbin/file1 /sbin/file2

du can accept any number of arguments, and they can be any combination of files and directories. When there are multiple arguments, no grand total is provided by default, although a total is still provided for each argument.

Options

As is the case with most commands on Linux and other Unix-like operating systems, du has a number of options, a few of which are commonly used. The options can vary somewhat according to the particular operating system and the version of du.

One of the most useful options is -h (i.e., human readable), which can make the output easier to read by displaying it in kilobytes (K), megabytes (M) and gigabytes (G) rather than just in the default kilobytes. Thus, the following command can be used to show the sizes of all the subdirectories in the current directory as well as the total size of the current directory, all formatted with the appropriate K, M or G:

du -h

The -s (for suppress or summarize) option tells du to report only the total disk space occupied by a directory tree and to suppress individual reports for its subdirectories. Thus, for example, the following would provide the total disk space occupied by the current directory in an easy-to-read format:

du -sh

The output is the same as the last line of a report issued by du with only the -h option.

The -a (i.e., all) option tells du to report not just the total disk usage for each directory at every level in a directory tree but also to report the space consumption for each individual file anywhere within the tree. Thus, for example, the following would list the name and size of every directory and file in the /etc directory (which contains system configuration files) for which the user has reading permission:

du -a /etc

A somewhat similar report is provided by using the star ( * ) wildcard, which will match any character or characters. For example, the following command would list the sizes of all directories that are in the tree that begins with the current directory:

du *

However, the only files listed are those in the the parent directory, not those in its subdirectories. Also, no total for the directory tree as a whole is provided.

The use of the -s option and the star wildcard together would cause du to report the names and sizes of only the files and directories contained directly in the top level directory itself (and to not list the names of any of its subdirectories and the files in them). The size of each listed directory is, of course, inclusive of all of its files and subdirectories (including all of the files in them). For example, such a report about the directory tree beginning with the current directory would be provided by the following:

du -hs *

The wildcard can also be used to filter the output to list only those items whose names begin with, contain or end with certain characters or sequences of characters. For example, the following would report the names and sizes of all of the directories and files in the current directory whose names begin with the letter s as well as the names and sizes of all levels of subdirectories of those directories regardless of what their names begin with:

du -h s*

The -c option can be added to provide a grand total for all of the files and directories that are listed. In the case of the above example, this would be

du -hc s*

As another example of the use of the wildcard, the following command would report the name and size of each gif (one of the two most popular image formats) file in the current directory as well as a total for all of the gifs:

du -hc *.gif

Another useful option is –max-depth=, which instructs du to list its subdirectories and their sizes to any desired level of depth (i.e., to any level of subdirectories) in a directory tree. For example, the following would cause du to list only the first tier (i.e., layer) of directories in the current directory and their sizes (inclusive of all of their contents, including those of their subdirectories):

du –max-depth=1

The total space consumption for the current directory tree will also be reported, and it will, of course, be the same regardless of the depth of the files listed.

Setting –max-depth= to zero tells du to not list any of the subdirectories within the selected directory, i.e., to list only report the size of the selected directory itself. The result is the same as using the -s option.

Using du With Filters

As is the case with other commands on Unix-like operating systems, du can be linked with pipes to filters to create powerful pipelines of commands. A filter is a (usually) small and specialized program that transforms data in some meaningful way.

For example, to arrange the output items according to size, du can be piped to the sort command, whose -n option tells it to list the output in numeric order with the smallest files first, as follows:

du | sort -n

As du will often generate more output than can fit on the monitor screen at one time, the output will fly by at high speed and be virtually unreadable. Fortunately, it is easy to display the output one screenful at a time by piping it to the less filter, for example,

du -h | less

The output of less can be advanced one screenful at a time by pressing the space bar, and it can be moved backward one screenful at a time by pressing the b key.

The output of du can likewise be piped to less after it has been passed through one or more other filters, for example,

du -h | sort -n | less

The grep filter can be used to search through du’s output for any desired string (i.e., sequence of characters). Thus, for example, the following will provide a list of the names and sizes of directories and files in the current directory that contain the word linux:

du -ah | grep linux

One way in which du can be used to produce a list of (mostly) directories and files in a directory tree that are consuming large amounts of disk space is to use grep to search for all the lines that contain the upper case letter M (i.e., for megabytes) or G (for gigabytes), such as

du -ah | grep M

The only problem with this approach is that it will also select directories and files that contain an upper case M or G in their names even if the file size is not measured in megabytes or gigabytes. (However, this problem could be overcome through the use of regular expressions, an advanced pattern matching technique).

Alternatives to du

There are several other ways of monitoring disk space consumption and reporting file sizes. Although very useful tools, they are generally not good substitutes for du.

Among them is the df command, which is likewise used by system administrators to monitor disk usage. However, unlike du, it can only show the space consumption on entire partitions, and it lacks du’s fine-grained ability to track the space usage of individual directories and files.

du is not designed to show the space consumption of partitions. The closest that it can come is to show the sizes of the first tier of directories in the root directory (i.e., the directory which contains all other directories and which is represented by a forward slash), several of which may be on their own partitions (depending on how the system has been set up). This is accomplished by becoming the root user and issuing the following command:

du -h –max-depth=1 /

The ls (i.e., list) command can provide the sizes of individual files by using its -s option, and its -h option (which is similar to du’s -h option) can be added to make the output easier to read. For example, the following would list the names and sizes of the files in the current directory:

ls -sh

Although the names of the first tier of directories within the current directory are also listed, the size data accompanying them does not represent their actual disk space consumption (i.e., inclusive of their contents). Nor does ls report the contents of any lower tiers of directories, unless such directories are specifically listed as arguments.

A convenient alternative for finding the sizes of files and directory trees when using a GUI (graphical user interface) is to click with the right mouse button on the icon (i.e., a small picture or symbol) for that item and then select Properties from the menu that appears. Although this is frequently sufficient, it does not provide the detailed control and reporting that du provides.

Courtesy – Linfo

Top Linux Commands

1: cd

The “Change Directory” command enables you to navigate to another directory.

As the command suggests, it enables the user to change / jump to a directory.

Examples:

cd Desktop
cd /etc/

Directory Up command

cd ..

>NOTE: Afther you have typed cd and entering the first or two letters of the directory you can press the TAB key to autocomplete the directory! So, cd De (press tabkey) will autocomplete it to Desktop.

2: man

The man command shows the users the “manual” of the command. In some situation you might need to get more information about the command you are using. The man command shows you this information about the command.

Example:

man cp

This will open up the “cp” manual document for us in the shell. The manual shows us the parameters available for the commands.

>NOTE: To close the manual simply press “Q”.

3: ls

In the absolute top 15 there’s no way the ls command is missing. On the third place, the ls command. The ls command is used to list the files/directories within a directory.

Example:

ls

It shows us the directories available.

4: cp

The cp command is available for us to “Copy” things. This might be usefull for duplicating files f.e.

Example:

cp fileOld fileNew

note: fileOld is on this case the file the user wants to be copied… fileNew is the name of the copied file. It’s that simple.

5 mv

The mv command is used for “Move” operations. The mv commands enables the users to move a file/directory to a specified location.

Example:

mv /home/root/Desktop/old /home/root/Desktop/new

>NOTE: the first part of the command is the file that has to be moved. The second part (after the whitespace) is the target directory. Make sure you type in the full path using this command!

6 mkdir

This command is used to “make” directories, NOT Files.. (thit is possible with another command which i will bring up later in this tutorial)

Example:

mkdir sampleDirectory

>NOTE: The name of the directory is case sensitive which means that Testdirectory is a complete different directory as sampleDirectory.

7 rmdir

When you are able to make directories, you also want to know how to remove them. Removing directories is done by the rmdir command and belongs to the absolute basic commands in shell bashing.

Example:

rmdir somedir

Note: When the directory is not empty the command will prompt an error message:

rmdir: failed to remove `somedir': Directory not empty

So make sure it’s completely empty before removing it.

>Note: To delete All the files in a directory, run the following command after cd into the folder.

$ find . -type f -delete

8 touch

Now we know how to make directories and deleting them, i now want to use the touch command. The touch command is used to make files.

Example:

touch sampleFile

This will create the file sampleFile for us in the directory.

9 rm

The rm command stand for remove. Remove directory & files along with it

Example

rm yourDirectory

To Remove directory & files along with it

rm -r yourDirectory

10 tar

Sometimes you have to archive files. Archiving files is a way to pack a set of files to one single file. The operation is done by the tar command.

Example:

tar -cvf test.tar test (Creating a tar file from directory or file test)

Example:

tar -xvf test.tar myexctractfolder (Extracts the particular tar file in the current working directory)

The parameters are telling the tar command how to behave and how to execute. After the parameters you entered the name of the file which is test.tar. The second part is the source directory/file of the tar file. In this situation a directory called test.

11 chmod

The chmod command. The chmod command comes from “Change Mode” back to the unix times. It’s a great command to restrict access to directories or files.

Chmod is qiet an advanced command to use. So therefore you really need to understand how it works.
chmod works with so called persmission bits. These bits can be set to a certain level of restrictions.

We have the following bits available:

7 full
6 read and write
5 read and execute
4 read only
3 write and execute
2 write only
1 execute only
0 none

The bits shown above are the permissions for a particular group or class.

Files or directories contain four classes:

1st: The owner itself
2nd: Member of the file group
3rd: Others
4th: All of the above

To set the right permission bits the a particular group or class it is very important to select to right amount of permission bits.

Read = 4 bits.
Write = 2 bits.
Exec = 1 bit.

So we have 3 groups to take care of (the first group which is the owner is optional in chmod)

[membersgroupbit],[others],[alloftheabove]

If we want to give everyone, a

chmod 777 myfile

[read=4+Write=2+Execute=1=7],[read=4+Write=2+Execute=1=7],[read=4+Write=2+Execute=1=7]

This is not good!

We want to restrict the access for the file offcourse so a better chmod would be:

chmod 700 myfile

[read=4+Write=2+Execute=1],[0][0]

How to Replace the Occurrences of Multiple Strings in a File using a Single Command in Terminal

The Linux command used to replace multiple strings with another in terminal is “replace”. Here is how to use it :

Consider a text file, “sample.txt” inside a folder “Testing”. Here are the steps to replace multiple strings inside the file.

1. Go to the folder in which the file is located using the “cd” command.

$ cd Testing/

Now your terminal window will point to this path.

2. Next you can use the cat command to see the contents of the file.

$ cat sample.txt

Sample test file with some content inside the folder Testing.

3. Now lets replace the words “content” and “Sample” inside the file with the words, “string” and “Some” respectively.

$ replace content string Sample Some — sample.txt

sample.txt converted

4. Now use the cat command once again to see the contents of the file.

$ cat sample.txt

Some test file with some string inside the folder Testing.

As you can see the strings are replaced in the file.

How to Replace the Occurrence of a String in a File using Terminal

The Linux command used to replace a string with another in terminal is “replace”. Here is how to use it :

Consider a text file, “sample.txt” inside a folder “Testing”. Here are the steps to replace a string inside the file.

1. Go to the folder in which the file is located using the “cd” command.

$ cd Testing/

Now your terminal window will point to this path.

2. Next you can use the cat command to see the contents of the file.

$ cat sample.txt

Sample test file with some content inside the folder Testing.

3. Now lets replace the word “content” inside the file with the word, “string”.

$ replace content string — sample.txt

sample.txt converted

4. Now use the cat command once again to see the contents of the file.

$ cat sample.txt

Sample test file with some string inside the folder Testing.

As you can see the string is replaced in the file.

How to Open a Text File in Edit Mode in Terminal

The Linux command used to open a text file in edit mode in terminal is “nano”. Here is how to use it :

Consider a text file, “sample.txt” inside a folder “Testing”. Here are the steps to follow to open the file “sample.txt” in terminal for editing.

1. Go to the folder in which the file is located using the “cd” command.

$ cd Testing/

Now your terminal window will point to this path.

2. Use the following command to echo the contents of the file in the terminal.

$ nano sample.txt

GNU nano 2.0.6               File: sample.txt

Sample test file with some content inside the folder Testing.

So the file will be open in edit mode inside the terminal itself so that you can make the necessary changes.

How to Echo the Contents of a File in Terminal

The Linux command used to echo the contents of a file in terminal is “cat”. Here is how to use it :

 

Consider a text file, “sample.txt” inside a folder “Testing”. Here are the steps to follow to echo the contents of the file “sample.txt” in terminal.

 

1. Go to the folder in which the file is located using the “cd” command.

 

$ cd Testing/

 

Now your terminal window will point to this path.

 

2. Use the following command to echo the contents of the file in the terminal.

 

$ cat sample.txt

Sample test file with some content inside the folder Testing.

 

So you will get the output like this.

 

Top Linux Commands

Basic Linux Commands

mkdir – make directories

Usage

mkdir [OPTION] DIRECTORY

Options

Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.

-m, mode=MODE  set permission mode (as in chmod), not rwxrwxrwx – umask

-p, parents  no error if existing, make parent directories as needed

-v, verbose  print a message for each created directory

-help display this help and exit

-version output version information and exit

cd – change directories

Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.

mv- change the name of a directory

Type mv followed by the current name of a directory and the new name of the directory.

Ex: mv testdir newnamedir

pwd – print working directory

will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page

rmdir – Remove an existing directory

rm -r

Removes directories and files within the directories recursively.

chown – change file owner and group

Usage

chown [OPTION] OWNER[:[GROUP]] FILE

chown [OPTION] :GROUP FILE

chown [OPTION] –reference=RFILE FILE

Options

Change the owner and/or group of each FILE to OWNER and/or GROUP. With –reference, change the owner and group of each FILE to those of RFILE.

-c, changes like verbose but report only when a change is made

-dereference affect the referent of each symbolic link, rather than the symbolic link itself

-h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can         change the ownership of a symlink)

-from=CURRENT_OWNER:CURRENT_GROUP

change the owner and/or group of each file only if its current owner and/or group match those specified here.  Either  may  be  omitted,  in which case a match is not required for the omitted attribute.

-no-preserve-root do not treat `/’ specially (the default)

-preserve-root fail to operate recursively on `/’

-f, -silent, -quiet  suppress most error messages

-reference=RFILE use RFILE’s owner and group rather than the specifying OWNER:GROUP values

-R, -recursive operate on files and directories recursively

-v, -verbose output a diagnostic for every file processed

The  following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one  takes effect.

-H     if a command line argument is a symbolic link to a directory, traverse it

-L     traverse every symbolic link to a directory encountered

-P     do not traverse any symbolic links (default)

chmod – change file access permissions

Usage

chmod [-r] permissions filenames

r  Change the permission on files that are in the subdirectories of the directory that you are currently in.        permission  Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha  numeric format.filenames  File or directory that you are associating the rights with Permissions

u – User who owns the file.

g – Group that owns the file.

o – Other.

a – All.

r – Read the file.

w – Write or edit the file.

x – Execute or run the file as a program.

Numeric Permissions:

CHMOD can also to attributed by using Numeric Permissions:

400 read by owner

040 read by group

004 read by anybody (other)

200 write by owner

020 write by group

002 write by anybody

100 execute by owner

010 execute by group

001 execute by anybody

ls – Short listing of directory contents

-a        list hidden files

-d        list the name of the current directory

-F        show directories with a trailing ‘/’

executable files with a trailing ‘*’

-g        show group ownership of file in long listing

-i        print the inode number of each file

-l        long listing giving details about files  and directories

-R        list all subdirectories encountered

-t        sort by time modified instead of name

cp – Copy files

cp  myfile yourfile

Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.

cp -i myfile yourfile

With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.

cp -i /data/myfile

Copy the file “/data/myfile” to the current working directory and name it “myfile”. Prompt before overwriting the  file.

cp -dpr srcdir destdir

Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir

ln – Creates a symbolic link to a file.

ln -s test symlink

Creates a symbolic link named symlink that points to the file test Typing “ls -i test symlink” will show the two files are different with different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.

locate – A fast database driven file locator.

slocate -u

This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically  on most systems.locate whereis Lists all files whose names contain the string “whereis”. directory.

more – Allows file contents or piped output to be sent to the screen one page at a time

less – Opposite of the more command

cat – Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.

whereis – Report all known instances of a command
wc – Print byte, word, and line counts

bg

bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.

cal month year – Prints a calendar for the specified month of the specified year.

cat files – Prints the contents of the specified files.

clear – Clears the terminal screen.

cmp file1 file2 – Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.

diff file1 file2 – Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.

dmesg – Prints the messages resulting from the most recent system boot.

fg

fg jobs – Brings the current job (or the specified jobs) to the foreground.

file files – Determines and prints a description of the type of each specified file.

find path -name pattern -print

Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.

finger users – Prints descriptions of the specified users.

free  – Displays the amount of used and free system memory.

ftp hostname

Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.

head files – Prints the first several lines of each specified file.

ispell files – Checks the spelling of the contents of the specified files.

kill process_ids

kill – signal process_ids

kill -l

Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.

killall program

killall – signal program

Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.

mail – Launches a simple mail client that permits sending and receiving email messages.

man title

man section title – Prints the specified man page.

ping host – Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.

reboot – Reboots the system (requires root privileges).

shutdown minutes

shutdown -r minutes

Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.

sleep time – Causes the command interpreter to pause for the specified number of seconds.

sort files – Sorts the specified files. The command has many useful arguments; see the online documentation.

split file – Splits a file into several smaller files. The command has many arguments; see the online documentation

sync – Completes all pending input/output operations (requires root privileges).

telnet host – Opens a login session on the specified host.

top – Prints a display of system processes that’s continually updated until the user presses the q key.

traceroute host – Uses echo requests to determine and print a network path to the host.

uptime – Prints the system uptime.

w – Prints the current system users.

wall – Prints a message to each user except those who’ve disabled message reception. Type Ctrl-D to end the message.

Scheduling a Job For a Specific Time -Linux Crontab

Scheduling a Job For a Specific Time

The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.

Linux Crontab Format

MIN HOUR DOM MON DOW CMD

Table: Crontab Fields and Allowed Ranges (Linux Crontab Syntax) Field     Description     Allowed Value
MIN     Minute field     0 to 59
HOUR     Hour field     0 to 23
DOM     Day of Month     1-31
MON     Month field     1-12
DOW     Day Of Week     0-6
CMD     Command     Any command to be executed.

Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.

30 08 10 06 * /home/ramesh/full-backup

30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week