Most frequently used Linux commands 3

Most frequently used Linux commands 3

Crontab command

View crontab entry for a specific user

# crontab -u john -l

Schedule a cron job every 10 minutes.

*/10 * * * * /home/ramesh/check-disk-space

Service command

Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.

Check the status of a service:

# service ssh status

Check the status of all the services.

service --status-all

Restart a service.

# service ssh restart

Ps command

ps command is used to display information about the processes that are running in the system.

While there are lot of arguments that could be passed to a ps command, following are some of the common ones.

To view current running processes.

$ ps -ef | more

To view current running processes in a tree structure. H option stands for process hierarchy.

$ ps -efH | more

Free command

This command is used to display the free, used, swap memory available in the system.

Typical free command output. The output is displayed in bytes.

$ free

If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.

$ free -g

If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.

$ free -t

Top command

top command displays the top processes in the system ( by default sorted by cpu usage ).

To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.

$ top -u oracle

Df command

Displays the file system disk space usage. By default df -k displays output in bytes.

$ df -k

df -h displays output in human readable form. i.e size will be displayed in GB’s.

$ df -h

Use -T option to display what type of file system.

$ df -T

Kill command

Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.

$ ps -ef | grep vim
$ kill -9 7243

Rm command

Get confirmation before removing the file.

$ rm -i filename.txt

It is very useful while giving shell metacharacters in the file name argument.

Print the filename and get confirmation before removing the file.

$ rm -i file*

Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.

$ rm -r example

Cp command

Copy file1 to file2 preserving the mode, ownership and timestamp.

$ cp -p file1 file2

Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$ cp -i file1 file2

Mv command

Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$ mv -i file1 file2

Note: mv -f is just the opposite, which will overwrite file2 without prompting.

mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.

$ mv -v file1 file2

Cat command

You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.

$ cat file1 file2

While displaying the file, following cat -n command will prepend the line number to each line of the output.

$ cat -n /etc/logrotate.conf


Most frequently used Linux commands 3
added 7 years 10 months ago

Contents related to 'Most frequently used Linux commands 3'

Most frequently used Linux commands 1: Most frequently used linux commands, explanation of linux commands, examples of linux command usage.

Most frequently used Linux commands 2: Most frequently used linux commands 2, explanation of linux commands, examples of linux command usage.

Most frequently used Linux commands 4: Most frequently used linux commands 4, explanation of linux commands, examples of linux command usage.

Most frequently used Linux commands 5: Most frequently used linux commands 5, explanation of linux commands, examples of linux command usage.

- Average Calculator
- Most frequently used Linux commands 5
- Most frequently used Linux commands 4
- Most frequently used Linux commands 3
- Most frequently used Linux commands 2
- Most frequently used Linux commands 1
- How to rename a filename to current date with batch
- How does a mutex work? What does a mutex cost?
- Locking : Mutex vs Spinlocks
- Description of Lock, Monitor, Mutex and Semaphore
- Difference between Mutex and Semaphore
- Difference between association, aggregation and composition
- Coordinating C/C++ ØMQ and .NET ØMQ
- Regular Expressions (Regex) Reference Sheet